| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
import { CheckboxControl } from '@wordpress/components'; |
| 6 |
import { useEntityProp } from '@wordpress/core-data'; |
| 7 |
import { useSelect } from '@wordpress/data'; |
| 8 |
import { Fragment } from '@wordpress/element'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Internal dependencies |
| 12 |
*/ |
| 13 |
import DisplayPlayerCheck from './check'; |
| 14 |
|
| 15 |
export function DisplayPlayer( { wrapper } ) { |
| 16 |
const Wrapper = wrapper || Fragment; |
| 17 |
|
| 18 |
const postType = useSelect( |
| 19 |
( select ) => select( 'core/editor' ).getCurrentPostType(), |
| 20 |
[] |
| 21 |
); |
| 22 |
|
| 23 |
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); |
| 24 |
|
| 25 |
const displayPlayer = meta.beyondwords_disabled !== '1'; |
| 26 |
|
| 27 |
const onUpdateDisplayPlayer = ( newDisplayPlayer ) => { |
| 28 |
setMeta( { |
| 29 |
...meta, |
| 30 |
beyondwords_disabled: newDisplayPlayer ? '' : '1', |
| 31 |
} ); |
| 32 |
}; |
| 33 |
|
| 34 |
return ( |
| 35 |
<DisplayPlayerCheck> |
| 36 |
<Wrapper> |
| 37 |
<CheckboxControl |
| 38 |
className="beyondwords--display-player" |
| 39 |
label={ __( 'Display player', 'speechkit' ) } |
| 40 |
checked={ displayPlayer } |
| 41 |
onChange={ () => { |
| 42 |
onUpdateDisplayPlayer( ! displayPlayer ); |
| 43 |
} } |
| 44 |
__nextHasNoMarginBottom |
| 45 |
/> |
| 46 |
</Wrapper> |
| 47 |
</DisplayPlayerCheck> |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
export default DisplayPlayer; |
| 52 |
|