@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 15.0.0-rc.2
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 +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +154 -30
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +10 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +94 -3
- package/appUtils/platform/platformUtils.ts +31 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +8 -3
- 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/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -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/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +64 -35
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +104 -20
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- 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/player.js +2764 -1539
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +12 -0
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +7 -5
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- 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 +53 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +17 -10
- package/reactHooks/feed/useFeedLoader.tsx +36 -34
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/index.ts +13 -0
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +6 -4
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +33 -1
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +164 -0
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +60 -0
- package/zappFrameworkUtils/HookCallback/useCallbackActions.ts +22 -0
- package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
- package/playerUtils/configurationGenerator.ts +0 -2572
|
@@ -16,7 +16,6 @@ import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickB
|
|
|
16
16
|
import { showConfirmationDialog } from "../alertUtils";
|
|
17
17
|
import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
|
|
18
18
|
import { createLogger } from "../logger";
|
|
19
|
-
import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
|
|
20
19
|
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
|
|
21
20
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
22
21
|
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
@@ -25,15 +24,19 @@ import {
|
|
|
25
24
|
resolveObjectValues,
|
|
26
25
|
} from "../appUtils/contextKeysManager/contextResolver";
|
|
27
26
|
import { useNavigation } from "../reactHooks";
|
|
28
|
-
import { get } from "lodash";
|
|
29
27
|
|
|
30
28
|
import {
|
|
31
29
|
useContentTypes,
|
|
32
30
|
usePickFromState,
|
|
33
31
|
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
34
|
-
import {
|
|
35
|
-
import { postEvent, useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
32
|
+
import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
|
|
36
33
|
import { APP_EVENTS } from "../appUtils/events";
|
|
34
|
+
import {
|
|
35
|
+
localStorageToggleFlag,
|
|
36
|
+
sessionStorageToggleFlag,
|
|
37
|
+
} from "./StorageActions";
|
|
38
|
+
|
|
39
|
+
import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
|
|
37
40
|
|
|
38
41
|
export const { log_error, log_info, log_debug } = createLogger({
|
|
39
42
|
subsystem: "ActionExecutorContext",
|
|
@@ -82,19 +85,6 @@ function findParentComponent(
|
|
|
82
85
|
return null;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
// send all data just in case (like for message string formatting)
|
|
86
|
-
// Type is not exported for now
|
|
87
|
-
type MaxTagsReachedEvent = {
|
|
88
|
-
selectedItems: string[];
|
|
89
|
-
maxItems: number;
|
|
90
|
-
tag: string;
|
|
91
|
-
keyNamespace: string;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
async function onMaxTagsReached(data: MaxTagsReachedEvent) {
|
|
95
|
-
postEvent(TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT, [data]);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
88
|
const prepareDefaultActions = (actionExecutor) => {
|
|
99
89
|
actionExecutor.registerAction("localStorageSet", async (action) => {
|
|
100
90
|
const namespaces = action.options.content;
|
|
@@ -130,7 +120,6 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
130
120
|
loadPipesData(dataSource, {
|
|
131
121
|
silentRefresh: false,
|
|
132
122
|
clearCache: true,
|
|
133
|
-
callback: (_data) => {},
|
|
134
123
|
riverId: context?.screenData?.id,
|
|
135
124
|
})
|
|
136
125
|
);
|
|
@@ -178,10 +167,15 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
178
167
|
|
|
179
168
|
const entry = context?.entry || {};
|
|
180
169
|
const entryResolver = new EntryResolver(entry);
|
|
170
|
+
const screenData = context?.screenStateStore.getState().data || {};
|
|
171
|
+
const screenResolver = new EntryResolver(screenData || {});
|
|
181
172
|
|
|
182
173
|
const data =
|
|
183
174
|
options?.data && options.inflateData
|
|
184
|
-
? await resolveObjectValues(options.data, {
|
|
175
|
+
? await resolveObjectValues(options.data, {
|
|
176
|
+
entry: entryResolver,
|
|
177
|
+
screen: screenResolver,
|
|
178
|
+
})
|
|
185
179
|
: options?.data || entry;
|
|
186
180
|
|
|
187
181
|
const cloudEvent = await createCloudEvent({
|
|
@@ -216,80 +210,62 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
216
210
|
});
|
|
217
211
|
|
|
218
212
|
actionExecutor.registerAction(
|
|
219
|
-
"
|
|
213
|
+
"sessionStorageToggleFlag",
|
|
220
214
|
async (
|
|
221
215
|
action: ActionType,
|
|
222
216
|
context?: Record<string, any>
|
|
223
217
|
): Promise<ActionResult> => {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
228
|
-
|
|
229
|
-
return ActionResult.Error;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const entry = context?.entry as ZappEntry;
|
|
233
|
-
|
|
234
|
-
if (!entry) {
|
|
235
|
-
log_error(
|
|
236
|
-
"handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
return ActionResult.Error;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const tag = action.options?.selector
|
|
243
|
-
? get(entry, action.options.selector)
|
|
244
|
-
: (entry.extensions?.tag ?? entry.id);
|
|
245
|
-
|
|
246
|
-
const keyNamespace = action.options?.key;
|
|
247
|
-
|
|
248
|
-
if (keyNamespace && tag) {
|
|
249
|
-
const multiSelectProvider =
|
|
250
|
-
StorageMultiSelectProvider.getProvider(keyNamespace);
|
|
251
|
-
|
|
252
|
-
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
253
|
-
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
254
|
-
|
|
255
|
-
log_info(
|
|
256
|
-
`handleAction: localStorageToggleFlag event will ${
|
|
257
|
-
isTagInSelectedItems ? "remove" : "add"
|
|
258
|
-
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
if (selectedItems.includes(tag)) {
|
|
262
|
-
await multiSelectProvider.removeItem(tag);
|
|
263
|
-
} else {
|
|
264
|
-
const maxItems = action.options?.max_items;
|
|
265
|
-
|
|
266
|
-
if (maxItems && selectedItems.length >= maxItems) {
|
|
267
|
-
log_info(
|
|
268
|
-
`handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
269
|
-
);
|
|
218
|
+
return await sessionStorageToggleFlag(context, action);
|
|
219
|
+
}
|
|
220
|
+
);
|
|
270
221
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
222
|
+
actionExecutor.registerAction(
|
|
223
|
+
"localStorageToggleFlag",
|
|
224
|
+
async (
|
|
225
|
+
action: ActionType,
|
|
226
|
+
context?: Record<string, any>
|
|
227
|
+
): Promise<ActionResult> => {
|
|
228
|
+
return await localStorageToggleFlag(context, action);
|
|
229
|
+
}
|
|
230
|
+
);
|
|
277
231
|
|
|
278
|
-
|
|
279
|
-
|
|
232
|
+
actionExecutor.registerAction(
|
|
233
|
+
"screenSetVariable",
|
|
234
|
+
async (
|
|
235
|
+
action: ActionType,
|
|
236
|
+
context?: Record<string, any>
|
|
237
|
+
): Promise<ActionResult> => {
|
|
238
|
+
const route = context?.screenRoute;
|
|
239
|
+
const screenStateStore = context?.screenStateStore;
|
|
240
|
+
|
|
241
|
+
await screenSetVariable(
|
|
242
|
+
route,
|
|
243
|
+
screenStateStore,
|
|
244
|
+
{ entry: context?.entry, options: action.options },
|
|
245
|
+
action
|
|
246
|
+
);
|
|
280
247
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
log_error(
|
|
285
|
-
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
286
|
-
{ keyNamespace, tag }
|
|
287
|
-
);
|
|
248
|
+
return Promise.resolve(ActionResult.Success);
|
|
249
|
+
}
|
|
250
|
+
);
|
|
288
251
|
|
|
289
|
-
|
|
290
|
-
|
|
252
|
+
actionExecutor.registerAction(
|
|
253
|
+
"screenToggleFlag",
|
|
254
|
+
async (
|
|
255
|
+
action: ActionType,
|
|
256
|
+
context?: Record<string, any>
|
|
257
|
+
): Promise<ActionResult> => {
|
|
258
|
+
const screenRoute = context?.screenRoute;
|
|
259
|
+
const screenStateStore = context?.screenStateStore;
|
|
260
|
+
|
|
261
|
+
await screenToggleFlag(
|
|
262
|
+
screenRoute,
|
|
263
|
+
screenStateStore,
|
|
264
|
+
{ entry: context?.entry, options: action.options },
|
|
265
|
+
action
|
|
266
|
+
);
|
|
291
267
|
|
|
292
|
-
return ActionResult.Success;
|
|
268
|
+
return Promise.resolve(ActionResult.Success);
|
|
293
269
|
}
|
|
294
270
|
);
|
|
295
271
|
};
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
import { ScreenSingleValueProvider } from "../storage/ScreenSingleValueProvider";
|
|
10
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
11
|
+
|
|
12
|
+
export const screenSetVariable = async (
|
|
13
|
+
screenRoute: string,
|
|
14
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>,
|
|
15
|
+
context: Record<string, any>,
|
|
16
|
+
action: ActionType
|
|
17
|
+
): Promise<ActionResult> => {
|
|
18
|
+
if (!context) {
|
|
19
|
+
log_error("handleAction: screenSetVariable action missing context");
|
|
20
|
+
|
|
21
|
+
return ActionResult.Error;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const entry = context?.entry as ZappEntry;
|
|
25
|
+
|
|
26
|
+
if (!entry) {
|
|
27
|
+
log_error(
|
|
28
|
+
"handleAction: screenSetVariable action missing entry. Entry is required to get the value."
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return ActionResult.Error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const tag = action.options?.selector
|
|
35
|
+
? get(entry, action.options.selector)
|
|
36
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
37
|
+
|
|
38
|
+
const key = action.options?.key;
|
|
39
|
+
|
|
40
|
+
if (!key) {
|
|
41
|
+
log_error("handleAction: screenSetVariable action missing argument 'key'", {
|
|
42
|
+
key,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return ActionResult.Error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!tag) {
|
|
49
|
+
log_error(
|
|
50
|
+
"handleAction: screenSetVariable action could not determine tag",
|
|
51
|
+
{ selector: action.options?.selector, value: action.options?.value }
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return ActionResult.Error;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const singleValueProvider = ScreenSingleValueProvider.getProvider(
|
|
59
|
+
key,
|
|
60
|
+
screenRoute,
|
|
61
|
+
screenStateStore
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const currentValue = await singleValueProvider.getValueAsync();
|
|
65
|
+
|
|
66
|
+
log_info(
|
|
67
|
+
`handleAction: screenSetVariable setting value: ${tag} for key: ${key}, previous value: ${currentValue}`
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await singleValueProvider.setValue(String(tag));
|
|
71
|
+
|
|
72
|
+
log_info(
|
|
73
|
+
`handleAction: screenSetVariable successfully set value: ${tag} for key: ${key}`
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return ActionResult.Success;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
log_error("handleAction: screenSetVariable failed to set value", {
|
|
79
|
+
key,
|
|
80
|
+
tag,
|
|
81
|
+
error,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return ActionResult.Error;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const screenToggleFlag = async (
|
|
89
|
+
screenRoute: string,
|
|
90
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>,
|
|
91
|
+
context: Record<string, any>,
|
|
92
|
+
action: ActionType
|
|
93
|
+
) => {
|
|
94
|
+
if (!context) {
|
|
95
|
+
log_error("handleAction: screenToggleFlag action missing context");
|
|
96
|
+
|
|
97
|
+
return ActionResult.Error;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const entry = context?.entry as ZappEntry;
|
|
101
|
+
|
|
102
|
+
if (!entry) {
|
|
103
|
+
log_error(
|
|
104
|
+
"handleAction: screenToggleFlag action missing entry. Entry is required to get the tag."
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return ActionResult.Error;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const tag = action.options?.selector
|
|
111
|
+
? get(entry, action.options.selector)
|
|
112
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
113
|
+
|
|
114
|
+
const key = action.options?.key;
|
|
115
|
+
|
|
116
|
+
if (key && tag) {
|
|
117
|
+
const multiSelectProvider = ScreenMultiSelectProvider.getProvider(
|
|
118
|
+
key,
|
|
119
|
+
screenRoute,
|
|
120
|
+
screenStateStore
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
124
|
+
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
125
|
+
|
|
126
|
+
log_info(
|
|
127
|
+
`handleAction: screenToggleFlag event will ${
|
|
128
|
+
isTagInSelectedItems ? "remove" : "add"
|
|
129
|
+
} tag: ${tag} for key: ${key}, current selectedItems: ${selectedItems}`
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
if (selectedItems.includes(tag)) {
|
|
133
|
+
await multiSelectProvider.removeItem(tag);
|
|
134
|
+
} else {
|
|
135
|
+
const maxItems = action.options?.max_items;
|
|
136
|
+
|
|
137
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
138
|
+
log_info(
|
|
139
|
+
`handleAction: screenToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
await onMaxTagsReached({
|
|
143
|
+
selectedItems,
|
|
144
|
+
maxItems,
|
|
145
|
+
tag,
|
|
146
|
+
keyNamespace: key,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return ActionResult.Cancel;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
await multiSelectProvider.addItem(tag);
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
log_error("handleAction: screenToggleFlag event missing key or tag", {
|
|
156
|
+
key,
|
|
157
|
+
tag,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return ActionResult.Error;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return ActionResult.Success;
|
|
164
|
+
};
|
|
@@ -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,
|
|
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
|
+
};
|