@applicaster/zapp-react-native-utils 14.0.0-alpha.7900711229 → 14.0.0-alpha.8419134002
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 +83 -60
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +14 -0
- package/analyticsUtils/events.ts +8 -0
- package/appUtils/accessibilityManager/index.ts +3 -3
- package/appUtils/contextKeysManager/contextResolver.ts +1 -14
- package/focusManager/FocusManager.ts +4 -6
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/package.json +2 -2
- package/playerUtils/getPlayerActionButtons.ts +1 -1
- package/reactHooks/cell-click/index.ts +1 -8
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
- package/reactHooks/feed/useBatchLoading.ts +1 -1
- package/reactHooks/feed/useFeedLoader.tsx +5 -12
- package/reactHooks/feed/usePipesCacheReset.ts +1 -1
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +2 -7
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/services/js2native.ts +1 -0
- package/time/BackgroundTimer.ts +5 -3
- package/utils/index.ts +4 -0
- package/actionsExecutor/ScreenActions.ts +0 -163
- package/actionsExecutor/StorageActions.ts +0 -110
- package/actionsExecutor/feedDecorator.ts +0 -171
- package/actionsExecutor/screenResolver.ts +0 -11
- package/reactHooks/navigation/useScreenStateStore.ts +0 -11
- package/storage/ScreenSingleValueProvider.ts +0 -197
- package/storage/ScreenStateMultiSelectProvider.ts +0 -282
- package/storage/StorageMultiSelectProvider.ts +0 -192
- package/storage/StorageSingleSelectProvider.ts +0 -108
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
|
|
1
2
|
import { useNavigation } from "./useNavigation";
|
|
2
3
|
import { usePathname } from "./usePathname";
|
|
3
4
|
|
|
@@ -6,11 +7,14 @@ export const useIsScreenActive = () => {
|
|
|
6
7
|
const pathname = usePathname();
|
|
7
8
|
const { currentRoute, videoModalState } = useNavigation();
|
|
8
9
|
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
if (videoModalState.visible) {
|
|
11
|
+
if (pathname.includes(ROUTE_TYPES.VIDEO_MODAL)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
return pathname === currentRoute;
|
|
@@ -28,19 +28,14 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
|
28
28
|
|
|
29
29
|
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
30
30
|
|
|
31
|
-
export const useRoute = (
|
|
32
|
-
useLegacy = true
|
|
33
|
-
): {
|
|
31
|
+
export const useRoute = (): {
|
|
34
32
|
screenData: VariousScreenData;
|
|
35
33
|
pathname: string;
|
|
36
34
|
} => {
|
|
37
35
|
const pathname = usePathname() || "";
|
|
38
36
|
const navigator = useNavigation();
|
|
39
|
-
const screenContext = useContext(ScreenDataContext);
|
|
40
37
|
|
|
41
|
-
const screenDataContext =
|
|
42
|
-
? legacyScreenData(screenContext)
|
|
43
|
-
: screenContext;
|
|
38
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
44
39
|
|
|
45
40
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
46
41
|
"plugins",
|
|
@@ -2,7 +2,7 @@ import { useContext, useMemo } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
|
|
4
4
|
import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
|
|
5
|
-
import { useNavigation } from "../navigation
|
|
5
|
+
import { useNavigation } from "../navigation";
|
|
6
6
|
|
|
7
7
|
import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
|
|
8
8
|
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { render, screen } from "@testing-library/react-native";
|
|
3
4
|
import { Text } from "react-native";
|
|
4
|
-
import {
|
|
5
|
+
import { useZStore, ZStoreProvider } from "../ZStoreProvider";
|
|
5
6
|
import { useStore } from "zustand";
|
|
6
7
|
|
|
7
8
|
interface TestState {
|
|
@@ -3,7 +3,7 @@ import { NativeModules, StyleSheet, View } from "react-native";
|
|
|
3
3
|
import { getXray } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
4
|
|
|
5
5
|
import { isApplePlatform, isWeb } from "../reactUtils";
|
|
6
|
-
import { useRivers } from "../reactHooks
|
|
6
|
+
import { useRivers } from "../reactHooks";
|
|
7
7
|
|
|
8
8
|
const layoutReducer = (state, { payload }) => {
|
|
9
9
|
return state.map((item, index, _state) => ({
|
package/services/js2native.ts
CHANGED
|
@@ -496,6 +496,7 @@ async function removeStorageListenerHandler(payload: { listenerId?: string }) {
|
|
|
496
496
|
function log({ level, messages }) {
|
|
497
497
|
try {
|
|
498
498
|
const parsedMessages = parseJsonIfNeeded(messages);
|
|
499
|
+
// eslint-disable-next-line no-console
|
|
499
500
|
const logFn = console[level] || console.log;
|
|
500
501
|
|
|
501
502
|
if (Array.isArray(parsedMessages)) {
|
package/time/BackgroundTimer.ts
CHANGED
|
@@ -13,13 +13,15 @@ class BackgroundTimer {
|
|
|
13
13
|
|
|
14
14
|
const EventEmitter = platformSelect({
|
|
15
15
|
android: DeviceEventEmitter,
|
|
16
|
-
|
|
16
|
+
android_tv: DeviceEventEmitter,
|
|
17
|
+
amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
|
|
17
18
|
default: undefined,
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
EventEmitter?.addListener("BackgroundTimer.timer.fired", (id: number) => {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const callback = this.callbacks[id];
|
|
23
|
+
|
|
24
|
+
if (callback) {
|
|
23
25
|
delete this.callbacks[id];
|
|
24
26
|
callback();
|
|
25
27
|
}
|
package/utils/index.ts
CHANGED
|
@@ -1,163 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useRoute } from "./useRoute";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
|
|
4
|
-
export const useScreenStateStore = () => {
|
|
5
|
-
const route = useRoute(false);
|
|
6
|
-
|
|
7
|
-
return useMemo(
|
|
8
|
-
() => route.screenData["screenStateStore"],
|
|
9
|
-
[route.screenData["screenStateStore"]]
|
|
10
|
-
);
|
|
11
|
-
};
|