Skip to content

Commit

Permalink
Merge pull request #42 from rishishah-multidots/try/inline-block-comm…
Browse files Browse the repository at this point in the history
…enting

Add error handling for duplicate comment
  • Loading branch information
poojabhimani12 authored Sep 5, 2024
2 parents fd4c045 + e1d4396 commit c78f981
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { useSelect } from '@wordpress/data';
*/
import BlockSettingsDropdown from './block-settings-dropdown';
import BlockCommentToolbar from '../collab/toolbar';
import { store as blockEditorStore } from '../../store';

export function BlockSettingsMenu( { clientIds, ...props } ) {
const selectedBlockClientId = clientIds[ 0 ];
const commentID = useSelect( ( select ) => {
return (
// eslint-disable-next-line @wordpress/data-no-store-string-literals
select( 'core/block-editor' ).getBlock( selectedBlockClientId )
select( blockEditorStore ).getBlock( selectedBlockClientId )
?.attributes?.blockCommentId || null
);
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import { MenuItem } from '@wordpress/components';
import { collabComment } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';

export default function BlockCommentMenuItem( { onClose } ) {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { openGeneralSidebar } = useDispatch( 'core/edit-post' );

// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { updateBlockAttributes } = useDispatch( 'core/block-editor' );
const { updateBlockAttributes } = useDispatch( blockEditorStore );

const clientId = useSelect( ( select ) => {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { getSelectedBlockClientId } = select( 'core/block-editor' );
const { getSelectedBlockClientId } = select( blockEditorStore );
return getSelectedBlockClientId();
}, [] );

Expand Down
9 changes: 7 additions & 2 deletions packages/block-editor/src/components/collab/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import { ToolbarButton } from '@wordpress/components';
import { collabComment } from '@wordpress/icons';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';

export default function BlockCommentToolbar() {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { openGeneralSidebar } = useDispatch( 'core/edit-post' );

// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { updateBlockAttributes } = useDispatch( 'core/block-editor' );
const { updateBlockAttributes } = useDispatch( blockEditorStore );

const clientId = useSelect( ( select ) => {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { getSelectedBlockClientId } = select( 'core/block-editor' );
const { getSelectedBlockClientId } = select( blockEditorStore );
return getSelectedBlockClientId();
}, [] );

Expand Down
45 changes: 44 additions & 1 deletion packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export default function CollabSidebar() {
comment_author: currentUserData?.name ?? null,
comment_approved: 0,
} );

if ( savedRecord ) {
updateBlockAttributes( clientId, {
blockCommentId: savedRecord?.id,
Expand All @@ -92,6 +91,17 @@ export default function CollabSidebar() {
isDismissible: true,
} );
fetchComments();
} else {
createNotice(
'error',
// translators: Error message when comment submission fails
__(
'Something went wrong. Please try publishing the post, or you may have already submitted your comment earlier.'
),
{
isDismissible: true,
}
);
}
};

Expand All @@ -109,6 +119,17 @@ export default function CollabSidebar() {
} );

fetchComments();
} else {
createNotice(
'error',
// translators: Error message when comment submission fails
__(
'Something went wrong. Please try publishing the post, or you may have already submitted your comment earlier.'
),
{
isDismissible: true,
}
);
}
};

Expand All @@ -132,6 +153,17 @@ export default function CollabSidebar() {
);

fetchComments();
} else {
createNotice(
'error',
// translators: Error message when comment submission fails
__(
'Something went wrong. Please try publishing the post, or you may have already submitted your comment earlier.'
),
{
isDismissible: true,
}
);
}
};

Expand Down Expand Up @@ -159,6 +191,17 @@ export default function CollabSidebar() {
}
);
fetchComments();
} else {
createNotice(
'error',
// translators: Error message when comment submission fails
__(
'Something went wrong. Please try publishing the post, or you may have already submitted your comment earlier.'
),
{
isDismissible: true,
}
);
}
};

Expand Down

0 comments on commit c78f981

Please sign in to comment.