PHP 8.2.31
Preview: pages-selections.js Size: 1.07 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/extendify_old/src/Launch/state/pages-selections.js

import { safeParseJson } from '@shared/lib/parsing';
import { create } from 'zustand';
import { createJSONStorage, devtools, persist } from 'zustand/middleware';

const initialState = {
	pages: [],
	style: null,
};

const key = `extendify-launch-pages-selection-${window.extSharedData.siteId}`;
const state = (set, get) => ({
	// initialize the state with default values
	...initialState,
	...(safeParseJson(window.localStorage.getItem(key))?.state || {}),
	has(type, item) {
		if (!item?.id) return false;
		return (get()?.[type] ?? [])?.some((t) => t.id === item.id);
	},
	add(type, item) {
		if (get().has(type, item)) return;
		set({ [type]: [...(get()?.[type] ?? []), item] });
	},
	remove(type, item) {
		set({ [type]: get()?.[type]?.filter((t) => t.id !== item.id) });
	},
	removeAll(type) {
		set({ [type]: [] });
	},
	setStyle(style) {
		set({ style });
	},
});

export const usePagesSelectionStore = create(
	persist(devtools(state, { name: 'Extendify Launch Pages Selections' }), {
		name: key,
		storage: createJSONStorage(() => localStorage),
		skipHydration: true,
	}),
	state,
);

Directory Contents

Dirs: 0 × Files: 5

Name Size Perms Modified Actions
190 B lrw-r--r-- 2023-10-11 06:07:34
Edit Download
257 B lrw-r--r-- 2023-10-11 06:07:34
Edit Download
1.07 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
3.38 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
5.15 KB lrw-r--r-- 2026-02-27 04:48:52
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).