-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
43 lines (37 loc) · 1.02 KB
/
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
41
42
43
/**
* External dependencies
*/
import { connect } from 'react-redux';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { FormToggle, withInstanceId } from '@wordpress/components';
/**
* Internal Dependencies
*/
import { getEditedPostAttribute } from '../../store/selectors';
import { editPost } from '../../store/actions';
function PostComments( { commentStatus = 'open', instanceId, ...props } ) {
const onToggleComments = () => props.editPost( { comment_status: commentStatus === 'open' ? 'closed' : 'open' } );
const commentsToggleId = 'allow-comments-toggle-' + instanceId;
return [
<label key="label" htmlFor={ commentsToggleId }>{ __( 'Allow Comments' ) }</label>,
<FormToggle
key="toggle"
checked={ commentStatus === 'open' }
onChange={ onToggleComments }
id={ commentsToggleId }
/>,
];
}
export default connect(
( state ) => {
return {
commentStatus: getEditedPostAttribute( state, 'comment_status' ),
};
},
{
editPost,
}
)( withInstanceId( PostComments ) );