Skip to content
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

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
912ec5a
Scroll editor blocks based on comments
karthick-murugan Nov 8, 2024
154c273
Update blockClientId
karthick-murugan Nov 8, 2024
52341d1
Update Iframe
karthick-murugan Nov 11, 2024
aef8840
Feedback Changes
karthick-murugan Nov 26, 2024
0c34d4e
Merge branch 'trunk' into feature/block-comments-scroll
karthick-murugan Nov 27, 2024
dad8215
Site Editor: Unify layout with posts dataviews (#67162)
youknowriad Nov 27, 2024
cd730bb
Scroll editor blocks based on comments
karthick-murugan Nov 8, 2024
583632d
Feedback Changes
karthick-murugan Nov 26, 2024
499cfd8
Feedback Changes
karthick-murugan Nov 27, 2024
d71c1c6
Remove unnecessary changes
karthick-murugan Nov 28, 2024
07c85f6
Feedback Changes
karthick-murugan Nov 28, 2024
a7693d4
Merge branch 'trunk' of github.com:karthick-murugan/gutenberg into fe…
karthick-murugan Nov 28, 2024
8367a44
Linting issues fixed
karthick-murugan Nov 28, 2024
9d60b44
Feedback Changes updated
karthick-murugan Dec 4, 2024
e5d379b
Feedback updates
karthick-murugan Dec 5, 2024
939f2f5
Feedback updates
karthick-murugan Dec 5, 2024
68568d9
Feedback updates
karthick-murugan Dec 5, 2024
13194c1
Feedback and site editor updates
karthick-murugan Dec 5, 2024
e9b0e4b
Updating feedback changes
karthick-murugan Dec 5, 2024
cc4c27a
Merge branch 'trunk' into feature/block-comments-scroll
karthick-murugan Dec 5, 2024
de2c602
Reverting comment header
karthick-murugan Dec 5, 2024
07453a5
Merge branch 'feature/block-comments-scroll' of github.com:karthick-m…
karthick-murugan Dec 5, 2024
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
50 changes: 43 additions & 7 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -52,6 +52,8 @@ export function Comments( {
} ) {
const [ actionState, setActionState ] = useState( false );
const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false );
const [ activeClientId, setActiveClientId ] = useState( null );
Copy link
Member

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?

Copy link
Contributor Author

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.

const [ blocksList, setBlocksList ] = useState( null );

const handleConfirmDelete = () => {
onCommentDelete( actionState.id );
Expand All @@ -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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't set sate inside useSelect, return the value instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix - now the value has been returned inside useSelect


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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use useDispatch instead, so we get the actions from the correct registry based on the context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix - Updated with useDispatch as per your advice.

}
};

const CommentBoard = ( { thread, parentThread } ) => {
return (
<>
Expand Down Expand Up @@ -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 &&
Expand Down