Skip to content

Commit 7f07bca

Browse files
Mamadukat-hamano
andauthored
Notes: Simplify editing mode change position tracking (#73696)
* Notes: Simplify editing mode change position tracking * Cleanup remaining code Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
1 parent 5ad32c0 commit 7f07bca

2 files changed

Lines changed: 23 additions & 47 deletions

File tree

packages/editor/src/components/collab-sidebar/comments.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,22 @@ export function Comments( {
7070
useDispatch( blockEditorStore )
7171
);
7272

73-
const {
74-
blockCommentId,
75-
selectedBlockClientId,
76-
orderedBlockIds,
77-
blockMode,
78-
} = useSelect( ( select ) => {
79-
const {
80-
getBlockAttributes,
81-
getSelectedBlockClientId,
82-
getClientIdsWithDescendants,
83-
getBlockMode,
84-
} = select( blockEditorStore );
85-
const clientId = getSelectedBlockClientId();
86-
return {
87-
blockCommentId: clientId
88-
? getBlockAttributes( clientId )?.metadata?.noteId
89-
: null,
90-
selectedBlockClientId: clientId,
91-
orderedBlockIds: getClientIdsWithDescendants(),
92-
blockMode: clientId ? getBlockMode( clientId ) : null,
93-
};
94-
}, [] );
73+
const { blockCommentId, selectedBlockClientId, orderedBlockIds } =
74+
useSelect( ( select ) => {
75+
const {
76+
getBlockAttributes,
77+
getSelectedBlockClientId,
78+
getClientIdsWithDescendants,
79+
} = select( blockEditorStore );
80+
const clientId = getSelectedBlockClientId();
81+
return {
82+
blockCommentId: clientId
83+
? getBlockAttributes( clientId )?.metadata?.noteId
84+
: null,
85+
selectedBlockClientId: clientId,
86+
orderedBlockIds: getClientIdsWithDescendants(),
87+
};
88+
}, [] );
9589

9690
const relatedBlockElement = useBlockElement( selectedBlockClientId );
9791

@@ -318,7 +312,6 @@ export function Comments( {
318312
threads,
319313
selectedThread,
320314
setCanvasMinHeight,
321-
blockMode,
322315
] );
323316

324317
const handleThreadNavigation = ( event, thread, isSelected ) => {

packages/editor/src/components/collab-sidebar/hooks.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { __ } from '@wordpress/i18n';
1414
import {
1515
useEffect,
1616
useMemo,
17-
useRef,
1817
useCallback,
1918
useReducer,
2019
} from '@wordpress/element';
@@ -36,9 +35,7 @@ import { collabSidebarName } from './constants';
3635
import { unlock } from '../../lock-unlock';
3736
import { noop } from './utils';
3837

39-
const { useBlockElementRef, cleanEmptyObject } = unlock(
40-
blockEditorPrivateApis
41-
);
38+
const { useBlockElement, cleanEmptyObject } = unlock( blockEditorPrivateApis );
4239

4340
export function useBlockComments( postId ) {
4441
const [ commentLastUpdated, reflowComments ] = useReducer(
@@ -369,20 +366,7 @@ export function useFloatingThread( {
369366
setBlockRef,
370367
commentLastUpdated,
371368
} ) {
372-
const blockRef = useRef();
373-
useBlockElementRef( thread.blockClientId, blockRef );
374-
375-
const blockMode = useSelect(
376-
( select ) => {
377-
return thread.blockClientId
378-
? select( blockEditorStore ).getBlockMode(
379-
thread.blockClientId
380-
)
381-
: null;
382-
},
383-
[ thread.blockClientId ]
384-
);
385-
369+
const blockElement = useBlockElement( thread.blockClientId );
386370
const updateHeight = useCallback(
387371
( id, newHeight ) => {
388372
setHeights( ( prev ) => {
@@ -408,17 +392,17 @@ export function useFloatingThread( {
408392

409393
// Store the block reference for each thread.
410394
useEffect( () => {
411-
if ( blockRef.current ) {
412-
refs.setReference( blockRef.current );
395+
if ( blockElement ) {
396+
refs.setReference( blockElement );
413397
}
414-
}, [ blockRef, refs, commentLastUpdated, blockMode ] );
398+
}, [ blockElement, refs, commentLastUpdated ] );
415399

416400
// Track thread heights.
417401
useEffect( () => {
418402
if ( refs.floating?.current ) {
419-
setBlockRef( thread.id, blockRef.current );
403+
setBlockRef( thread.id, blockElement );
420404
}
421-
}, [ thread.id, refs.floating, setBlockRef ] );
405+
}, [ blockElement, thread.id, refs.floating, setBlockRef ] );
422406

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

437421
return {
438-
blockRef,
439422
y,
440423
refs,
441424
};

0 commit comments

Comments
 (0)