forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline Commenting: Update placement of reply input and add author inf…
…o header (WordPress#66580)
- Loading branch information
Showing
4 changed files
with
187 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/editor/src/components/collab-sidebar/comment-author-info.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalVStack as VStack } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { dateI18n, getSettings as getDateSettings } from '@wordpress/date'; | ||
import { useEntityProp, store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Render author information for a comment. | ||
* | ||
* @param {Object} props - Component properties. | ||
* @param {string} props.avatar - URL of the author's avatar. | ||
* @param {string} props.name - Name of the author. | ||
* @param {string} props.date - Date of the comment. | ||
* | ||
* @return {JSX.Element} The JSX element representing the author's information. | ||
*/ | ||
function CommentAuthorInfo( { avatar, name, date } ) { | ||
const dateSettings = getDateSettings(); | ||
const [ dateTimeFormat = dateSettings.formats.time ] = useEntityProp( | ||
'root', | ||
'site', | ||
'time_format' | ||
); | ||
|
||
const { currentUserAvatar, currentUserName } = useSelect( ( select ) => { | ||
const userData = select( coreStore ).getCurrentUser(); | ||
|
||
const { getSettings } = select( blockEditorStore ); | ||
const { __experimentalDiscussionSettings } = getSettings(); | ||
const defaultAvatar = __experimentalDiscussionSettings?.avatarURL; | ||
return { | ||
currentUserAvatar: userData?.avatar_urls[ 48 ] ?? defaultAvatar, | ||
currentUserName: userData?.name, | ||
}; | ||
}, [] ); | ||
|
||
const currentDate = new Date(); | ||
|
||
return ( | ||
<> | ||
<img | ||
src={ avatar ?? currentUserAvatar } | ||
className="editor-collab-sidebar-panel__user-avatar" | ||
// translators: alt text for user avatar image | ||
alt={ __( 'User avatar' ) } | ||
width={ 32 } | ||
height={ 32 } | ||
/> | ||
<VStack spacing="0"> | ||
<span className="editor-collab-sidebar-panel__user-name"> | ||
{ name ?? currentUserName } | ||
</span> | ||
<time | ||
dateTime={ dateI18n( 'c', date ?? currentDate ) } | ||
className="editor-collab-sidebar-panel__user-time" | ||
> | ||
{ dateI18n( dateTimeFormat, date ?? currentDate ) } | ||
</time> | ||
</VStack> | ||
</> | ||
); | ||
} | ||
|
||
export default CommentAuthorInfo; |
62 changes: 62 additions & 0 deletions
62
packages/editor/src/components/collab-sidebar/comment-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { | ||
__experimentalHStack as HStack, | ||
Button, | ||
TextareaControl, | ||
} from '@wordpress/components'; | ||
import { _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { sanitizeCommentString } from './utils'; | ||
|
||
/** | ||
* EditComment component. | ||
* | ||
* @param {Object} props - The component props. | ||
* @param {Function} props.onSubmit - The function to call when updating the comment. | ||
* @param {Function} props.onCancel - The function to call when canceling the comment update. | ||
* @param {Object} props.thread - The comment thread object. | ||
* @param {string} props.submitButtonText - The text to display on the submit button. | ||
* @return {JSX.Element} The CommentForm component. | ||
*/ | ||
function CommentForm( { onSubmit, onCancel, thread, submitButtonText } ) { | ||
const [ inputComment, setInputComment ] = useState( | ||
thread?.content?.raw ?? '' | ||
); | ||
|
||
return ( | ||
<> | ||
<TextareaControl | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
value={ inputComment ?? '' } | ||
onChange={ setInputComment } | ||
/> | ||
<HStack alignment="left" spacing="3" justify="flex-start"> | ||
<Button | ||
__next40pxDefaultSize | ||
accessibleWhenDisabled | ||
variant="primary" | ||
onClick={ () => onSubmit( inputComment ) } | ||
disabled={ | ||
0 === sanitizeCommentString( inputComment ).length | ||
} | ||
text={ submitButtonText } | ||
/> | ||
<Button | ||
__next40pxDefaultSize | ||
variant="tertiary" | ||
onClick={ onCancel } | ||
text={ _x( 'Cancel', 'Cancel comment button' ) } | ||
/> | ||
</HStack> | ||
</> | ||
); | ||
} | ||
|
||
export default CommentForm; |
Oops, something went wrong.