-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selecting on a comment should scroll to the block #66873
base: trunk
Are you sure you want to change the base?
Changes from 3 commits
912ec5a
154c273
52341d1
aef8840
0c34d4e
dad8215
cd730bb
583632d
499cfd8
d71c1c6
07c85f6
a7693d4
8367a44
9d60b44
e5d379b
939f2f5
68568d9
13194c1
e9b0e4b
cc4c27a
de2c602
07453a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ export function Comments( { | |
} ) { | ||
const [ actionState, setActionState ] = useState( false ); | ||
const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false ); | ||
const [ activeClientId, setActiveClientId ] = useState( null ); | ||
const [ blocksList, setBlocksList ] = useState( null ); | ||
|
||
const handleConfirmDelete = () => { | ||
onCommentDelete( actionState.id ); | ||
|
@@ -70,14 +72,59 @@ export function Comments( { | |
setIsConfirmDialogOpen( false ); | ||
}; | ||
|
||
const blockCommentId = useSelect( ( select ) => { | ||
useSelect( ( select ) => { | ||
const clientID = select( blockEditorStore ).getSelectedBlockClientId(); | ||
return ( | ||
const clientBlocks = select( blockEditorStore ).getBlocks(); | ||
setBlocksList( clientBlocks ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't set sate inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ellatrix - now the value has been returned inside |
||
|
||
const getBlockCommentId = | ||
select( blockEditorStore ).getBlock( clientID )?.attributes | ||
?.blockCommentId ?? false | ||
); | ||
?.blockCommentId ?? false; | ||
|
||
if ( getBlockCommentId ) { | ||
setActiveClientId( getBlockCommentId ); | ||
} | ||
}, [] ); | ||
|
||
const findBlockByCommentId = ( blocks, commentId ) => { | ||
for ( const block of blocks ) { | ||
if ( block.attributes.blockCommentId === commentId ) { | ||
return block; | ||
} | ||
if ( block.innerBlocks && block.innerBlocks.length > 0 ) { | ||
const foundBlock = findBlockByCommentId( | ||
block.innerBlocks, | ||
commentId | ||
); | ||
if ( foundBlock ) { | ||
return foundBlock; | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
const handleThreadClick = ( thread ) => { | ||
const block = findBlockByCommentId( blocksList, thread.id ); | ||
|
||
if ( block ) { | ||
const blockClientId = block.clientId; | ||
const iframe = document.querySelector( | ||
'iframe[name="editor-canvas"]' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ellatrix - when I try to use the useBlockElementRef hook, As per my understanding, it’s a part of the @wordpress/block-editor package. However, when I attempt to use it in the @wordpress/editor package, I cannot get it to work as expected. Could you please confirm if this is an expected limitation? If so, are there any recommended workarounds or alternative approaches to achieve similar functionality (e.g., getting a reference to a block’s DOM element within the editor context)? Thanks in advance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean that it's not available as an API? Can we export it as a private API so we can use it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If just need to focus the respective block when comment board is focused, then I think below code would do the work
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akasunil - thank you and I have updated it and pushed the code. |
||
); | ||
const iframeDocument = | ||
iframe.contentDocument || iframe.contentWindow.document; | ||
const blockElement = iframeDocument.getElementById( | ||
'block-' + blockClientId | ||
); | ||
|
||
if ( blockElement ) { | ||
blockElement.scrollIntoView( { behavior: 'smooth' } ); | ||
setActiveClientId( thread.id ); | ||
} | ||
} | ||
}; | ||
|
||
const CommentBoard = ( { thread, parentThread } ) => { | ||
return ( | ||
<> | ||
|
@@ -201,12 +248,13 @@ export function Comments( { | |
'editor-collab-sidebar-panel__thread', | ||
{ | ||
'editor-collab-sidebar-panel__active-thread': | ||
blockCommentId && | ||
blockCommentId === thread.id, | ||
activeClientId && | ||
activeClientId === thread.id, | ||
} | ||
) } | ||
id={ thread.id } | ||
spacing="3" | ||
onClick={ () => handleThreadClick( thread ) } | ||
> | ||
<CommentBoard thread={ thread } /> | ||
{ 'reply' === actionState?.action && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is eslint disabled here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellatrix - The above lines no longer needed and removed it.