From 15465be4261e4552872bc31cec0ef5a9c403d45f Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Wed, 20 Apr 2022 17:08:00 +0200 Subject: [PATCH 1/6] Add placeholder to Post Comments block --- .../block-library/src/post-comments/edit.js | 185 +++++++++++++----- .../src/post-comments/style.scss | 6 +- 2 files changed, 142 insertions(+), 49 deletions(-) diff --git a/packages/block-library/src/post-comments/edit.js b/packages/block-library/src/post-comments/edit.js index 237569227c61e7..41e872903c6952 100644 --- a/packages/block-library/src/post-comments/edit.js +++ b/packages/block-library/src/post-comments/edit.js @@ -6,7 +6,6 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useSelect } from '@wordpress/data'; import { AlignmentControl, BlockControls, @@ -14,58 +13,25 @@ import { useBlockProps, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; -import { RawHTML } from '@wordpress/element'; -import { store as coreStore } from '@wordpress/core-data'; - -function PostCommentsDisplay( { postId } ) { - return useSelect( - ( select ) => { - const comments = select( coreStore ).getEntityRecords( - 'root', - 'comment', - { - post: postId, - } - ); - // TODO: "No Comments" placeholder should be editable. - return comments && comments.length - ? comments.map( ( comment ) => ( - - { comment.content.rendered } - - ) ) - : __( 'No comments.' ); - }, - [ postId ] - ); -} +import { useSelect } from '@wordpress/data'; +import { useEntityProp, store as coreStore } from '@wordpress/core-data'; export default function PostCommentsEdit( { - attributes, + attributes: { textAlign }, setAttributes, - context, + context: { postType, postId }, } ) { - const { postType, postId } = context; - const { textAlign } = attributes; + let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId ); + postTitle = postTitle || __( 'Post Title' ); + const { name: currentUserName } = useSelect( ( select ) => + select( coreStore ).getCurrentUser() + ); const blockProps = useBlockProps( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, } ), } ); - if ( ! postType || ! postId ) { - return ( -
- - { __( 'Post comments block: no post found.' ) } - -
- ); - } - return ( <> @@ -78,7 +44,138 @@ export default function PostCommentsEdit( {
- + + { __( + 'This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments Query Loop" block.' + ) } + + +

+ { __( 'One response to' ) } “{ postTitle }” +

+ +
+
+ « { __( 'Older Comments' ) } +
+
+ { __( 'Newer Comments' ) } » +
+
+ +
    +
  1. + +
  2. +
+ +
+
+ « { __( 'Older Comments' ) } +
+
+ { __( 'Newer Comments' ) } » +
+
+ +
+

+ { __( 'Leave a Reply' ) } +

+ +
+

+ { __( 'Logged in as' ) } { currentUserName }.{ ' ' } + { __( 'Log out?' ) }{ ' ' } +

+

+ +