Skip to content

Commit

Permalink
Post content: show placeholder if trying to render itself (#24010)
Browse files Browse the repository at this point in the history
Co-authored-by: Noah Allen <noahtallen@gmail.com>
  • Loading branch information
Addison-Stavlo and noahtallen committed Aug 31, 2020
1 parent c47ba60 commit 970e8e0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@import "./navigation-link/editor.scss";
@import "./nextpage/editor.scss";
@import "./paragraph/editor.scss";
@import "./post-content/editor.scss";
@import "./post-excerpt/editor.scss";
@import "./post-author/editor.scss";
@import "./pullquote/editor.scss";
Expand Down
29 changes: 25 additions & 4 deletions packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PostContentInnerBlocks from './inner-blocks';

export default function PostContentEdit( { context: { postId, postType } } ) {
if ( postId && postType ) {
export default function PostContentEdit( {
context: { postId: contextPostId, postType: contextPostType },
} ) {
const { id: currentPostId, type: currentPostType } = useSelect(
( select ) => select( 'core/editor' ).getCurrentPost() ?? {}
);

// Only render InnerBlocks if the context is different from the active post
// to avoid infinite recursion of post content.
if (
contextPostId &&
contextPostType &&
contextPostId !== currentPostId &&
contextPostType !== currentPostType
) {
return (
<PostContentInnerBlocks postType={ postType } postId={ postId } />
<PostContentInnerBlocks
postType={ contextPostType }
postId={ contextPostId }
/>
);
}
return <p>{ __( 'This is a placeholder for post content.' ) }</p>;
return (
<div className="wp-block-post-content__placeholder">
<span>{ __( 'This is a placeholder for post content.' ) }</span>
</div>
);
}
11 changes: 11 additions & 0 deletions packages/block-library/src/post-content/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.wp-block-post-content__placeholder {
height: 100px;
border: 1px dashed;
display: flex;
justify-content: center;
align-items: center;

span {
font-style: italic;
}
}
7 changes: 2 additions & 5 deletions packages/block-library/src/query-loop/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ import { useQueryContext } from '../query';
const TEMPLATE = [ [ 'core/post-title' ], [ 'core/post-content' ] ];
export default function QueryLoopEdit( {
clientId,
context: {
query: { perPage, offset, categoryIds },
queryContext,
},
context: { query: { perPage, offset, categoryIds } = {}, queryContext },
} ) {
const [ { page } ] = useQueryContext() || queryContext;
const [ { page } ] = useQueryContext() || queryContext || [ {} ];
const [ activeBlockContext, setActiveBlockContext ] = useState();

const { posts, blocks } = useSelect(
Expand Down

0 comments on commit 970e8e0

Please sign in to comment.