PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Assist / state / user-selections.js

user-selections.js in Extendify 3.2.1, at src/Assist/state/user-selections.js

41 lines 1003 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { safeParseJson } from '@shared/lib/parsing';
2 import apiFetch from '@wordpress/api-fetch';
3 import { create } from 'zustand';
4 import { createJSONStorage, devtools, persist } from 'zustand/middleware';
5
6 const startingState = {
7 siteType: {
8 slug: '0default',
9 name: 'Default',
10 },
11 siteInformation: {
12 title: undefined,
13 },
14 variation: null,
15 style: null,
16 pages: [],
17 sitePlugins: [],
18 // initialize the state with default values
19 ...(safeParseJson(window.extSharedData.launchDataLegacy)?.state ?? {}),
20 };
21
22 const state = () => ({
23 ...startingState,
24 // Add methods here
25 });
26
27 const path = '/extendify/v1/shared/user-selections-data';
28 const storage = {
29 getItem: async () => await apiFetch({ path }),
30 setItem: async (_name, state) =>
31 await apiFetch({ path, method: 'POST', data: { state } }),
32 };
33
34 export const useUserSelectionStore = create(
35 persist(devtools(state, { name: 'Extendify User Selections' }), {
36 storage: createJSONStorage(() => storage),
37 skipHydration: true,
38 }),
39 state,
40 );
41