Skip to content

Commit

Permalink
Derive blockCommentId value
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Oct 30, 2024
1 parent f850546 commit 58d03a6
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, resolveSelect } from '@wordpress/data';
import { useState, useEffect, useMemo } from '@wordpress/element';
import { comment as commentIcon, post } from '@wordpress/icons';
import { useState, useMemo } from '@wordpress/element';
import { comment as commentIcon } from '@wordpress/icons';
import { addFilter } from '@wordpress/hooks';
import { store as noticesStore } from '@wordpress/notices';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -54,7 +54,6 @@ export default function CollabSidebar() {
const { saveEntityRecord, deleteEntityRecord } = useDispatch( coreStore );
const { getEntityRecord } = resolveSelect( coreStore );
const { enableComplementaryArea } = useDispatch( interfaceStore );
const [ blockCommentID, setBlockCommentID ] = useState( null );
const [ showCommentBoard, setShowCommentBoard ] = useState( false );

const { postId, postStatus, threads } = useSelect( ( select ) => {
Expand All @@ -77,14 +76,16 @@ export default function CollabSidebar() {
};
}, [] );

const { clientId, blockDetails } = useSelect( ( select ) => {
const { getBlock, getSelectedBlockClientId } =
const { clientId, blockCommentId } = useSelect( ( select ) => {
const { getBlockAttributes, getSelectedBlockClientId } =
select( blockEditorStore );
const _clientId = getSelectedBlockClientId();

return {
clientId: _clientId,
blockDetails: _clientId ? getBlock( _clientId ) : null,
blockCommentId: _clientId
? getBlockAttributes( _clientId ).blockCommentId
: null,
};
}, [] );

Expand Down Expand Up @@ -247,24 +248,18 @@ export default function CollabSidebar() {
);
};

useEffect( () => {
if ( blockDetails ) {
setBlockCommentID( blockDetails?.attributes.blockCommentId );
}
}, [ postId, clientId ] );

// Check if the experimental flag is enabled.
if ( ! isBlockCommentExperimentEnabled || postStatus === 'publish' ) {
return null; // or maybe return some message indicating no threads are available.
}

return (
<>
{ ! blockCommentID && (
{ ! blockCommentId && (
<AddCommentButton onClick={ openCollabBoard } />
) }

{ blockCommentID > 0 && (
{ blockCommentId > 0 && (
<AddCommentToolbarButton onClick={ openCollabBoard } />
) }
<PluginSidebar
Expand Down

0 comments on commit 58d03a6

Please sign in to comment.