-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
40 lines (36 loc) · 939 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { CheckboxControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
function PostComments( { commentStatus = 'open', ...props } ) {
const onToggleComments = () =>
props.editPost( {
comment_status: commentStatus === 'open' ? 'closed' : 'open',
} );
return (
<CheckboxControl
label={ __( 'Allow comments' ) }
checked={ commentStatus === 'open' }
onChange={ onToggleComments }
/>
);
}
export default compose( [
withSelect( ( select ) => {
return {
commentStatus: select( editorStore ).getEditedPostAttribute(
'comment_status'
),
};
} ),
withDispatch( ( dispatch ) => ( {
editPost: dispatch( editorStore ).editPost,
} ) ),
] )( PostComments );