Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Commenting: Re-order the comments in sidebar in which blocks are listed #66927

Merged
merged 9 commits into from
Dec 4, 2024
18 changes: 16 additions & 2 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function CollabSidebarContent( { showCommentBoard, setShowCommentBoard } ) {
};
}, [] );

const { getSelectedBlockClientId } = useSelect( blockEditorStore );
const { getSelectedBlockClientId, getBlocks } =
useSelect( blockEditorStore );
const { updateBlockAttributes } = useDispatch( blockEditorStore );

// Process comments to build the tree structure
Expand Down Expand Up @@ -96,7 +97,20 @@ function CollabSidebarContent( { showCommentBoard, setShowCommentBoard } ) {
}
} );

return result;
const blockCommentIds = getBlocks()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work for comments in posts with a template, such as Site Editor > Pages?

Copy link
Member Author

@akasunil akasunil Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated PR, it should be working fine now on post/page with template.

?.filter( ( block ) => !! block?.attributes?.blockCommentId )
?.map( ( block ) => block.attributes.blockCommentId );

const uniqueIds = [ ...new Set( blockCommentIds.values() ) ];

const threadIdMap = new Map(
filteredComments?.map( ( thread ) => [ thread.id, thread ] )
);
const sortedThreads = uniqueIds
.map( ( id ) => threadIdMap.get( id ) )
.filter( ( thread ) => thread !== undefined );

return sortedThreads;
}, [ threads ] );

// Function to save the comment.
Expand Down
Loading