-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
edit.js
36 lines (34 loc) · 874 Bytes
/
edit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useEntityId } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';
function PostCommentsDisplay( { postId } ) {
return useSelect(
( select ) => {
const comments = select( 'core' ).getEntityRecords(
'root',
'comment',
{
post: postId,
}
);
// TODO: "No Comments" placeholder should be editable.
return comments && comments.length
? comments.map( ( comment ) => (
<p key={ comment.id }>{ comment.content.raw }</p>
) )
: __( 'No comments.' );
},
[ postId ]
);
}
export default function PostCommentsEdit() {
// TODO: Update to handle multiple post types.
const postId = useEntityId( 'postType', 'post' );
if ( ! postId ) {
return __( 'Post Comments' );
}
return <PostCommentsDisplay postId={ postId } />;
}