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