diff --git a/packages/editor/src/components/collab-sidebar/index.js b/packages/editor/src/components/collab-sidebar/index.js index 5037abe58f331f..482bf3d4081ed1 100644 --- a/packages/editor/src/components/collab-sidebar/index.js +++ b/packages/editor/src/components/collab-sidebar/index.js @@ -96,6 +96,35 @@ export default function CollabSidebar() { // Get the dispatch functions to save the comment and update the block attributes. const { updateBlockAttributes } = useDispatch( blockEditorStore ); + // Process comments to build the tree structure + const resultComments = useMemo( () => { + // Create a compare to store the references to all objects by id + const compare = {}; + const result = []; + + const filteredComments = threads.filter( + ( comment ) => comment.status !== 'trash' + ); + + // Initialize each object with an empty `reply` array + filteredComments.forEach( ( item ) => { + compare[ item.id ] = { ...item, reply: [] }; + } ); + + // Iterate over the data to build the tree structure + filteredComments.forEach( ( item ) => { + if ( item.parent === 0 ) { + // If parent is 0, it's a root item, push it to the result array + result.push( compare[ item.id ] ); + } else if ( compare[ item.parent ] ) { + // Otherwise, find its parent and push it to the parent's `reply` array + compare[ item.parent ].reply.push( compare[ item.id ] ); + } + } ); + + return result; + }, [ threads ] ); + const openCollabBoard = () => { setShowCommentBoard( true ); enableComplementaryArea( 'core', 'edit-post/collab-sidebar' ); @@ -234,35 +263,6 @@ export default function CollabSidebar() { return null; // or maybe return some message indicating no threads are available. } - // Process comments to build the tree structure - const resultComments = useMemo( () => { - // Create a compare to store the references to all objects by id - const compare = {}; - const result = []; - - const filteredComments = threads.filter( - ( comment ) => comment.status !== 'trash' - ); - - // Initialize each object with an empty `reply` array - filteredComments.forEach( ( item ) => { - compare[ item.id ] = { ...item, reply: [] }; - } ); - - // Iterate over the data to build the tree structure - filteredComments.forEach( ( item ) => { - if ( item.parent === 0 ) { - // If parent is 0, it's a root item, push it to the result array - result.push( compare[ item.id ] ); - } else if ( compare[ item.parent ] ) { - // Otherwise, find its parent and push it to the parent's `reply` array - compare[ item.parent ].reply.push( compare[ item.id ] ); - } - } ); - - return result; - }, [ threads ] ); - return ( <> { ! blockCommentID && (