♻️ Refactor hooks without changing their response

This commit is contained in:
Philipp Stracker 2025-02-21 20:53:44 +01:00
parent 0f5f571f98
commit c0dbcf6884
No known key found for this signature in database

View file

@ -41,8 +41,6 @@ const useHooks = () => {
const { useTransient, usePersistent, dispatch, select } = useStoreData();
const {
persist,
sandboxOnboardingUrl,
productionOnboardingUrl,
authenticateWithCredentials,
authenticateWithOAuth,
startWebhookSimulation,
@ -55,7 +53,6 @@ const useHooks = () => {
useTransient( 'activeHighlight' );
// Persistent accessors.
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
'useManualConnection'
);
@ -75,16 +72,10 @@ const useHooks = () => {
setActiveModal,
activeHighlight,
setActiveHighlight,
isSandboxMode,
setSandboxMode: ( state ) => {
return savePersistent( setSandboxMode, state );
},
isManualConnectionMode,
setManualConnectionMode: ( state ) => {
return savePersistent( setManualConnectionMode, state );
},
sandboxOnboardingUrl,
productionOnboardingUrl,
authenticateWithCredentials,
authenticateWithOAuth,
wooSettings,
@ -109,13 +100,23 @@ export const useStore = () => {
};
export const useSandbox = () => {
const { isSandboxMode, setSandboxMode, sandboxOnboardingUrl } = useHooks();
const { dispatch, usePersistent } = useStoreData();
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
const { sandboxOnboardingUrl, persist } = dispatch;
return { isSandboxMode, setSandboxMode, sandboxOnboardingUrl };
return {
isSandboxMode,
setSandboxMode: ( state ) => {
setSandboxMode( state );
return persist();
},
sandboxOnboardingUrl,
};
};
export const useProduction = () => {
const { productionOnboardingUrl } = useHooks();
const { dispatch } = useStoreData();
const { productionOnboardingUrl } = dispatch;
return { productionOnboardingUrl };
};