@applicaster/zapp-react-native-utils 14.0.0-alpha.5521273514 → 14.0.0-alpha.5594607030
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 -83
- package/actionsExecutor/ScreenActions.ts +163 -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 +14 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/index.ts +6 -3
- package/appUtils/contextKeysManager/contextResolver.ts +14 -1
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -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 +547 -0
- package/configurationUtils/index.ts +63 -34
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +26 -16
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/index.d.ts +0 -9
- 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 +1239 -200
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +1 -2
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +6 -4
- 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 +53 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -0
- package/reactHooks/feed/useBatchLoading.ts +10 -8
- package/reactHooks/feed/useFeedLoader.tsx +25 -12
- package/reactHooks/feed/usePipesCacheReset.ts +2 -2
- 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/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/useRivers.ts +7 -8
- package/storage/ScreenSingleValueProvider.ts +201 -0
- package/storage/ScreenStateMultiSelectProvider.ts +290 -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/index.ts +17 -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;
|
|
@@ -178,10 +168,15 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
178
168
|
|
|
179
169
|
const entry = context?.entry || {};
|
|
180
170
|
const entryResolver = new EntryResolver(entry);
|
|
171
|
+
const screenData = context?.screenStateStore.getState().data || {};
|
|
172
|
+
const screenResolver = new EntryResolver(screenData || {});
|
|
181
173
|
|
|
182
174
|
const data =
|
|
183
175
|
options?.data && options.inflateData
|
|
184
|
-
? await resolveObjectValues(options.data, {
|
|
176
|
+
? await resolveObjectValues(options.data, {
|
|
177
|
+
entry: entryResolver,
|
|
178
|
+
screen: screenResolver,
|
|
179
|
+
})
|
|
185
180
|
: options?.data || entry;
|
|
186
181
|
|
|
187
182
|
const cloudEvent = await createCloudEvent({
|
|
@@ -216,80 +211,62 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
216
211
|
});
|
|
217
212
|
|
|
218
213
|
actionExecutor.registerAction(
|
|
219
|
-
"
|
|
214
|
+
"sessionStorageToggleFlag",
|
|
220
215
|
async (
|
|
221
216
|
action: ActionType,
|
|
222
217
|
context?: Record<string, any>
|
|
223
218
|
): 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
|
-
);
|
|
219
|
+
return await sessionStorageToggleFlag(context, action);
|
|
220
|
+
}
|
|
221
|
+
);
|
|
270
222
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
+
);
|
|
277
232
|
|
|
278
|
-
|
|
279
|
-
|
|
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 screenStateStore = context?.screenStateStore;
|
|
241
|
+
|
|
242
|
+
await screenSetVariable(
|
|
243
|
+
route,
|
|
244
|
+
screenStateStore,
|
|
245
|
+
{ entry: context?.entry, options: action.options },
|
|
246
|
+
action
|
|
247
|
+
);
|
|
280
248
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
log_error(
|
|
285
|
-
"handleAction: localStorageToggleFlag event missing keyNamespace or tag",
|
|
286
|
-
{ keyNamespace, tag }
|
|
287
|
-
);
|
|
249
|
+
return Promise.resolve(ActionResult.Success);
|
|
250
|
+
}
|
|
251
|
+
);
|
|
288
252
|
|
|
289
|
-
|
|
290
|
-
|
|
253
|
+
actionExecutor.registerAction(
|
|
254
|
+
"screenToggleFlag",
|
|
255
|
+
async (
|
|
256
|
+
action: ActionType,
|
|
257
|
+
context?: Record<string, any>
|
|
258
|
+
): Promise<ActionResult> => {
|
|
259
|
+
const screenRoute = context?.screenRoute;
|
|
260
|
+
const screenStateStore = context?.screenStateStore;
|
|
261
|
+
|
|
262
|
+
await screenToggleFlag(
|
|
263
|
+
screenRoute,
|
|
264
|
+
screenStateStore,
|
|
265
|
+
{ entry: context?.entry, options: action.options },
|
|
266
|
+
action
|
|
267
|
+
);
|
|
291
268
|
|
|
292
|
-
return ActionResult.Success;
|
|
269
|
+
return Promise.resolve(ActionResult.Success);
|
|
293
270
|
}
|
|
294
271
|
);
|
|
295
272
|
};
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
|
|
11
|
+
export const screenSetVariable = async (
|
|
12
|
+
screenRoute: string,
|
|
13
|
+
screenStateStore: ScreenStateStore,
|
|
14
|
+
context: Record<string, any>,
|
|
15
|
+
action: ActionType
|
|
16
|
+
): Promise<ActionResult> => {
|
|
17
|
+
if (!context) {
|
|
18
|
+
log_error("handleAction: screenSetVariable action missing context");
|
|
19
|
+
|
|
20
|
+
return ActionResult.Error;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const entry = context?.entry as ZappEntry;
|
|
24
|
+
|
|
25
|
+
if (!entry) {
|
|
26
|
+
log_error(
|
|
27
|
+
"handleAction: screenSetVariable action missing entry. Entry is required to get the value."
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return ActionResult.Error;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const tag = action.options?.selector
|
|
34
|
+
? get(entry, action.options.selector)
|
|
35
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
36
|
+
|
|
37
|
+
const keyNamespace = action.options?.key;
|
|
38
|
+
|
|
39
|
+
if (!keyNamespace) {
|
|
40
|
+
log_error("handleAction: screenSetVariable action missing key namespace", {
|
|
41
|
+
keyNamespace,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return ActionResult.Error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!tag) {
|
|
48
|
+
log_error(
|
|
49
|
+
"handleAction: screenSetVariable action could not determine tag",
|
|
50
|
+
{ selector: action.options?.selector, value: action.options?.value }
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return ActionResult.Error;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const singleValueProvider = ScreenSingleValueProvider.getProvider(
|
|
58
|
+
keyNamespace,
|
|
59
|
+
screenRoute,
|
|
60
|
+
screenStateStore
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const currentValue = await singleValueProvider.getValueAsync();
|
|
64
|
+
|
|
65
|
+
log_info(
|
|
66
|
+
`handleAction: screenSetVariable setting value: ${tag} for keyNamespace: ${keyNamespace}, previous value: ${currentValue}`
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await singleValueProvider.setValue(String(tag));
|
|
70
|
+
|
|
71
|
+
log_info(
|
|
72
|
+
`handleAction: screenSetVariable successfully set value: ${tag} for keyNamespace: ${keyNamespace}`
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return ActionResult.Success;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
log_error("handleAction: screenSetVariable failed to set value", {
|
|
78
|
+
keyNamespace,
|
|
79
|
+
tag,
|
|
80
|
+
error,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return ActionResult.Error;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const screenToggleFlag = async (
|
|
88
|
+
screenRoute: string,
|
|
89
|
+
screenStateStore: ScreenStateStore,
|
|
90
|
+
context: Record<string, any>,
|
|
91
|
+
action: ActionType
|
|
92
|
+
) => {
|
|
93
|
+
if (!context) {
|
|
94
|
+
log_error("handleAction: screenToggleFlag action missing context");
|
|
95
|
+
|
|
96
|
+
return ActionResult.Error;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const entry = context?.entry as ZappEntry;
|
|
100
|
+
|
|
101
|
+
if (!entry) {
|
|
102
|
+
log_error(
|
|
103
|
+
"handleAction: screenToggleFlag action missing entry. Entry is required to get the tag."
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return ActionResult.Error;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const tag = action.options?.selector
|
|
110
|
+
? get(entry, action.options.selector)
|
|
111
|
+
: (entry.extensions?.tag ?? entry.id);
|
|
112
|
+
|
|
113
|
+
const keyNamespace = action.options?.key;
|
|
114
|
+
|
|
115
|
+
if (keyNamespace && tag) {
|
|
116
|
+
const multiSelectProvider = ScreenMultiSelectProvider.getProvider(
|
|
117
|
+
keyNamespace,
|
|
118
|
+
screenRoute,
|
|
119
|
+
screenStateStore
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const selectedItems = await multiSelectProvider.getSelectedAsync();
|
|
123
|
+
const isTagInSelectedItems = selectedItems.includes(tag);
|
|
124
|
+
|
|
125
|
+
log_info(
|
|
126
|
+
`handleAction: screenToggleFlag event will ${
|
|
127
|
+
isTagInSelectedItems ? "remove" : "add"
|
|
128
|
+
} tag: ${tag} for keyNamespace: ${keyNamespace}, current selectedItems: ${selectedItems}`
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
if (selectedItems.includes(tag)) {
|
|
132
|
+
await multiSelectProvider.removeItem(tag);
|
|
133
|
+
} else {
|
|
134
|
+
const maxItems = action.options?.max_items;
|
|
135
|
+
|
|
136
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
137
|
+
log_info(
|
|
138
|
+
`handleAction: screenToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
await onMaxTagsReached({
|
|
142
|
+
selectedItems,
|
|
143
|
+
maxItems,
|
|
144
|
+
tag,
|
|
145
|
+
keyNamespace,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return ActionResult.Cancel;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
await multiSelectProvider.addItem(tag);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
log_error(
|
|
155
|
+
"handleAction: screenToggleFlag event missing keyNamespace or tag",
|
|
156
|
+
{ keyNamespace, tag }
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return ActionResult.Error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return ActionResult.Success;
|
|
163
|
+
};
|
|
@@ -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
|
+
};
|