Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,22 @@ export function Comments( {
useDispatch( blockEditorStore )
);

const {
blockCommentId,
selectedBlockClientId,
orderedBlockIds,
blockMode,
} = useSelect( ( select ) => {
const {
getBlockAttributes,
getSelectedBlockClientId,
getClientIdsWithDescendants,
getBlockMode,
} = select( blockEditorStore );
const clientId = getSelectedBlockClientId();
return {
blockCommentId: clientId
? getBlockAttributes( clientId )?.metadata?.noteId
: null,
selectedBlockClientId: clientId,
orderedBlockIds: getClientIdsWithDescendants(),
blockMode: clientId ? getBlockMode( clientId ) : null,
};
}, [] );
const { blockCommentId, selectedBlockClientId, orderedBlockIds } =
useSelect( ( select ) => {
const {
getBlockAttributes,
getSelectedBlockClientId,
getClientIdsWithDescendants,
} = select( blockEditorStore );
const clientId = getSelectedBlockClientId();
return {
blockCommentId: clientId
? getBlockAttributes( clientId )?.metadata?.noteId
: null,
selectedBlockClientId: clientId,
orderedBlockIds: getClientIdsWithDescendants(),
};
}, [] );

const relatedBlockElement = useBlockElement( selectedBlockClientId );

Expand Down Expand Up @@ -318,7 +312,6 @@ export function Comments( {
threads,
selectedThread,
setCanvasMinHeight,
blockMode,
] );

const handleThreadNavigation = ( event, thread, isSelected ) => {
Expand Down
31 changes: 7 additions & 24 deletions packages/editor/src/components/collab-sidebar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { __ } from '@wordpress/i18n';
import {
useEffect,
useMemo,
useRef,
useCallback,
useReducer,
} from '@wordpress/element';
Expand All @@ -36,9 +35,7 @@ import { collabSidebarName } from './constants';
import { unlock } from '../../lock-unlock';
import { noop } from './utils';

const { useBlockElementRef, cleanEmptyObject } = unlock(
blockEditorPrivateApis
);
const { useBlockElement, cleanEmptyObject } = unlock( blockEditorPrivateApis );

export function useBlockComments( postId ) {
const [ commentLastUpdated, reflowComments ] = useReducer(
Expand Down Expand Up @@ -369,20 +366,7 @@ export function useFloatingThread( {
setBlockRef,
commentLastUpdated,
} ) {
const blockRef = useRef();
useBlockElementRef( thread.blockClientId, blockRef );

const blockMode = useSelect(
( select ) => {
return thread.blockClientId
? select( blockEditorStore ).getBlockMode(
thread.blockClientId
)
: null;
},
[ thread.blockClientId ]
);

const blockElement = useBlockElement( thread.blockClientId );
const updateHeight = useCallback(
( id, newHeight ) => {
setHeights( ( prev ) => {
Expand All @@ -408,17 +392,17 @@ export function useFloatingThread( {

// Store the block reference for each thread.
useEffect( () => {
if ( blockRef.current ) {
refs.setReference( blockRef.current );
if ( blockElement ) {
refs.setReference( blockElement );
}
}, [ blockRef, refs, commentLastUpdated, blockMode ] );
}, [ blockElement, refs, commentLastUpdated ] );

// Track thread heights.
useEffect( () => {
if ( refs.floating?.current ) {
setBlockRef( thread.id, blockRef.current );
setBlockRef( thread.id, blockElement );
}
}, [ thread.id, refs.floating, setBlockRef ] );
}, [ blockElement, thread.id, refs.floating, setBlockRef ] );

// When the selected thread changes, update heights, triggering offset recalculation.
useEffect( () => {
Expand All @@ -435,7 +419,6 @@ export function useFloatingThread( {
] );

return {
blockRef,
y,
refs,
};
Expand Down
Loading