Skip to content

Commit

Permalink
Add associated block client ids to comment object
Browse files Browse the repository at this point in the history
  • Loading branch information
akasunil committed Dec 5, 2024
1 parent 3133f56 commit ea0d195
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,26 @@ export default function CollabSidebar() {
}

const blockCommentIds = getCommentIdsFromBlocks( blocks );
const blockCommentIdMap = new Map(
blockCommentIds.map( ( item ) => [ item.commentID, item ] )
);

const updatedResult = result.map( ( item ) => {
return {
...item,
clientId: blockCommentIdMap.get( item.id )?.clientID,
};
} );

const threadIdMap = new Map(
result.map( ( thread ) => [ thread.id, thread ] )
updatedResult.map( ( thread ) => [ thread.id, thread ] )
);

const sortedComments = blockCommentIds
.map( ( id ) => threadIdMap.get( id ) )
.map( ( item ) => threadIdMap.get( item.commentID ) )
.filter( ( thread ) => thread !== undefined );

return { resultComments: result, sortedThreads: sortedComments };
return { resultComments: updatedResult, sortedThreads: sortedComments };
}, [ threads, blocks ] );

// Get the global styles to set the background color of the sidebar.
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/src/components/collab-sidebar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export function getCommentIdsFromBlocks( blocks ) {
block.attributes.blockCommentId &&
! commentIds.includes( block.attributes.blockCommentId )
) {
commentIds.push( block.attributes.blockCommentId );
commentIds.push( {
clientID: block.clientId,
commentID: block.attributes.blockCommentId,
} );
}

// Recursively check inner blocks
Expand Down

0 comments on commit ea0d195

Please sign in to comment.