-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
use-show-prepublish-checks.ts
45 lines (37 loc) · 1.08 KB
/
use-show-prepublish-checks.ts
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 { useSelect, useDispatch } from '@wordpress/data';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
/**
* Internal dependencies
*/
import { SHOW_PREPUBLISH_CHECKS_ENABLED_OPTION_NAME } from '../constants';
export function useShowPrepublishChecks() {
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
const { isResolving, showPrepublishChecks } = useSelect( ( select ) => {
const { getOption, hasFinishedResolution } =
select( OPTIONS_STORE_NAME );
const showPrepublishChecksOption =
getOption( SHOW_PREPUBLISH_CHECKS_ENABLED_OPTION_NAME ) || 'yes';
const resolving = ! hasFinishedResolution( 'getOption', [
SHOW_PREPUBLISH_CHECKS_ENABLED_OPTION_NAME,
] );
return {
isResolving: resolving,
showPrepublishChecks: showPrepublishChecksOption === 'yes',
};
}, [] );
const togglePrepublishChecks = () => {
updateOptions( {
[ SHOW_PREPUBLISH_CHECKS_ENABLED_OPTION_NAME ]: showPrepublishChecks
? 'no'
: 'yes',
} );
};
return {
isResolving,
showPrepublishChecks,
togglePrepublishChecks,
};
}