Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Comment Content: Replace loading message with placeholder
  • Loading branch information
DAreRodz committed Oct 19, 2021
commit a9d62148376cc56975300a3c2c9c2358f7484509
15 changes: 10 additions & 5 deletions packages/block-library/src/post-comment-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { RawHTML } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useBlockProps, Warning } from '@wordpress/block-editor';
import { Disabled } from '@wordpress/components';
import { Icon, Disabled } from '@wordpress/components';
import { commentContent } from '@wordpress/icons';

/**
* Renders the `core/post-comment-content` block on the editor.
Expand All @@ -21,7 +22,7 @@ export default function Edit( { context: { commentId } } ) {
const blockProps = useBlockProps();

// Get the comment using a custom selector. This allows us to
// check if the comment is ready or not.
// check whether the comment is still loading or ready.
const { comment, isLoading } = useSelect(
( select ) => {
const { getEntityRecord, hasFinishedResolution } = select(
Expand All @@ -39,10 +40,14 @@ export default function Edit( { context: { commentId } } ) {
[ commentId ]
);

// Show a loading message if it's not ready yet. This could/should
// be replaced by some kind of placeholder.
// Show a placeholder chip if the comment is not ready yet.
if ( isLoading ) {
return <div { ...blockProps }>Loading...</div>;
return (
<div { ...blockProps }>
<Icon icon={ commentContent } />
<p> { __( 'Comment Content' ) }</p>
</div>
);
}

// Show a sample text when there is no `commentId` in the context.
Expand Down