PluginProbe
Extendify / 3.1.6
Extendify v3.1.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 / Launch / state / pages-selections.js

pages-selections.js in Extendify 3.1.6, at src/Launch/state/pages-selections.js

43 lines 1.1 KB
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 { safeLocalStorage } from '@shared/state/safe-local-storage';
3 import { create } from 'zustand';
4 import { createJSONStorage, devtools, persist } from 'zustand/middleware';
5
6 const initialState = {
7 pages: [],
8 style: null,
9 };
10
11 const key = `extendify-launch-pages-selection-${window.extSharedData.siteId}`;
12 const state = (set, get) => ({
13 // initialize the state with default values
14 ...initialState,
15 ...(safeParseJson(window.localStorage.getItem(key))?.state || {}),
16 has(type, item) {
17 if (!item?.id) return false;
18 return (get()?.[type] ?? [])?.some((t) => t.id === item.id);
19 },
20 add(type, item) {
21 if (get().has(type, item)) return;
22 set({ [type]: [...(get()?.[type] ?? []), item] });
23 },
24 remove(type, item) {
25 set({ [type]: get()?.[type]?.filter((t) => t.id !== item.id) });
26 },
27 removeAll(type) {
28 set({ [type]: [] });
29 },
30 setStyle(style) {
31 set({ style });
32 },
33 });
34
35 export const usePagesSelectionStore = create(
36 persist(devtools(state, { name: 'Extendify Launch Pages Selections' }), {
37 name: key,
38 storage: createJSONStorage(() => safeLocalStorage),
39 skipHydration: true,
40 }),
41 state,
42 );
43