Skip to content

Commit

Permalink
Feedback Changes updated
Browse files Browse the repository at this point in the history
  • Loading branch information
karthick-murugan committed Dec 4, 2024
1 parent 8367a44 commit 9d60b44
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { useState, RawHTML, useEffect } from '@wordpress/element';
import { useState, RawHTML } from '@wordpress/element';
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Expand All @@ -17,7 +17,7 @@ import {
} from '@wordpress/components';
import { Icon, check, published, moreVertical } from '@wordpress/icons';
import { __, _x } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect, useDispatch, select } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
Expand Down Expand Up @@ -48,7 +48,6 @@ export function Comments( {
const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false );
// eslint-disable-next-line no-unused-vars
const [ activeClientId, setActiveClientId ] = useState( null );
const [ blocksList, setBlocksList ] = useState( null );

const handleConfirmDelete = () => {
onCommentDelete( actionState.id );
Expand All @@ -67,40 +66,14 @@ export function Comments( {
setIsConfirmDialogOpen( false );
};

const blockCommentId = useSelect( ( select ) => {
const blockCommentId = useSelect( () => {
const clientID = select( blockEditorStore ).getSelectedBlockClientId();
return (
select( blockEditorStore ).getBlock( clientID )?.attributes
?.blockCommentId ?? false
);
}, [] );

const { selectedClientBlocks, selectedActiveClientId } = useSelect(
( select ) => {
const clientID =
select( blockEditorStore ).getSelectedBlockClientId();
const selClientBlocks = select( blockEditorStore ).getBlocks();

const getBlockCommentId =
select( blockEditorStore ).getBlock( clientID )?.attributes
?.blockCommentId ?? false;

return {
selectedClientBlocks: selClientBlocks,
selectedActiveClientId: getBlockCommentId || null,
};
},
[]
);

useEffect( () => {
setBlocksList( selectedClientBlocks );

if ( selectedActiveClientId ) {
setActiveClientId( selectedActiveClientId );
}
}, [ selectedClientBlocks, selectedActiveClientId ] );

const findBlockByCommentId = ( blocks, commentId ) => {
for ( const block of blocks ) {
if ( block.attributes.blockCommentId === commentId ) {
Expand All @@ -121,7 +94,8 @@ export function Comments( {

const { selectBlock } = useDispatch( blockEditorStore );
const handleThreadClick = ( thread ) => {
const block = findBlockByCommentId( blocksList, thread.id );
const selClientBlocks = select( blockEditorStore ).getBlocks();
const block = findBlockByCommentId( selClientBlocks, thread.id );
if ( block ) {
selectBlock( block.clientId ); // Use the action to select the block
}
Expand Down

0 comments on commit 9d60b44

Please sign in to comment.