PluginProbe
Extendify / 1.17.1
Extendify v1.17.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 / HelpCenter / state / user-selections.js

user-selections.js in Extendify 1.17.1, at src/HelpCenter/state/user-selections.js

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