PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
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 / Shared / state / site-profile.js

site-profile.js in Extendify 3.0.5, at src/Shared/state/site-profile.js

42 lines 914 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 { create } from 'zustand';
3 import { createJSONStorage, devtools, persist } from 'zustand/middleware';
4
5 const { siteProfile } = window.extSharedData;
6
7 const state = (set) => ({
8 siteProfile,
9 setSiteProfile(data) {
10 set((state) => {
11 const updatedProfile = {
12 ...state.siteProfile,
13 ...data,
14 };
15 return { siteProfile: updatedProfile };
16 });
17 },
18 resetState() {
19 set({ siteProfile });
20 },
21 });
22
23 const path = '/extendify/v1/shared/site-profile';
24 const storage = {
25 getItem: async () => await apiFetch({ path }),
26 setItem: async (_name, state) => {
27 await apiFetch({
28 path,
29 method: 'POST',
30 data: { siteProfile: JSON.stringify(state) },
31 });
32 },
33 };
34
35 export const useSiteProfileStore = create(
36 persist(devtools(state, { name: 'Extendify Site Profile' }), {
37 storage: createJSONStorage(() => storage),
38 skipHydration: false,
39 }),
40 state,
41 );
42