Skip to content

Commit

Permalink
Distinguish first comment from others.
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Dec 10, 2024
1 parent 050e926 commit 2189aef
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/block-library/src/comment-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { __ } from '@wordpress/i18n';
import { RawHTML } from '@wordpress/element';
import { Disabled } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import {
AlignmentControl,
BlockControls,
store as blockEditorStore,
useBlockProps,
} from '@wordpress/block-editor';

Expand All @@ -25,13 +27,15 @@ import {
* @param {string} props.attributes.textAlign The `textAlign` attribute.
* @param {Object} props.context Inherited context.
* @param {string} props.context.commentId The comment ID.
* @param {string} props.clientId The block client ID.
*
* @return {JSX.Element} React element.
*/
export default function Edit( {
setAttributes,
attributes: { textAlign },
context: { commentId },
clientId,
} ) {
const blockProps = useBlockProps( {
className: clsx( {
Expand All @@ -44,6 +48,13 @@ export default function Edit( {
'content',
commentId
);
const isFirstCommentContentBlockinTemplate = useSelect(
( select ) =>
select( blockEditorStore ).getBlockParentsByBlockName(
clientId,
'core/comment-template'
).length > 0
);

const blockControls = (
<BlockControls group="block">
Expand All @@ -62,9 +73,11 @@ export default function Edit( {
{ blockControls }
<div { ...blockProps }>
<p>
{ __(
'This is the Comment Content block. It displays the text of user comments submitted on your site, ranging from short remarks to longer, multi-paragraph responses.'
) }
{ isFirstCommentContentBlockinTemplate
? __(
'This is the Comment Content block. It displays the text of user comments submitted on your site, ranging from short remarks to longer, multi-paragraph responses.'
)
: __( 'This is another Comment Content block.' ) }
</p>
</div>
</>
Expand Down

0 comments on commit 2189aef

Please sign in to comment.