summaryrefslogtreecommitdiff
blob: dfe1e6c5405de75d6a97b8f6643064e6c801db19 (plain)
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
44
45
/**
 * External dependencies
 */
import { __ } from '@wordpress/i18n';
import { CheckboxControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { PostTypeSupportCheck } from '@wordpress/editor';
import { withDispatch, withSelect } from '@wordpress/data';

/**
 * Internal dependencies
 */
import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';

const SharingCheckbox = ( { isSharingEnabled, editPost } ) => (
	<PostTypeSupportCheck supportKeys="jetpack-sharing-buttons">
		<JetpackLikesAndSharingPanel>
			<CheckboxControl
				label={ __( 'Show sharing buttons.', 'jetpack' ) }
				checked={ isSharingEnabled }
				onChange={ value => {
					editPost( { jetpack_sharing_enabled: value } );
				} }
			/>
		</JetpackLikesAndSharingPanel>
	</PostTypeSupportCheck>
);

// Fetch the post meta.
const applyWithSelect = withSelect( select => {
	const { getEditedPostAttribute } = select( 'core/editor' );
	const isSharingEnabled = getEditedPostAttribute( 'jetpack_sharing_enabled' );

	return { isSharingEnabled };
} );

// Provide method to update post meta.
const applyWithDispatch = withDispatch( dispatch => {
	const { editPost } = dispatch( 'core/editor' );

	return { editPost };
} );

// Combine the higher-order components.
export default compose( [ applyWithSelect, applyWithDispatch ] )( SharingCheckbox );