Skip to content
Prev Previous commit
Next Next commit
Revert "Loose coupling"
This reverts commit d1a9f97.
  • Loading branch information
ockham committed Jun 17, 2022
commit 8bc89aa81935e06b22a5b932f10091674ebf21a9
39 changes: 15 additions & 24 deletions packages/block-library/src/post-comments-form/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Button } from '@wordpress/components';
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -41,15 +42,7 @@ export default function PostCommentsFormEdit( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ),
} );

// We're deliberately using the string literal to avoid tight coupling
// to `@wordpress/editor`, since we don't want the block-library package
// to depend on it, in order to keep it backend agnostic. For more details, see
// https://github.com/WordPress/gutenberg/pull/41603#discussion_r893429223
// Alternatively, we could consider using a dynamic import.
//
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const editorDispatcher = useDispatch( 'core/editor' );
const { editPost } = useDispatch( editorStore );

const isSiteEditor = postType === undefined || postId === undefined;

Expand Down Expand Up @@ -78,21 +71,19 @@ export default function PostCommentsFormEdit( {
),
postType
);
if ( editorDispatcher ) {
const enableComments = () =>
editorDispatcher.editPost( {
comment_status: 'open',
} );
actions = [
<Button
key="enableComments"
onClick={ enableComments }
variant="primary"
>
{ __( 'Enable comments' ) }
</Button>,
];
}
const enableComments = () =>
editPost( {
comment_status: 'open',
} );
actions = [
<Button
key="enableComments"
onClick={ enableComments }
variant="primary"
>
{ __( 'Enable comments' ) }
</Button>,
];
showPlaceholder = false;
} else if ( ! postTypeSupportsComments ) {
warning = sprintf(
Expand Down