diff --git a/packages/editor/src/components/collab-sidebar/add-comment.js b/packages/editor/src/components/collab-sidebar/add-comment.js index 01ee7aff0370e..fce47e821e206 100644 --- a/packages/editor/src/components/collab-sidebar/add-comment.js +++ b/packages/editor/src/components/collab-sidebar/add-comment.js @@ -1,22 +1,19 @@ /** * WordPress dependencies */ -import { __, _x } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; -import { useState, useEffect } from '@wordpress/element'; import { __experimentalHStack as HStack, __experimentalVStack as VStack, - Button, - TextControl, } from '@wordpress/components'; import { store as blockEditorStore } from '@wordpress/block-editor'; -import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ -import { sanitizeCommentString } from './utils'; +import CommentAuthorInfo from './comment-author-info'; +import CommentForm from './comment-form'; /** * Renders the UI for adding a comment in the Gutenberg editor's collaboration sidebar. @@ -32,39 +29,14 @@ export function AddComment( { showCommentBoard, setShowCommentBoard, } ) { - // State to manage the comment thread. - const [ inputComment, setInputComment ] = useState( '' ); - - const { defaultAvatar, clientId, blockCommentId, currentUser } = useSelect( - ( select ) => { - const { getSettings, getSelectedBlock } = - select( blockEditorStore ); - const { __experimentalDiscussionSettings } = getSettings(); - const selectedBlock = getSelectedBlock(); - const userData = select( coreStore ).getCurrentUser(); - return { - defaultAvatar: __experimentalDiscussionSettings?.avatarURL, - clientId: selectedBlock?.clientId, - blockCommentId: selectedBlock?.attributes?.blockCommentId, - currentUser: userData, - }; - }, - [] - ); - - const userAvatar = - currentUser && currentUser.avatar_urls && currentUser.avatar_urls[ 48 ] - ? currentUser.avatar_urls[ 48 ] - : defaultAvatar; - - useEffect( () => { - setInputComment( '' ); - }, [ clientId ] ); - - const handleCancel = () => { - setShowCommentBoard( false ); - setInputComment( '' ); - }; + const { clientId, blockCommentId } = useSelect( ( select ) => { + const { getSelectedBlock } = select( blockEditorStore ); + const selectedBlock = getSelectedBlock(); + return { + clientId: selectedBlock?.clientId, + blockCommentId: selectedBlock?.attributes?.blockCommentId, + }; + } ); if ( ! showCommentBoard || ! clientId || undefined !== blockCommentId ) { return null; @@ -76,46 +48,17 @@ export function AddComment( { className="editor-collab-sidebar-panel__thread editor-collab-sidebar-panel__active-thread" > - - - { currentUser?.name ?? '' } - + - { + onSubmit( inputComment ); + } } + onCancel={ () => { + setShowCommentBoard( false ); + } } + submitButtonText={ _x( 'Comment', 'Add comment button' ) } /> - - - - - - - ); -} - /** * Renders the header of a comment in the collaboration sidebar. * @@ -321,13 +280,6 @@ function CommentHeader( { onReply, status, } ) { - const dateSettings = getDateSettings(); - const [ dateTimeFormat = dateSettings.formats.time ] = useEntityProp( - 'root', - 'site', - 'time_format' - ); - const actions = [ { title: _x( 'Edit', 'Edit comment' ), @@ -347,29 +299,15 @@ function CommentHeader( { return ( - - - - { thread.author_name } - - - { status !== 'approved' && ( - { 0 === thread.parent && onResolve && ( + { 0 === thread?.parent && onResolve && (