PluginProbe
Extendify / trunk
Extendify vtrunk
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
← All changes | src/AutoLaunch/state/launch-data.js +21 -10 3.1.1 → trunk View file →
@@ -10,11 +10,13 @@
10 10 getStringsShape,
11 11 getStyleShape,
12 12 } from '@auto-launch/fetchers/shape';
13 13 import { clearSiteImages } from '@auto-launch/functions/wp';
14 -import { __ } from '@wordpress/i18n';
14 +import { launchStrings } from '@auto-launch/strings';
15 +import { siteImageUrls } from '@shared/lib/site-images';
16 +import { safeLocalStorage } from '@shared/state/safe-local-storage';
15 17 import { create } from 'zustand';
16 -import { devtools, persist } from 'zustand/middleware';
18 +import { createJSONStorage, devtools, persist } from 'zustand/middleware';
17 19 import { overrideWithUrlParams, urlParams, urlParamsShape } from './url-params';
18 20
19 21 const shapeToKeyValue = (shape) => {
20 22 return Object.fromEntries(
@@ -23,10 +25,11 @@
23 25 };
24 26
25 27 const initialState = {
26 28 go: false,
29 + showExtendifyCodeScreen: false,
27 30 // translators: this is for a action log UI. Keep it short
28 - statusMessages: [__('Booting things up', 'extendify-local')],
31 + statusMessages: [launchStrings().statusBooting],
29 32 errorMessage: null,
30 33 errorCount: 0,
31 34 title: null,
32 35 description: null,
@@ -60,10 +63,8 @@
60 63 title: undefined,
61 64 description: undefined,
62 65 descriptionBackup: undefined,
63 66 descriptionRaw: undefined,
64 - pulse: false,
65 - setPulse: (value) => set({ pulse: value }),
66 67 setData: (key, value) => {
67 68 if (!isValidKey(key)) return;
68 69 if (get()[key] === value) return; // avoid unnecessary updates
69 70 set({ [key]: value });
@@ -120,8 +121,9 @@
120 121
121 122 export const useLaunchDataStore = create(
122 123 persist(devtools(state, { name: 'Extendify Launch Data' }), {
123 124 name: `extendify-launch-data-${window.extSharedData.siteId}`,
125 + storage: createJSONStorage(() => safeLocalStorage),
124 126 merge: (p, current) => {
125 127 // Make sure the persisted state is valid and not corrupted.
126 128 const persisted = p && typeof p === 'object' ? p : {};
127 129
@@ -145,9 +147,12 @@
145 147 // If there's a URL param here it should override these values
146 148 title: title || persisted.title,
147 149 description: description || persisted.description,
148 150 descriptionRaw: description || persisted.descriptionRaw,
149 - descriptionBackup: persisted.descriptionBackup || description || title,
151 + descriptionBackup:
152 + persisted.descriptionBackup ||
153 + description ||
154 + (window.extLaunchData?.showLaunchTitle ? undefined : title),
150 155 go: go || persisted.go,
151 156 urlParams: {
152 157 title,
153 158 description,
@@ -166,19 +171,25 @@
166 171 const {
167 172 statusMessages,
168 173 errorMessage,
169 174 errorCount,
170 - pulse,
171 175 description,
172 176 descriptionRaw,
173 177 title,
178 + showExtendifyCodeScreen,
174 179 ...rest
175 180 } = state;
176 181 return Object.fromEntries(
177 - Object.entries(rest).filter(([, v]) =>
178 - Array.isArray(v) ? v.length > 0 : Boolean(v),
179 - ),
182 + Object.entries(rest).filter(([key, v]) => {
183 + // An empty set means the fetch failed; keeping it skips the retry.
184 + if (key === 'siteImages') return siteImageUrls(v).length > 0;
185 + return Array.isArray(v) ? v.length > 0 : Boolean(v);
186 + }),
180 187 );
181 188 },
182 189 }),
183 190 state,
184 191 );
192 +
193 +export const clearPersistedLaunchData = () => {
194 + useLaunchDataStore.persist.clearStorage();
195 +};