-
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 4 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 |
---|---|---|
|
@@ -23,7 +23,7 @@ import { | |
} from '@wordpress/date'; | ||
import { Icon, check, published, moreVertical } from '@wordpress/icons'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useSelect, dispatch } from '@wordpress/data'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
|
@@ -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,47 @@ 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; | ||
// Select the block in the editor | ||
dispatch( blockEditorStore ).selectBlock( blockClientId ); | ||
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 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 - Updated with |
||
} | ||
}; | ||
|
||
const CommentBoard = ( { thread, parentThread } ) => { | ||
return ( | ||
<> | ||
|
@@ -201,12 +236,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.