-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changes from previous merge attempt
- Loading branch information
Showing
9 changed files
with
381 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
AlignmentControl, | ||
BlockControls, | ||
Warning, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useEntityProp, store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CommentsInspectorControls from './comments-inspector-controls'; | ||
import Placeholder from './placeholder'; | ||
|
||
export default function PostCommentsEdit( { | ||
attributes, | ||
setAttributes, | ||
context: { postType, postId }, | ||
clientId, | ||
} ) { | ||
const { tagName: TagName, textAlign } = attributes; | ||
|
||
const [ commentStatus ] = useEntityProp( | ||
'postType', | ||
postType, | ||
'comment_status', | ||
postId | ||
); | ||
|
||
const { defaultCommentStatus } = useSelect( | ||
( select ) => | ||
select( blockEditorStore ).getSettings() | ||
.__experimentalDiscussionSettings | ||
); | ||
|
||
const innerBlocks = useSelect( ( select ) => | ||
select( blockEditorStore ).getBlocks( clientId ) | ||
); | ||
|
||
const isSiteEditor = postType === undefined || postId === undefined; | ||
|
||
const postTypeSupportsComments = useSelect( ( select ) => | ||
postType | ||
? !! select( coreStore ).getPostType( postType )?.supports.comments | ||
: false | ||
); | ||
|
||
let warning = __( | ||
'Post Comments block: 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.' | ||
); | ||
let showPlacholder = true; | ||
|
||
if ( ! isSiteEditor && 'open' !== commentStatus ) { | ||
if ( 'closed' === commentStatus ) { | ||
warning = sprintf( | ||
/* translators: 1: Post type (i.e. "post", "page") */ | ||
__( | ||
'Post Comments block: Comments to this %s are not allowed.' | ||
), | ||
postType | ||
); | ||
showPlacholder = false; | ||
} else if ( ! postTypeSupportsComments ) { | ||
warning = sprintf( | ||
/* translators: 1: Post type (i.e. "post", "page") */ | ||
__( | ||
'Post Comments block: Comments for this post type (%s) are not enabled.' | ||
), | ||
postType | ||
); | ||
showPlacholder = false; | ||
} else if ( 'open' !== defaultCommentStatus ) { | ||
warning = __( 'Post Comments block: Comments are not enabled.' ); | ||
showPlacholder = false; | ||
} | ||
} | ||
|
||
const blockProps = useBlockProps( { | ||
className: classnames( { | ||
[ `has-text-align-${ textAlign }` ]: textAlign, | ||
} ), | ||
} ); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps ); | ||
|
||
if ( innerBlocks.length > 0 ) { | ||
return ( | ||
<> | ||
<CommentsInspectorControls | ||
attributes={ attributes } | ||
setAttributes={ setAttributes } | ||
/> | ||
<TagName { ...innerBlocksProps } /> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<BlockControls group="block"> | ||
<AlignmentControl | ||
value={ textAlign } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { textAlign: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
|
||
<div { ...blockProps }> | ||
<Warning>{ warning }</Warning> | ||
|
||
{ showPlacholder && ( | ||
<Placeholder postId={ postId } postType={ postType } /> | ||
) } | ||
</div> | ||
</> | ||
); | ||
} |
121 changes: 121 additions & 0 deletions
121
packages/block-library/src/comments/edit/placeholder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { useDisabled } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CommentsForm from '../../post-comments-form/form'; | ||
|
||
export default function PostCommentsPlaceholder( { postType, postId } ) { | ||
let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId ); | ||
postTitle = postTitle || __( 'Post Title' ); | ||
|
||
const { avatarURL } = useSelect( | ||
( select ) => | ||
select( blockEditorStore ).getSettings() | ||
.__experimentalDiscussionSettings | ||
); | ||
|
||
const disabledRef = useDisabled(); | ||
|
||
return ( | ||
<div | ||
className="wp-block-post-comments__placeholder" | ||
ref={ disabledRef } | ||
> | ||
<h3> | ||
{ __( 'One response to' ) } “{ postTitle }” | ||
</h3> | ||
|
||
<div className="navigation"> | ||
<div className="alignleft"> | ||
<a href="#top">« { __( 'Older Comments' ) }</a> | ||
</div> | ||
<div className="alignright"> | ||
<a href="#top">{ __( 'Newer Comments' ) } »</a> | ||
</div> | ||
</div> | ||
|
||
<ol className="commentlist"> | ||
<li className="comment even thread-even depth-1"> | ||
<article className="comment-body"> | ||
<footer className="comment-meta"> | ||
<div className="comment-author vcard"> | ||
<img | ||
alt="Commenter Avatar" | ||
src={ avatarURL } | ||
className="avatar avatar-32 photo" | ||
height="32" | ||
width="32" | ||
loading="lazy" | ||
/> | ||
<b className="fn"> | ||
<a href="#top" className="url"> | ||
{ __( 'A WordPress Commenter' ) } | ||
</a> | ||
</b>{ ' ' } | ||
<span className="says">{ __( 'says' ) }:</span> | ||
</div> | ||
|
||
<div className="comment-metadata"> | ||
<a href="#top"> | ||
<time dateTime="2000-01-01T00:00:00+00:00"> | ||
{ __( 'January 1, 2000 at 00:00 am' ) } | ||
</time> | ||
</a>{ ' ' } | ||
<span className="edit-link"> | ||
<a | ||
className="comment-edit-link" | ||
href="#top" | ||
> | ||
{ __( 'Edit' ) } | ||
</a> | ||
</span> | ||
</div> | ||
</footer> | ||
|
||
<div className="comment-content"> | ||
<p> | ||
{ __( 'Hi, this is a comment.' ) } | ||
<br /> | ||
{ __( | ||
'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.' | ||
) } | ||
<br /> | ||
{ __( 'Commenter avatars come from' ) }{ ' ' } | ||
<a href="https://gravatar.com/">Gravatar</a>. | ||
</p> | ||
</div> | ||
|
||
<div className="reply"> | ||
<a | ||
className="comment-reply-link" | ||
href="#top" | ||
aria-label="Reply to A WordPress Commenter" | ||
> | ||
{ __( 'Reply' ) } | ||
</a> | ||
</div> | ||
</article> | ||
</li> | ||
</ol> | ||
|
||
<div className="navigation"> | ||
<div className="alignleft"> | ||
<a href="#top">« { __( 'Older Comments' ) }</a> | ||
</div> | ||
<div className="alignright"> | ||
<a href="#top">{ __( 'Newer Comments' ) } »</a> | ||
</div> | ||
</div> | ||
|
||
<CommentsForm /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.