@applicaster/zapp-react-native-utils 13.0.0-rc.99 → 14.0.0-alpha.1216545755
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutorContext.tsx +87 -67
- package/actionsExecutor/ScreenActions.ts +92 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/consts.ts +4 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/appUtils/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
- package/appUtils/__tests__/allZappLocales.ts +79 -0
- package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
- package/appUtils/accessibilityManager/const.ts +18 -0
- package/appUtils/accessibilityManager/index.ts +4 -1
- package/appUtils/contextKeysManager/contextResolver.ts +14 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
- package/appUtils/focusManager/index.ios.ts +14 -4
- package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
- package/appUtils/focusManager/utils/index.ts +5 -0
- package/appUtils/localizationsHelper.ts +10 -2
- package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +7 -2
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
- package/audioPlayerUtils/assets/index.ts +2 -0
- package/audioPlayerUtils/index.ts +242 -0
- package/cellUtils/index.ts +9 -5
- package/componentsUtils/index.ts +8 -1
- package/conf/player/__tests__/selectors.test.ts +34 -0
- package/conf/player/selectors.ts +10 -0
- package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
- package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
- package/configurationUtils/index.ts +63 -34
- package/localizationUtils/index.ts +3 -3
- package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
- package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
- package/manifestUtils/createConfig.js +4 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +13 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +1228 -205
- package/manifestUtils/index.js +2 -0
- package/manifestUtils/keys.js +27 -2
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +1 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +0 -65
- package/navigationUtils/index.ts +0 -31
- package/package.json +2 -2
- package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
- package/playerUtils/_internals/index.ts +1 -0
- package/playerUtils/_internals/utils.ts +31 -0
- package/playerUtils/configurationUtils.ts +0 -44
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +25 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/app/useAppState.ts +2 -2
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -0
- package/reactHooks/feed/useBatchLoading.ts +12 -14
- package/reactHooks/feed/useFeedLoader.tsx +12 -5
- package/reactHooks/navigation/{useGetTabBarHeight.ts → getTabBarHeight.ts} +1 -1
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +10 -3
- package/reactHooks/navigation/useNavigationPluginData.ts +8 -4
- package/reactHooks/navigation/useNavigationType.ts +4 -2
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +11 -0
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
- package/reactHooks/state/README.md +79 -0
- package/reactHooks/state/ZStoreProvider.tsx +71 -0
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +66 -0
- package/reactHooks/state/index.ts +2 -0
- package/reactHooks/useListenEventBusEvent.ts +1 -1
- package/reactUtils/index.ts +9 -0
- package/storage/ScreenSingleValueProvider.ts +198 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/typeGuards/index.ts +3 -0
- package/utils/index.ts +12 -1
- package/zappFrameworkUtils/localStorageHelper.ts +32 -10
- package/playerUtils/configurationGenerator.ts +0 -2588
|
@@ -5,13 +5,17 @@ import {
|
|
|
5
5
|
actionExecutor as _actionExecutor,
|
|
6
6
|
ActionResult,
|
|
7
7
|
} from "./ActionExecutor";
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
batchRemoveAllFromNamespaceForStorage,
|
|
10
|
+
batchSave,
|
|
11
|
+
} from "../zappFrameworkUtils/localStorageHelper";
|
|
12
|
+
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
13
|
+
|
|
10
14
|
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
15
|
+
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
11
16
|
import { showConfirmationDialog } from "../alertUtils";
|
|
12
17
|
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
13
18
|
import { createLogger } from "../logger";
|
|
14
|
-
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
|
|
15
19
|
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
16
20
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
17
21
|
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
@@ -20,12 +24,19 @@ import {
|
|
|
20
24
|
resolveObjectValues,
|
|
21
25
|
} from "../appUtils/contextKeysManager/contextResolver";
|
|
22
26
|
import { useNavigation } from "../reactHooks";
|
|
23
|
-
import { get } from "lodash";
|
|
24
27
|
|
|
25
28
|
import {
|
|
26
29
|
useContentTypes,
|
|
27
30
|
usePickFromState,
|
|
28
31
|
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
32
|
+
import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
33
|
+
import { APP_EVENTS } from "../appUtils/events";
|
|
34
|
+
import {
|
|
35
|
+
localStorageToggleFlag,
|
|
36
|
+
sessionStorageToggleFlag,
|
|
37
|
+
} from "./StorageActions";
|
|
38
|
+
|
|
39
|
+
import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
|
|
29
40
|
|
|
30
41
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
31
42
|
subsystem: "ActionExecutorContext",
|
|
@@ -77,7 +88,15 @@ function findParentComponent(
|
|
|
77
88
|
const prepareDefaultActions = (actionExecutor) => {
|
|
78
89
|
actionExecutor.registerAction("localStorageSet", async (action) => {
|
|
79
90
|
const namespaces = action.options.content;
|
|
80
|
-
await
|
|
91
|
+
await batchSave(namespaces, localStorage);
|
|
92
|
+
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
93
|
+
|
|
94
|
+
return ActionResult.Success;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
actionExecutor.registerAction("sessionStorageSet", async (action) => {
|
|
98
|
+
const namespaces = action.options.content;
|
|
99
|
+
await batchSave(namespaces, sessionStorage);
|
|
81
100
|
// TODO: Add support for ownershipKey and ownershipNamespace
|
|
82
101
|
|
|
83
102
|
return ActionResult.Success;
|
|
@@ -134,15 +153,13 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
134
153
|
actionExecutor.registerAction("confirmDialog", async (action) => {
|
|
135
154
|
log_info("handleAction: confirmDialog event");
|
|
136
155
|
|
|
137
|
-
|
|
156
|
+
return new Promise<ActionResult>((resolve) => {
|
|
138
157
|
showConfirmationDialog({
|
|
139
158
|
...action.options,
|
|
140
159
|
confirmCompletion: () => resolve(ActionResult.Success),
|
|
141
160
|
cancelCompletion: () => resolve(ActionResult.Cancel),
|
|
142
161
|
});
|
|
143
162
|
});
|
|
144
|
-
|
|
145
|
-
return confirmationPromise;
|
|
146
163
|
});
|
|
147
164
|
|
|
148
165
|
actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
|
|
@@ -151,10 +168,15 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
151
168
|
|
|
152
169
|
const entry = context?.entry || {};
|
|
153
170
|
const entryResolver = new EntryResolver(entry);
|
|
171
|
+
const screenData = context?.screenStateStore.getState().data || {};
|
|
172
|
+
const screenResolver = new EntryResolver(screenData || {});
|
|
154
173
|
|
|
155
174
|
const data =
|
|
156
175
|
options?.data && options.inflateData
|
|
157
|
-
? await resolveObjectValues(options.data, {
|
|
176
|
+
? await resolveObjectValues(options.data, {
|
|
177
|
+
entry: entryResolver,
|
|
178
|
+
screen: screenResolver,
|
|
179
|
+
})
|
|
158
180
|
: options?.data || entry;
|
|
159
181
|
|
|
160
182
|
const cloudEvent = await createCloudEvent({
|
|
@@ -189,73 +211,56 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
189
211
|
});
|
|
190
212
|
|
|
191
213
|
actionExecutor.registerAction(
|
|
192
|
-
"
|
|
214
|
+
"sessionStorageToggleFlag",
|
|
193
215
|
async (
|
|
194
216
|
action: ActionType,
|
|
195
217
|
context?: Record<string, any>
|
|
196
218
|
): Promise<ActionResult> => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
return ActionResult.Error;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const entry = context?.entry as ZappEntry;
|
|
206
|
-
|
|
207
|
-
if (!entry) {
|
|
208
|
-
log_error(
|
|
209
|
-
"handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
return ActionResult.Error;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const tag = action.options?.selector
|
|
216
|
-
? get(entry, action.options.selector)
|
|
217
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
218
|
-
|
|
219
|
-
const keyNamespace = action.options?.key;
|
|
220
|
-
|
|
221
|
-
if (keyNamespace && tag) {
|
|
222
|
-
const multiSelectProvider =
|
|
223
|
-
StorageMultiSelectProvider.getProvider(keyNamespace);
|
|
224
|
-
|
|
225
|
-
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
226
|
-
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
227
|
-
|
|
228
|
-
log_info(
|
|
229
|
-
`handleAction: localStorageToggleFlag event will ${
|
|
230
|
-
isTagInSelectedItems ? "remove" : "add"
|
|
231
|
-
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
if (selectedItems.includes(tag)) {
|
|
235
|
-
await multiSelectProvider.removeItem(tag);
|
|
236
|
-
} else {
|
|
237
|
-
const maxItems = action.options?.max_items;
|
|
219
|
+
return await sessionStorageToggleFlag(context, action);
|
|
220
|
+
}
|
|
221
|
+
);
|
|
238
222
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
223
|
+
actionExecutor.registerAction(
|
|
224
|
+
"localStorageToggleFlag",
|
|
225
|
+
async (
|
|
226
|
+
action: ActionType,
|
|
227
|
+
context?: Record<string, any>
|
|
228
|
+
): Promise<ActionResult> => {
|
|
229
|
+
return await localStorageToggleFlag(context, action);
|
|
230
|
+
}
|
|
231
|
+
);
|
|
243
232
|
|
|
244
|
-
|
|
245
|
-
|
|
233
|
+
actionExecutor.registerAction(
|
|
234
|
+
"screenSetVariable",
|
|
235
|
+
async (
|
|
236
|
+
action: ActionType,
|
|
237
|
+
context?: Record<string, any>
|
|
238
|
+
): Promise<ActionResult> => {
|
|
239
|
+
const route = context?.screenRoute;
|
|
240
|
+
const { key, value } = action.options;
|
|
241
|
+
screenSetVariable(route, key, value);
|
|
246
242
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
log_error(
|
|
251
|
-
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
252
|
-
{ keyNamespace, tag }
|
|
253
|
-
);
|
|
243
|
+
return Promise.resolve(ActionResult.Success);
|
|
244
|
+
}
|
|
245
|
+
);
|
|
254
246
|
|
|
255
|
-
|
|
256
|
-
|
|
247
|
+
actionExecutor.registerAction(
|
|
248
|
+
"screenToggleFlag",
|
|
249
|
+
async (
|
|
250
|
+
action: ActionType,
|
|
251
|
+
context?: Record<string, any>
|
|
252
|
+
): Promise<ActionResult> => {
|
|
253
|
+
const screenRoute = context?.screenRoute;
|
|
254
|
+
const screenStateStore = context?.screenStateStore;
|
|
255
|
+
|
|
256
|
+
await screenToggleFlag(
|
|
257
|
+
screenRoute,
|
|
258
|
+
screenStateStore,
|
|
259
|
+
{ entry: context?.entry, options: action.options },
|
|
260
|
+
action
|
|
261
|
+
);
|
|
257
262
|
|
|
258
|
-
return ActionResult.Success;
|
|
263
|
+
return Promise.resolve(ActionResult.Success);
|
|
259
264
|
}
|
|
260
265
|
);
|
|
261
266
|
};
|
|
@@ -281,9 +286,24 @@ export function withActionExecutor(Component) {
|
|
|
281
286
|
};
|
|
282
287
|
}, []);
|
|
283
288
|
|
|
289
|
+
useSubscriberFor(APP_EVENTS.onLogout, () => {
|
|
290
|
+
log_debug(
|
|
291
|
+
"User profile: onLogout event received, clearing user profile data"
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const userAccountKey = "user_account";
|
|
295
|
+
void batchRemoveAllFromNamespaceForStorage(userAccountKey, localStorage);
|
|
296
|
+
|
|
297
|
+
void batchRemoveAllFromNamespaceForStorage(
|
|
298
|
+
userAccountKey,
|
|
299
|
+
sessionStorage
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
284
303
|
useEffect(() => {
|
|
285
304
|
return _actionExecutor.registerAction(
|
|
286
305
|
"navigateToScreen",
|
|
306
|
+
|
|
287
307
|
async (action: ActionType, context?: Record<string, any>) => {
|
|
288
308
|
const screenType = action.options?.typeMapping;
|
|
289
309
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
2
|
+
|
|
3
|
+
import { log_error, log_info } from "./ActionExecutorContext";
|
|
4
|
+
import { ActionResult } from "./ActionExecutor";
|
|
5
|
+
import { get } from "lodash";
|
|
6
|
+
|
|
7
|
+
import { onMaxTagsReached } from "./StorageActions";
|
|
8
|
+
import { ScreenMultiSelectProvider } from "../storage/ScreenStateMultiSelectProvider";
|
|
9
|
+
|
|
10
|
+
export const screenSetVariable = (
|
|
11
|
+
_screenRoute: string,
|
|
12
|
+
_key: string,
|
|
13
|
+
_value: string
|
|
14
|
+
) => {};
|
|
15
|
+
|
|
16
|
+
export const screenToggleFlag = async (
|
|
17
|
+
screenRoute: string,
|
|
18
|
+
screenStateStore: ScreenStateStore,
|
|
19
|
+
context: Record<string, any>,
|
|
20
|
+
action: ActionType
|
|
21
|
+
) => {
|
|
22
|
+
if (!context) {
|
|
23
|
+
log_error("handleAction: screenToggleFlag action missing context");
|
|
24
|
+
|
|
25
|
+
return ActionResult.Error;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const entry = context?.entry as ZappEntry;
|
|
29
|
+
|
|
30
|
+
if (!entry) {
|
|
31
|
+
log_error(
|
|
32
|
+
"handleAction: screenToggleFlag action missing entry. Entry is required to get the tag."
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return ActionResult.Error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const tag = action.options?.selector
|
|
39
|
+
? get(entry, action.options.selector)
|
|
40
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
41
|
+
|
|
42
|
+
const keyNamespace = action.options?.key;
|
|
43
|
+
|
|
44
|
+
if (keyNamespace && tag) {
|
|
45
|
+
const multiSelectProvider = ScreenMultiSelectProvider.getProvider(
|
|
46
|
+
keyNamespace,
|
|
47
|
+
screenRoute,
|
|
48
|
+
screenStateStore
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
52
|
+
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
53
|
+
|
|
54
|
+
log_info(
|
|
55
|
+
`handleAction: screenToggleFlag event will ${
|
|
56
|
+
isTagInSelectedItems ? "remove" : "add"
|
|
57
|
+
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (selectedItems.includes(tag)) {
|
|
61
|
+
await multiSelectProvider.removeItem(tag);
|
|
62
|
+
} else {
|
|
63
|
+
const maxItems = action.options?.max_items;
|
|
64
|
+
|
|
65
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
66
|
+
log_info(
|
|
67
|
+
`handleAction: screenToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await onMaxTagsReached({
|
|
71
|
+
selectedItems,
|
|
72
|
+
maxItems,
|
|
73
|
+
tag,
|
|
74
|
+
keyNamespace,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return ActionResult.Cancel;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await multiSelectProvider.addItem(tag);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
log_error(
|
|
84
|
+
"handleAction: screenToggleFlag event missing keyNamespace or tag",
|
|
85
|
+
{ keyNamespace, tag }
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return ActionResult.Error;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return ActionResult.Success;
|
|
92
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ActionResult } from "./ActionExecutor";
|
|
2
|
+
import { get } from "lodash";
|
|
3
|
+
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-utils/storage/StorageMultiSelectProvider";
|
|
4
|
+
import { log_error, log_info } from "./ActionExecutorContext";
|
|
5
|
+
import { postEvent } from "../reactHooks/useSubscriberFor";
|
|
6
|
+
import { TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT } from "./consts";
|
|
7
|
+
import { StorageType } from "../appUtils/contextKeysManager/consts";
|
|
8
|
+
|
|
9
|
+
// send all data just in case (like for message string formatting)
|
|
10
|
+
// Type is not exported for now
|
|
11
|
+
type MaxTagsReachedEvent = {
|
|
12
|
+
selectedItems: string[];
|
|
13
|
+
maxItems: number;
|
|
14
|
+
tag: string;
|
|
15
|
+
keyNamespace: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function onMaxTagsReached(data: MaxTagsReachedEvent) {
|
|
19
|
+
postEvent(TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT, [data]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function storageToggleFlag(
|
|
23
|
+
context: Record<string, any>,
|
|
24
|
+
action: ActionType,
|
|
25
|
+
storageType: StorageType
|
|
26
|
+
) {
|
|
27
|
+
if (!context) {
|
|
28
|
+
log_error("handleAction: localStorageToggleFlag action missing context");
|
|
29
|
+
|
|
30
|
+
return ActionResult.Error;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const entry = context?.entry as ZappEntry;
|
|
34
|
+
|
|
35
|
+
if (!entry) {
|
|
36
|
+
log_error(
|
|
37
|
+
"handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return ActionResult.Error;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tag = action.options?.selector
|
|
44
|
+
? get(entry, action.options.selector)
|
|
45
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
46
|
+
|
|
47
|
+
const keyNamespace = action.options?.key;
|
|
48
|
+
|
|
49
|
+
if (keyNamespace && tag) {
|
|
50
|
+
const multiSelectProvider = StorageMultiSelectProvider.getProvider(
|
|
51
|
+
keyNamespace,
|
|
52
|
+
storageType
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
56
|
+
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
57
|
+
|
|
58
|
+
log_info(
|
|
59
|
+
`handleAction: localStorageToggleFlag event will ${
|
|
60
|
+
isTagInSelectedItems ? "remove" : "add"
|
|
61
|
+
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (selectedItems.includes(tag)) {
|
|
65
|
+
await multiSelectProvider.removeItem(tag);
|
|
66
|
+
} else {
|
|
67
|
+
const maxItems = action.options?.max_items;
|
|
68
|
+
|
|
69
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
70
|
+
log_info(
|
|
71
|
+
`handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
await onMaxTagsReached({
|
|
75
|
+
selectedItems,
|
|
76
|
+
maxItems,
|
|
77
|
+
tag,
|
|
78
|
+
keyNamespace,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return ActionResult.Cancel;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await multiSelectProvider.addItem(tag);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
log_error(
|
|
88
|
+
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
89
|
+
{ keyNamespace, tag }
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return ActionResult.Error;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return ActionResult.Success;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function sessionStorageToggleFlag(
|
|
99
|
+
context: Record<string, any>,
|
|
100
|
+
action: ActionType
|
|
101
|
+
) {
|
|
102
|
+
return storageToggleFlag(context, action, StorageType.session);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function localStorageToggleFlag(
|
|
106
|
+
context: Record<string, any>,
|
|
107
|
+
action: ActionType
|
|
108
|
+
) {
|
|
109
|
+
return storageToggleFlag(context, action, StorageType.local);
|
|
110
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as R from "ramda";
|
|
2
|
+
import { getNamespaceAndKey } from "../appUtils/contextKeysManager/utils";
|
|
3
|
+
import { createLogger } from "../logger";
|
|
4
|
+
|
|
5
|
+
const { log_error, log_verbose } = createLogger({
|
|
6
|
+
subsystem: "FeedDecorator",
|
|
7
|
+
category: "General",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function getScope(scope) {
|
|
11
|
+
if (scope === "screen") {
|
|
12
|
+
return scope;
|
|
13
|
+
} else if (!scope || scope === "ctx") {
|
|
14
|
+
return "ctx";
|
|
15
|
+
} else {
|
|
16
|
+
log_verbose(
|
|
17
|
+
`decorateFeed: Unsupported scope "${scope}" provided in preference_editor_options. Defaulting to "ctx".`
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return "ctx";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function makeMultiSelect(feed: ZappFeed, key, decoratedFeed) {
|
|
25
|
+
const scope = getScope(
|
|
26
|
+
decoratedFeed.extensions?.preference_editor_options?.scope
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const behavior = {
|
|
30
|
+
...feed.extensions?.["behavior"],
|
|
31
|
+
select_mode: "multi",
|
|
32
|
+
current_selection: `@{${scope}/${key}}`,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (!feed.extensions) {
|
|
36
|
+
decoratedFeed.extensions = {
|
|
37
|
+
behavior,
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
decoratedFeed.extensions.behavior = behavior;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const actionType =
|
|
44
|
+
decoratedFeed.extensions?.preference_editor_options?.scope === "screen"
|
|
45
|
+
? "screenToggleFlag"
|
|
46
|
+
: decoratedFeed.extensions?.preference_editor_options?.scope === "session"
|
|
47
|
+
? "sessionStorageToggleFlag"
|
|
48
|
+
: "localStorageToggleFlag";
|
|
49
|
+
|
|
50
|
+
decoratedFeed.entry?.forEach((entry: ZappEntry) => {
|
|
51
|
+
entry.type.value = "action";
|
|
52
|
+
entry.id = entry.extensions?.tag || entry.id;
|
|
53
|
+
|
|
54
|
+
entry.extensions = {
|
|
55
|
+
...(entry.extensions || {}),
|
|
56
|
+
tap_actions: {
|
|
57
|
+
actions: [
|
|
58
|
+
{
|
|
59
|
+
type: actionType,
|
|
60
|
+
options: {
|
|
61
|
+
key,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return decoratedFeed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function makeSingleSelect(feed: ZappFeed, key, decoratedFeed) {
|
|
73
|
+
const scope = getScope(
|
|
74
|
+
decoratedFeed.extensions?.preference_editor_options?.scope
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const behavior = {
|
|
78
|
+
...feed.extensions?.["behavior"],
|
|
79
|
+
select_mode: "single",
|
|
80
|
+
current_selection: `@{${scope}/${key}}`,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (!feed.extensions) {
|
|
84
|
+
decoratedFeed.extensions = {
|
|
85
|
+
behavior,
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
decoratedFeed.extensions.behavior = behavior;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const localStorageProducer = (entry: ZappFeed) => {
|
|
92
|
+
entry.id = entry.extensions?.tag || entry.id;
|
|
93
|
+
const { key: keyName, namespace } = getNamespaceAndKey(key);
|
|
94
|
+
|
|
95
|
+
const action =
|
|
96
|
+
decoratedFeed.extensions?.preference_editor_options?.scope === "session"
|
|
97
|
+
? "sessionStorageSet"
|
|
98
|
+
: "localStorageSet";
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
type: action,
|
|
102
|
+
options: {
|
|
103
|
+
content: {
|
|
104
|
+
[namespace]: {
|
|
105
|
+
[keyName]: entry.id,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const screenStateProducer = (entry: ZappFeed) => {
|
|
113
|
+
entry.id = entry.extensions?.tag || entry.id;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
type: "screenSetVariable",
|
|
117
|
+
options: {
|
|
118
|
+
key: `@{screen/${key}}`,
|
|
119
|
+
value: entry.id,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const producer =
|
|
125
|
+
decoratedFeed.extensions?.preference_editor_options?.scope === "screen"
|
|
126
|
+
? screenStateProducer
|
|
127
|
+
: localStorageProducer;
|
|
128
|
+
|
|
129
|
+
decoratedFeed.entry?.forEach((entry: ZappEntry) => {
|
|
130
|
+
entry.type.value = "action";
|
|
131
|
+
|
|
132
|
+
entry.extensions = {
|
|
133
|
+
...(entry.extensions || {}),
|
|
134
|
+
tap_actions: {
|
|
135
|
+
actions: [producer(entry)],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return decoratedFeed;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const decorateFeed = (feed: ZappFeed) => {
|
|
144
|
+
if (!(feed.extensions?.["role"] === "preference_editor")) {
|
|
145
|
+
return feed;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const key = feed.extensions?.["preference_editor_options"]?.["key"];
|
|
149
|
+
|
|
150
|
+
if (!key) {
|
|
151
|
+
log_error(
|
|
152
|
+
`decorateFeed: No 'key' provided in feed titled "${feed.title}" with id "${feed.id}" in preference_editor_options. The preference_editor role requires a key for local storage.`
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
throw new Error(
|
|
156
|
+
"decorateFeed: No 'key' provided in feed preference_editor_options"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const decoratedFeed = R.clone(feed);
|
|
161
|
+
|
|
162
|
+
const isSingleSelect =
|
|
163
|
+
(feed.extensions?.["preference_editor_options"]?.select_mode ||
|
|
164
|
+
feed.extensions?.["behavior"]?.select_mode) === "single";
|
|
165
|
+
|
|
166
|
+
if (isSingleSelect) {
|
|
167
|
+
return makeSingleSelect(feed, key, decoratedFeed);
|
|
168
|
+
} else {
|
|
169
|
+
return makeMultiSelect(feed, key, decoratedFeed);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { ScreenStateResolver } from "../appUtils/contextKeysManager/contextResolver";
|
|
3
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
4
|
+
|
|
5
|
+
export const useScreenResolvers = () => {
|
|
6
|
+
const screenStateStore = useScreenStateStore();
|
|
7
|
+
|
|
8
|
+
return useMemo(() => {
|
|
9
|
+
return { screen: new ScreenStateResolver(screenStateStore) };
|
|
10
|
+
}, [screenStateStore]);
|
|
11
|
+
};
|