Skip to content

Commit

Permalink
Re-order the comments in sidebar in which blocks are listed
Browse files Browse the repository at this point in the history
  • Loading branch information
akasunil committed Nov 12, 2024
1 parent e6d38fe commit 1d42175
Showing 1 changed file with 16 additions and 2 deletions.
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()
?.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

0 comments on commit 1d42175

Please sign in to comment.