PluginProbe
Extendify / 3.0.6
Extendify v3.0.6
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 / Library / state / site.js

site.js in Extendify 3.0.6, at src/Library/state/site.js

35 lines 945 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, persist } from 'zustand/middleware';
5
6 const path = '/extendify/v1/library/settings';
7 const storage = {
8 getItem: async () => await apiFetch({ path }),
9 setItem: async (_name, state) =>
10 await apiFetch({ path, method: 'POST', data: { state } }),
11 };
12
13 const startingState = {
14 category: '',
15 totalImports: 0,
16 };
17 const incomingState = safeParseJson(window.extLibraryData.siteInfo);
18
19 export const useSiteSettingsStore = create(
20 persist(
21 (set) => ({
22 ...startingState,
23 ...(incomingState?.state ?? {}),
24 setCategory: (category) => set({ category }),
25 incrementImports: () =>
26 set((state) => ({ totalImports: Number(state.totalImports) + 1 })),
27 }),
28 {
29 name: 'extendify_library_site_data',
30 storage: createJSONStorage(() => storage),
31 skipHydration: true,
32 },
33 ),
34 );
35