Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Comments Form: Add button that enables commenting to warning #41603

Merged
merged 12 commits into from
Jun 17, 2022
23 changes: 20 additions & 3 deletions packages/block-library/src/post-comments-form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { Button } from '@wordpress/components';
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import { __, _x, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
Expand All @@ -28,7 +30,7 @@ export default function PostCommentsFormEdit( {
} ) {
const { textAlign } = attributes;
const { postId, postType } = context;
const [ commentStatus ] = useEntityProp(
const [ commentStatus, setCommentStatus ] = useEntityProp(
'postType',
postType,
'comment_status',
Expand All @@ -55,6 +57,7 @@ export default function PostCommentsFormEdit( {
);

let warning = false;
let actions;
let showPlaceholder = true;

if ( ! isSiteEditor && 'open' !== commentStatus ) {
Expand All @@ -66,6 +69,18 @@ export default function PostCommentsFormEdit( {
),
postType
);
actions = [
<Button
key="enableComments"
onClick={ () => setCommentStatus( 'open' ) }
variant="primary"
>
{ _x(
'Enable comments',
'action that affects the current post'
) }
</Button>,
];
showPlaceholder = false;
} else if ( ! postTypeSupportsComments ) {
warning = sprintf(
Expand Down Expand Up @@ -95,7 +110,9 @@ export default function PostCommentsFormEdit( {
/>
</BlockControls>
<div { ...blockProps }>
{ warning && <Warning>{ warning }</Warning> }
{ warning && (
<Warning actions={ actions }>{ warning }</Warning>
) }

{ showPlaceholder ? <CommentsForm /> : null }
</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/post-comments-form/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.wp-block-post-comments-form * {
pointer-events: none;

&.block-editor-warning * {
pointer-events: auto;
}
}