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 +27 -10 3.0.6 → trunk View file →
@@ -1,8 +1,9 @@
1 1 import {
2 2 getDesignBuildShape,
3 3 getHomeShape,
4 4 getImagesShape,
5 + getLaunchDecisionsShape,
5 6 getLogoShape,
6 7 getPagesShape,
7 8 getPluginsShape,
8 9 getProfileShape,
@@ -9,11 +10,13 @@
9 10 getStringsShape,
10 11 getStyleShape,
11 12 } from '@auto-launch/fetchers/shape';
12 13 import { clearSiteImages } from '@auto-launch/functions/wp';
13 -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';
14 17 import { create } from 'zustand';
15 -import { devtools, persist } from 'zustand/middleware';
18 +import { createJSONStorage, devtools, persist } from 'zustand/middleware';
16 19 import { overrideWithUrlParams, urlParams, urlParamsShape } from './url-params';
17 20
18 21 const shapeToKeyValue = (shape) => {
19 22 return Object.fromEntries(
@@ -22,12 +25,14 @@
22 25 };
23 26
24 27 const initialState = {
25 28 go: false,
29 + showExtendifyCodeScreen: false,
26 30 // translators: this is for a action log UI. Keep it short
27 - statusMessages: [__('Booting things up', 'extendify-local')],
31 + statusMessages: [launchStrings().statusBooting],
28 32 errorMessage: null,
29 33 errorCount: 0,
34 + title: null,
30 35 description: null,
31 36 descriptionBackup: undefined,
32 37 descriptionRaw: null,
33 38 urlParams: {},
@@ -33,8 +38,11 @@
33 38 urlParams: {},
34 39 siteProfile: {
35 40 ...shapeToKeyValue(getProfileShape),
36 41 },
42 + launchDecisions: {
43 + ...shapeToKeyValue(getLaunchDecisionsShape),
44 + },
37 45 ...shapeToKeyValue(getLogoShape),
38 46 ...shapeToKeyValue(getPluginsShape),
39 47 ...shapeToKeyValue(getStyleShape),
40 48 ...shapeToKeyValue(getStringsShape),
@@ -55,10 +63,8 @@
55 63 title: undefined,
56 64 description: undefined,
57 65 descriptionBackup: undefined,
58 66 descriptionRaw: undefined,
59 - pulse: false,
60 - setPulse: (value) => set({ pulse: value }),
61 67 setData: (key, value) => {
62 68 if (!isValidKey(key)) return;
63 69 if (get()[key] === value) return; // avoid unnecessary updates
64 70 set({ [key]: value });
@@ -97,8 +103,9 @@
97 103
98 104 const keySchemas = {
99 105 urlParams: urlParamsShape,
100 106 siteProfile: getProfileShape,
107 + launchDecisions: getLaunchDecisionsShape,
101 108 ...Object.fromEntries(
102 109 [
103 110 getLogoShape,
104 111 getPluginsShape,
@@ -114,8 +121,9 @@
114 121
115 122 export const useLaunchDataStore = create(
116 123 persist(devtools(state, { name: 'Extendify Launch Data' }), {
117 124 name: `extendify-launch-data-${window.extSharedData.siteId}`,
125 + storage: createJSONStorage(() => safeLocalStorage),
118 126 merge: (p, current) => {
119 127 // Make sure the persisted state is valid and not corrupted.
120 128 const persisted = p && typeof p === 'object' ? p : {};
121 129
@@ -139,9 +147,12 @@
139 147 // If there's a URL param here it should override these values
140 148 title: title || persisted.title,
141 149 description: description || persisted.description,
142 150 descriptionRaw: description || persisted.descriptionRaw,
143 - descriptionBackup: persisted.descriptionBackup || description || title,
151 + descriptionBackup:
152 + persisted.descriptionBackup ||
153 + description ||
154 + (window.extLaunchData?.showLaunchTitle ? undefined : title),
144 155 go: go || persisted.go,
145 156 urlParams: {
146 157 title,
147 158 description,
@@ -160,19 +171,25 @@
160 171 const {
161 172 statusMessages,
162 173 errorMessage,
163 174 errorCount,
164 - pulse,
165 175 description,
166 176 descriptionRaw,
167 177 title,
178 + showExtendifyCodeScreen,
168 179 ...rest
169 180 } = state;
170 181 return Object.fromEntries(
171 - Object.entries(rest).filter(([, v]) =>
172 - Array.isArray(v) ? v.length > 0 : Boolean(v),
173 - ),
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 + }),
174 187 );
175 188 },
176 189 }),
177 190 state,
178 191 );
192 +
193 +export const clearPersistedLaunchData = () => {
194 + useLaunchDataStore.persist.clearStorage();
195 +};