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

Addressed feedback #43

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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function BlockSettingsMenu( { clientIds, ...props } ) {
const selectedBlockClientId = clientIds[ 0 ];
const commentID = useSelect( ( select ) => {
return (
// eslint-disable-next-line @wordpress/data-no-store-string-literals
select( blockEditorStore ).getBlock( selectedBlockClientId )
?.attributes?.blockCommentId || null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export default function BlockCommentMenuItem( { onClose } ) {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { openGeneralSidebar } = useDispatch( 'core/edit-post' );

// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { updateBlockAttributes } = useDispatch( blockEditorStore );

const clientId = useSelect( ( select ) => {
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const { getSelectedBlockClientId } = select( blockEditorStore );
return getSelectedBlockClientId();
}, [] );
Expand All @@ -38,10 +36,7 @@ export default function BlockCommentMenuItem( { onClose } ) {
onClick={ openCollabBoard }
aria-haspopup="dialog"
>
{ _x(
'Comment',
'Click to open new comment form in comment sidebar'
) }
{ _x( 'Comment', 'Add comment button' ) }
</MenuItem>
);
}
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/collab/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export default function BlockCommentToolbar() {
<ToolbarButton
accessibleWhenDisabled
icon={ collabComment }
label={ _x(
'Comment',
'Click to open sidebar and highlight comment board'
) }
label={ _x( 'Comment', 'Open comment button' ) }
onClick={ openCollabBoard }
/>
);
Expand Down
58 changes: 23 additions & 35 deletions packages/editor/src/components/collab-sidebar/add-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,27 @@ export function AddComment( { onSubmit } ) {
// State to manage the comment thread.
const [ inputComment, setInputComment ] = useState( '' );

const currentUserData = useSelect( ( select ) => {
return select( coreStore ).getCurrentUser();
}, [] );
const {
defaultAvatar,
clientId,
blockCommentId,
showAddCommentBoard,
currentUser,
} = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { __experimentalDiscussionSettings } = getSettings();
const selectedBlock = select( blockEditorStore ).getSelectedBlock();
const userData = select( coreStore ).getCurrentUser();
return {
defaultAvatar: __experimentalDiscussionSettings?.avatarURL,
clientId: selectedBlock?.clientId,
blockCommentId: selectedBlock?.attributes?.blockCommentId,
showAddCommentBoard: selectedBlock?.attributes?.showCommentBoard,
currentUser: userData,
};
} );

const useDefaultAvatar = () => {
const { avatarURL: defaultAvatarUrl } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { __experimentalDiscussionSettings } = getSettings();
return __experimentalDiscussionSettings;
} );
return defaultAvatarUrl;
};

const defaultAvatar = useDefaultAvatar();
const userAvatar = currentUserData?.avatar_urls[ 48 ] ?? defaultAvatar;

const currentUser = currentUserData?.name || null;

const { clientId, blockCommentId, showAddCommentBoard } = useSelect(
( select ) => {
const selectedBlock = select( blockEditorStore ).getSelectedBlock();
const selectedBlockClientID =
select( blockEditorStore ).getSelectedBlockClientId();
return {
clientId: selectedBlockClientID,
blockCommentId: selectedBlock?.attributes?.blockCommentId,
showAddCommentBoard:
selectedBlock?.attributes?.showCommentBoard,
};
},
[]
);
const userAvatar = currentUser?.avatar_urls[ 48 ] ?? defaultAvatar;

useEffect( () => {
setInputComment( '' );
Expand Down Expand Up @@ -94,22 +83,21 @@ export function AddComment( { onSubmit } ) {
height={ 32 }
/>
<span className="editor-collab-sidebar-panel__user-name">
{ currentUser }
{ currentUser?.name ?? '' }
</span>
</HStack>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
value={ inputComment }
onChange={ setInputComment }
// translators: placeholder text for comment input
placeholder={ __( 'Comment' ) }
placeholder={ _x( 'Comment', 'noun' ) }
/>
<HStack alignment="right" spacing="3">
<Button
__next40pxDefaultSize
variant="tertiary"
text={ _x( 'Cancel', 'Cancel comment' ) }
text={ _x( 'Cancel', 'Cancel comment button' ) }
onClick={ handleCancel }
size="compact"
/>
Expand Down
Loading
Loading