@applicaster/zapp-react-native-utils 14.0.0-alpha.9203091422 → 14.0.0-alpha.9551591420
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 +1 -1
- package/appUtils/contextKeysManager/contextResolver.ts +1 -14
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +6 -4
- package/package.json +2 -3
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +3 -1
- package/reactHooks/cell-click/index.ts +1 -8
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +0 -20
- package/reactHooks/feed/useBatchLoading.ts +8 -6
- package/reactHooks/feed/useFeedLoader.tsx +14 -17
- 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/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/useRoute.ts +2 -7
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/state/useRivers.ts +7 -8
- package/time/BackgroundTimer.ts +1 -1
- package/utils/index.ts +1 -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 -8
- package/storage/ScreenSingleValueProvider.ts +0 -201
- package/storage/ScreenStateMultiSelectProvider.ts +0 -290
- package/storage/StorageMultiSelectProvider.ts +0 -192
- package/storage/StorageSingleSelectProvider.ts +0 -108
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { useDispatch } from "react-redux";
|
|
3
2
|
|
|
4
3
|
import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
|
|
5
4
|
import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
|
|
6
5
|
import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
7
6
|
|
|
8
7
|
import { useRoute } from "../navigation";
|
|
8
|
+
import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* reset river components cache when screen is unmounted
|
|
@@ -13,7 +13,7 @@ import { useRoute } from "../navigation";
|
|
|
13
13
|
* @param {Array} riverComponents list of UI components
|
|
14
14
|
*/
|
|
15
15
|
export const usePipesCacheReset = (riverId, riverComponents) => {
|
|
16
|
-
const dispatch =
|
|
16
|
+
const dispatch = useAppDispatch();
|
|
17
17
|
const { screenData, pathname } = useRoute();
|
|
18
18
|
const pipesContexts = usePipesContexts(riverId, pathname);
|
|
19
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
-
import { View } from "react-native";
|
|
3
|
+
import { View, ViewStyle } from "react-native";
|
|
4
4
|
|
|
5
5
|
import { platformSelect } from "../../reactUtils";
|
|
6
6
|
|
|
@@ -49,13 +49,13 @@ export const useSequentialRenderItem = (data: Data) => {
|
|
|
49
49
|
const readyToDisplay =
|
|
50
50
|
index === 0 ? true : arePreviousComponentsReady(index);
|
|
51
51
|
|
|
52
|
-
const displayStyle = {
|
|
52
|
+
const displayStyle: ViewStyle = {
|
|
53
53
|
display: readyToDisplay ? "flex" : "none",
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const readyStyle = {
|
|
57
57
|
visibility: readyToDisplay ? "visible" : "hidden",
|
|
58
|
-
};
|
|
58
|
+
} as ViewStyle;
|
|
59
59
|
|
|
60
60
|
const style = platformSelect({
|
|
61
61
|
tvos: readyStyle,
|
|
@@ -42,15 +42,17 @@ jest.mock("react-native-safe-area-context", () => ({
|
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
44
|
jest.mock("../../../reactUtils", () => ({
|
|
45
|
+
...jest.requireActual("../../../reactUtils"),
|
|
45
46
|
platformSelect: jest.fn((specs) => specs[platform] || specs.default),
|
|
46
47
|
isTV: jest.fn(() => mock_tv_flag),
|
|
47
48
|
}));
|
|
48
49
|
|
|
49
50
|
jest.mock("../../navigation", () => ({
|
|
50
|
-
useNavigation: () => null,
|
|
51
51
|
useIsScreenActive: () => true,
|
|
52
52
|
}));
|
|
53
53
|
|
|
54
|
+
jest.mock("../../navigation/useNavigation");
|
|
55
|
+
|
|
54
56
|
const { Dimensions } = require("react-native");
|
|
55
57
|
const { useDimensions } = require("..");
|
|
56
58
|
|
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
import { Dimensions, StatusBar } from "react-native";
|
|
3
|
+
import { useDimensions } from "../useDimensions";
|
|
4
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
const mockUseIsScreenActive = jest.fn();
|
|
6
|
-
const mockGetInitialDimensions = jest.fn();
|
|
7
|
-
const mockGetDeviceInfo = jest.fn();
|
|
6
|
+
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
|
|
8
7
|
|
|
9
|
-
jest.mock("@applicaster/zapp-react-native-redux/hooks", () =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
useIsScreenActive: mockUseIsScreenActive,
|
|
16
|
-
}));
|
|
8
|
+
jest.mock("@applicaster/zapp-react-native-redux/hooks", () => {
|
|
9
|
+
return {
|
|
10
|
+
...jest.requireActual("@applicaster/zapp-react-native-redux/hooks"),
|
|
11
|
+
usePickFromState: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
});
|
|
17
14
|
|
|
18
|
-
jest.mock(
|
|
19
|
-
|
|
15
|
+
jest.mock(
|
|
16
|
+
"@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive",
|
|
17
|
+
() => ({
|
|
18
|
+
useIsScreenActive: jest.fn().mockReturnValue(true),
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
jest.doMock("../helpers", () => ({
|
|
23
|
+
getInitialDimensions: jest
|
|
24
|
+
.fn()
|
|
25
|
+
.mockReturnValue({ width: 100, height: 200, scale: 1, fontScale: 1 }),
|
|
20
26
|
}));
|
|
21
27
|
|
|
22
28
|
jest.mock("../../getDeviceInfo", () => ({
|
|
23
|
-
getDeviceInfo:
|
|
29
|
+
getDeviceInfo: jest.fn().mockReturnValue({ deviceInfo: "testDeviceInfo" }),
|
|
24
30
|
}));
|
|
25
31
|
|
|
26
|
-
const {
|
|
32
|
+
const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
|
|
33
|
+
|
|
34
|
+
Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
|
|
35
|
+
|
|
36
|
+
Dimensions.addEventListener = jest.fn().mockReturnValue({
|
|
37
|
+
remove: jest.fn(),
|
|
38
|
+
});
|
|
27
39
|
|
|
28
40
|
describe("useDimensions", () => {
|
|
29
|
-
const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
|
|
30
41
|
const mockAppData = { someData: "test" };
|
|
31
42
|
|
|
32
43
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Dimensions.addEventListener = jest.fn().mockReturnValue({
|
|
37
|
-
remove: jest.fn(),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
mockUsePickFromState.mockReturnValue({ appData: mockAppData });
|
|
41
|
-
mockUseIsScreenActive.mockReturnValue(true);
|
|
42
|
-
mockGetInitialDimensions.mockReturnValue(mockDimensions);
|
|
43
|
-
mockGetDeviceInfo.mockReturnValue({ deviceInfo: "testDeviceInfo" });
|
|
44
|
+
StatusBar.currentHeight = 20;
|
|
45
|
+
(usePickFromState as jest.Mock).mockReturnValue({ appData: mockAppData });
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
it("returns correct initial dimensions", () => {
|
|
@@ -48,12 +50,9 @@ describe("useDimensions", () => {
|
|
|
48
50
|
useDimensions("window", { fullDimensions: false })
|
|
49
51
|
);
|
|
50
52
|
|
|
51
|
-
expect(result.current).
|
|
52
|
-
...mockDimensions,
|
|
53
|
+
expect(result.current).toMatchObject({
|
|
53
54
|
statusBarHeight: StatusBar.currentHeight,
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
-
expect(mockGetInitialDimensions).toHaveBeenCalledWith("window");
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
it("calls handler on mount", () => {
|
|
@@ -70,7 +69,7 @@ describe("useDimensions", () => {
|
|
|
70
69
|
useDimensions("window", { fullDimensions: false })
|
|
71
70
|
);
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
(useIsScreenActive as jest.Mock).mockReturnValue(false);
|
|
74
73
|
rerender();
|
|
75
74
|
|
|
76
75
|
expect(Dimensions.addEventListener).toHaveBeenCalledWith(
|
|
@@ -84,8 +83,7 @@ describe("useDimensions", () => {
|
|
|
84
83
|
useDimensions("window", { fullDimensions: true })
|
|
85
84
|
);
|
|
86
85
|
|
|
87
|
-
expect(result.current).
|
|
88
|
-
...mockDimensions,
|
|
86
|
+
expect(result.current).toMatchObject({
|
|
89
87
|
scale: 1,
|
|
90
88
|
fontScale: 1,
|
|
91
89
|
statusBarHeight: StatusBar.currentHeight,
|
|
@@ -98,7 +96,7 @@ describe("useDimensions", () => {
|
|
|
98
96
|
);
|
|
99
97
|
|
|
100
98
|
expect(result.current.height).toBe(
|
|
101
|
-
mockDimensions.height - StatusBar
|
|
99
|
+
mockDimensions.height - (StatusBar?.currentHeight ?? 0)
|
|
102
100
|
);
|
|
103
101
|
});
|
|
104
102
|
|
|
@@ -10,7 +10,7 @@ import { isTV } from "../../../reactUtils";
|
|
|
10
10
|
import { Options, UseDimensions } from "../types";
|
|
11
11
|
import { getDeviceInfo } from "../getDeviceInfo";
|
|
12
12
|
import { getInitialDimensions } from "./helpers";
|
|
13
|
-
import { useIsScreenActive } from "../../navigation";
|
|
13
|
+
import { useIsScreenActive } from "../../navigation/useIsScreenActive";
|
|
14
14
|
|
|
15
15
|
function compensateForScaleIfNeeded(context) {
|
|
16
16
|
return function () {
|
|
@@ -24,8 +24,6 @@ const applyScaleToDimensions = R.unless(R.propEq("scale", 1), (dimensions) => ({
|
|
|
24
24
|
scale: 1,
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
|
-
const statusBarHeight = StatusBar?.currentHeight;
|
|
28
|
-
|
|
29
27
|
/**
|
|
30
28
|
* Returns React-native Dimensions object and updates it on any dimension change
|
|
31
29
|
* @param {('screen'|'window')} [context=window] - Dimensions context passed to Dimensions.get method
|
|
@@ -37,6 +35,7 @@ export const useDimensions: UseDimensions = (
|
|
|
37
35
|
context = "window",
|
|
38
36
|
fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
|
|
39
37
|
) => {
|
|
38
|
+
const statusBarHeight = StatusBar?.currentHeight;
|
|
40
39
|
const isActive = useIsScreenActive();
|
|
41
40
|
const { appData } = usePickFromState(["appData"]);
|
|
42
41
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-redeclare */
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
useAppSelector,
|
|
4
|
+
selectLayoutVersion,
|
|
5
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
4
6
|
|
|
5
7
|
export function useLayoutVersion(): ZappLayoutVersions;
|
|
6
8
|
|
|
@@ -23,9 +25,7 @@ export function useLayoutVersion({
|
|
|
23
25
|
isV2?: boolean;
|
|
24
26
|
isV1?: boolean;
|
|
25
27
|
} = {}): boolean | ZappLayoutVersions {
|
|
26
|
-
const layoutVersion =
|
|
27
|
-
R.path(["appData", "layoutVersion"])
|
|
28
|
-
);
|
|
28
|
+
const layoutVersion = useAppSelector(selectLayoutVersion);
|
|
29
29
|
|
|
30
30
|
if (isV2) {
|
|
31
31
|
return layoutVersion === "v2";
|
|
@@ -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",
|
|
@@ -14,6 +14,10 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
|
|
|
14
14
|
|
|
15
15
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
|
|
16
16
|
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
|
|
19
|
+
);
|
|
20
|
+
|
|
17
21
|
const { useCellResolver } = require("../useCellResolver");
|
|
18
22
|
|
|
19
23
|
describe("cellResolver", () => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useAppSelector,
|
|
3
|
+
selectRivers,
|
|
4
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { rivers } = usePickFromState(riversSelector as any);
|
|
7
|
-
|
|
8
|
-
return rivers;
|
|
9
|
-
};
|
|
6
|
+
export function useRivers(): Record<string, ZappRiver> {
|
|
7
|
+
return useAppSelector(selectRivers);
|
|
8
|
+
}
|
package/time/BackgroundTimer.ts
CHANGED
|
@@ -11,7 +11,7 @@ class BackgroundTimer {
|
|
|
11
11
|
this.uniqueId = 0;
|
|
12
12
|
this.callbacks = {};
|
|
13
13
|
|
|
14
|
-
const EventEmitter = platformSelect({
|
|
14
|
+
const EventEmitter: typeof DeviceEventEmitter | undefined = platformSelect({
|
|
15
15
|
android: DeviceEventEmitter,
|
|
16
16
|
android_tv: DeviceEventEmitter,
|
|
17
17
|
amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
|
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
|
-
}
|