@applicaster/zapp-react-native-utils 15.1.4 → 16.0.0-alpha.1042942411
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/README.md +0 -6
- package/actionUtils/index.ts +7 -0
- package/actionsExecutor/ActionExecutor.ts +8 -10
- package/actionsExecutor/ActionExecutorContext.tsx +45 -340
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/index.ts +30 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +123 -0
- package/actionsExecutor/actions/refreshComponent.ts +79 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/showToast.ts +31 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +59 -0
- package/adsUtils/__tests__/createVMAP.test.ts +419 -0
- package/adsUtils/index.ts +2 -2
- package/analyticsUtils/README.md +1 -1
- package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
- package/appUtils/HooksManager/index.ts +12 -18
- package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
- package/appUtils/accessibilityManager/const.ts +4 -0
- package/appUtils/accessibilityManager/utils.ts +0 -1
- package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
- package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
- package/appUtils/contextKeysManager/contextResolver.ts +51 -22
- package/appUtils/contextKeysManager/index.ts +65 -10
- package/appUtils/contextKeysManager/utils/index.ts +38 -25
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
- package/appUtils/focusManager/index.ios.ts +43 -4
- package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
- package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
- package/appUtils/focusManagerAux/utils/index.ts +11 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +202 -3
- package/appUtils/keyCodes/keys/keys.web.ts +1 -4
- package/appUtils/orientationHelper.ts +2 -4
- package/appUtils/platform/platformUtils.ts +12 -1
- package/appUtils/playerManager/player.ts +4 -0
- package/appUtils/playerManager/playerNative.ts +30 -21
- package/appUtils/playerManager/usePlayerState.tsx +14 -2
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cloudEventsUtils/__tests__/index.test.ts +529 -0
- package/cloudEventsUtils/index.ts +65 -1
- package/componentsUtils/index.ts +8 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
- package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
- package/errorUtils/__tests__/GeneralError.test.ts +97 -0
- package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
- package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
- package/errorUtils/__tests__/NetworkError.test.ts +202 -0
- package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
- package/errorUtils/__tests__/invariant.test.ts +112 -0
- package/focusManager/aux/index.ts +1 -1
- package/headersUtils/__tests__/headersUtils.test.js +11 -1
- package/headersUtils/index.ts +2 -1
- package/manifestUtils/_internals/__tests__/index.test.js +41 -0
- package/manifestUtils/_internals/index.js +33 -0
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +63 -5
- package/manifestUtils/index.js +3 -1
- package/manifestUtils/keys.js +236 -0
- package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
- package/manifestUtils/mobileAction/button/index.js +156 -0
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
- package/manifestUtils/mobileAction/container/index.js +75 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
- package/manifestUtils/mobileAction/groups/defaults.js +78 -0
- package/manifestUtils/mobileAction/groups/index.js +80 -0
- package/manifestUtils/tvAction/container/index.js +1 -1
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +54 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
- package/numberUtils/index.ts +46 -5
- package/package.json +4 -4
- package/pluginUtils/index.ts +4 -0
- package/reactHooks/actions/index.ts +51 -1
- package/reactHooks/advertising/index.ts +2 -2
- package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
- package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
- package/reactHooks/cell-click/__tests__/index.test.js +1 -3
- package/reactHooks/cell-click/index.ts +15 -7
- package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
- package/reactHooks/connection/__tests__/index.test.js +1 -1
- package/reactHooks/debugging/__tests__/index.test.js +4 -4
- package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
- package/reactHooks/device/useIsTablet.tsx +14 -19
- package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
- package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +26 -1
- package/reactHooks/feed/index.ts +5 -3
- package/reactHooks/feed/useBatchLoading.ts +17 -3
- package/reactHooks/feed/useEntryScreenId.ts +2 -2
- package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +14 -4
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
- package/reactHooks/layout/__tests__/index.test.tsx +1 -1
- package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
- package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
- package/reactHooks/navigation/__tests__/index.test.tsx +2 -4
- package/reactHooks/navigation/index.ts +7 -6
- package/reactHooks/navigation/useRoute.ts +8 -6
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
- package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
- package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
- package/reactHooks/resolvers/useCellResolver.ts +6 -2
- package/reactHooks/resolvers/useComponentResolver.ts +8 -2
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
- package/reactHooks/screen/__tests__/useIsStandaloneFullscreen.test.ts +114 -0
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
- package/reactHooks/screen/useTargetScreenData.ts +4 -2
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/state/useRivers.ts +1 -1
- package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
- package/reactHooks/usePluginConfiguration.ts +2 -2
- package/reactHooks/utils/__tests__/index.test.js +1 -1
- package/reactHooks/utils/index.ts +3 -2
- package/rectUtils/__tests__/index.test.ts +549 -0
- package/rectUtils/index.ts +2 -2
- package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
- package/refreshUtils/RefreshCoordinator/index.ts +245 -0
- package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
- package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/__tests__/index.test.ts +333 -0
- package/screenState/__tests__/index.test.ts +1 -1
- package/screenUtils/index.ts +3 -0
- package/searchUtils/const.ts +7 -0
- package/searchUtils/index.ts +3 -0
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +3 -3
- package/testUtils/index.tsx +30 -21
- package/time/__tests__/BackgroundTimer.test.ts +156 -0
- package/time/__tests__/Timer.test.ts +236 -0
- package/typeGuards/__tests__/isString.test.ts +21 -0
- package/typeGuards/index.ts +4 -0
- package/uiActionsRegistrator/index.ts +203 -0
- package/utils/__tests__/mergeRight.test.ts +48 -0
- package/utils/__tests__/path.test.ts +7 -0
- package/utils/__tests__/selectors.test.ts +124 -0
- package/utils/index.ts +13 -0
- package/utils/mergeRight.ts +5 -0
- package/utils/path.ts +6 -3
- package/utils/pathOr.ts +5 -1
- package/utils/selectors.ts +46 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +1 -1
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
- package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
- package/reactHooks/componentsMap/index.ts +0 -55
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
- package/reactHooks/feed/useFeedRefresh.tsx +0 -65
package/utils/pathOr.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { get } from "lodash";
|
|
2
2
|
|
|
3
|
-
export const pathOr =
|
|
3
|
+
export const pathOr = <T = any>(
|
|
4
|
+
defaultValue: T,
|
|
5
|
+
path: (number | string) | (number | string)[],
|
|
6
|
+
record: any
|
|
7
|
+
): T => {
|
|
4
8
|
return get(record, path, defaultValue);
|
|
5
9
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { get } from "lodash";
|
|
2
|
+
|
|
3
|
+
export type Selector<T> = (state: any) => T;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a selector for filtering plugins by path
|
|
7
|
+
* @param path - Path to check in plugin. Can be a dot notation string or array
|
|
8
|
+
* @returns A selector function that returns matching plugins
|
|
9
|
+
*/
|
|
10
|
+
export const createPluginsByPathSelector = (
|
|
11
|
+
path: string | string[]
|
|
12
|
+
): Selector<any[]> => {
|
|
13
|
+
return (state: any) => {
|
|
14
|
+
const plugins = state.plugins || [];
|
|
15
|
+
|
|
16
|
+
return plugins.filter((plugin: any) => get(plugin, path));
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates a selector for filtering plugins by module path
|
|
22
|
+
* @param modulePath - Module path to check in plugin (e.g., "urlScheme", "player")
|
|
23
|
+
* @returns A selector function that returns plugins with specified module
|
|
24
|
+
*/
|
|
25
|
+
export const createPluginsByModuleSelector = (
|
|
26
|
+
modulePath: string
|
|
27
|
+
): Selector<any[]> => {
|
|
28
|
+
return createPluginsByPathSelector(["module", modulePath]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a selector that combines multiple plugin selectors
|
|
33
|
+
* @param selectors - Array of plugin selectors to combine
|
|
34
|
+
* @returns A selector function that returns plugins matching all conditions
|
|
35
|
+
*/
|
|
36
|
+
export const combinePluginSelectors = (
|
|
37
|
+
...selectors: Selector<any[]>[]
|
|
38
|
+
): Selector<any[]> => {
|
|
39
|
+
return (state: any) => {
|
|
40
|
+
return selectors.reduce((filtered, selector) => {
|
|
41
|
+
const selected = selector(state);
|
|
42
|
+
|
|
43
|
+
return filtered.filter((plugin) => selected.includes(plugin));
|
|
44
|
+
}, state.plugins || []);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -85,7 +85,7 @@ export const getNavigationKeys = (
|
|
|
85
85
|
const general = (item?.general ?? {}) as General;
|
|
86
86
|
|
|
87
87
|
const pluginIdentifier =
|
|
88
|
-
(item as any)
|
|
88
|
+
(item as any).identifier ?? item?.type ?? item?.component_type ?? "";
|
|
89
89
|
|
|
90
90
|
const legacy =
|
|
91
91
|
legacyMappingKeys[`${pluginIdentifier}.${resultType}`] ??
|
|
@@ -20,7 +20,7 @@ const callbackKeyPrefix = (key, prefix, keySeparator = "_") =>
|
|
|
20
20
|
|
|
21
21
|
const extendManifestWithHookCallback = (prefix = null) => ({
|
|
22
22
|
group: true,
|
|
23
|
-
label:
|
|
23
|
+
label: `CallBack Navigation: ${prefix}`,
|
|
24
24
|
folded: true,
|
|
25
25
|
fields: [
|
|
26
26
|
{
|
|
@@ -20,7 +20,7 @@ const isAuthenticationRequired = ({ payload, logs }) => {
|
|
|
20
20
|
|
|
21
21
|
if (!payload) {
|
|
22
22
|
log_info(
|
|
23
|
-
"isAuthenticationRequired: No payload
|
|
23
|
+
"isAuthenticationRequired: No payload exist, authentication required"
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
return true;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
const layoutReducer = (state, { payload }) => {
|
|
4
|
-
return state.map((item, index, _state) => ({
|
|
5
|
-
height: index === payload.index ? payload.height : item.height,
|
|
6
|
-
y:
|
|
7
|
-
index > 0
|
|
8
|
-
? _state.slice(0, index).reduce((acc, value) => acc + value.height, 0)
|
|
9
|
-
: 0,
|
|
10
|
-
}));
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const useComponentsLayout = (count, onFinishLoadingVisible) => {
|
|
14
|
-
const [itemsLayout, dispatchItemLayout] = React.useReducer(
|
|
15
|
-
layoutReducer,
|
|
16
|
-
Array.from({ length: count }, () => ({ height: 0, y: 0 }))
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const notified = React.useRef(false);
|
|
20
|
-
const [listHeight, setListHeight] = React.useState<number>(0);
|
|
21
|
-
|
|
22
|
-
const onItemLayout = React.useCallback(
|
|
23
|
-
(index) => (event) => {
|
|
24
|
-
const { height } = event.nativeEvent.layout;
|
|
25
|
-
dispatchItemLayout({ payload: { index, height } });
|
|
26
|
-
},
|
|
27
|
-
[]
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const onListLayout = React.useCallback((event) => {
|
|
31
|
-
const { height } = event.nativeEvent.layout;
|
|
32
|
-
setListHeight(height);
|
|
33
|
-
}, []);
|
|
34
|
-
|
|
35
|
-
React.useEffect(() => {
|
|
36
|
-
if (!notified.current) {
|
|
37
|
-
const finishLoadingVisible = !!itemsLayout.find(
|
|
38
|
-
(item) => item.y > listHeight
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
if (finishLoadingVisible) {
|
|
42
|
-
notified.current = true;
|
|
43
|
-
onFinishLoadingVisible?.();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, [itemsLayout, listHeight]);
|
|
47
|
-
|
|
48
|
-
return React.useMemo(
|
|
49
|
-
() => ({
|
|
50
|
-
onItemLayout,
|
|
51
|
-
onListLayout,
|
|
52
|
-
}),
|
|
53
|
-
[]
|
|
54
|
-
);
|
|
55
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const usePipesCacheReset = jest.fn();
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
|
|
3
|
-
jest.useFakeTimers();
|
|
4
|
-
|
|
5
|
-
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
6
|
-
useIsScreenActive: () => true,
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
const { useFeedRefresh, feedRefreshLogger } = require("..");
|
|
10
|
-
|
|
11
|
-
describe("useFeedRefresh", () => {
|
|
12
|
-
const reloadData = jest.fn();
|
|
13
|
-
|
|
14
|
-
const component = {
|
|
15
|
-
id: "foo",
|
|
16
|
-
rules: { enable_data_refreshing: true, refreshing_interval: 61 },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
it("Calls reloadData after passed time lapses", () => {
|
|
20
|
-
renderHook(() => useFeedRefresh({ reloadData, component }));
|
|
21
|
-
|
|
22
|
-
expect(reloadData).not.toBeCalled();
|
|
23
|
-
jest.runOnlyPendingTimers();
|
|
24
|
-
expect(reloadData).toBeCalled();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("Logs warning message if refresh time set below minimum value", () => {
|
|
28
|
-
const loggerSpy = jest.spyOn(feedRefreshLogger, "warning");
|
|
29
|
-
|
|
30
|
-
renderHook(() =>
|
|
31
|
-
useFeedRefresh({
|
|
32
|
-
reloadData,
|
|
33
|
-
component: {
|
|
34
|
-
...component,
|
|
35
|
-
rules: { enable_data_refreshing: true, refreshing_interval: 2 },
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
expect(loggerSpy).toBeCalled();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("Calls reloadData on a Component that had a timer setup and was re-mounted", () => {
|
|
44
|
-
reloadData.mockReset();
|
|
45
|
-
|
|
46
|
-
// it is not called before rendering hook"
|
|
47
|
-
expect(reloadData).not.toBeCalled();
|
|
48
|
-
|
|
49
|
-
// it is not called when rendering new component (Not previously rendered)
|
|
50
|
-
renderHook(() =>
|
|
51
|
-
useFeedRefresh({ reloadData, component: { ...component, id: "bar" } })
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
expect(reloadData).not.toBeCalled();
|
|
55
|
-
|
|
56
|
-
// it is called when rendering previously rendered component",
|
|
57
|
-
renderHook(() => useFeedRefresh({ reloadData, component }));
|
|
58
|
-
expect(reloadData).toBeCalled();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("Doesn't refresh data when enable_data_refreshing if false", () => {
|
|
62
|
-
reloadData.mockReset();
|
|
63
|
-
|
|
64
|
-
renderHook(() =>
|
|
65
|
-
useFeedRefresh({
|
|
66
|
-
reloadData,
|
|
67
|
-
component: { ...component, rules: { enable_data_refreshing: false } },
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
jest.runOnlyPendingTimers();
|
|
72
|
-
|
|
73
|
-
expect(reloadData).not.toBeCalled();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { path, max } from "ramda";
|
|
3
|
-
import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
4
|
-
import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
5
|
-
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
6
|
-
|
|
7
|
-
import { reactHooksLogger } from "../logger";
|
|
8
|
-
import { ReloadDataFunction } from "./useFeedLoader";
|
|
9
|
-
|
|
10
|
-
export const feedRefreshLogger = reactHooksLogger.addSubsystem("feed-refresh");
|
|
11
|
-
|
|
12
|
-
type Props = {
|
|
13
|
-
reloadData?: ReloadDataFunction;
|
|
14
|
-
component: ZappUIComponent;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const previousTimersMap = {};
|
|
18
|
-
const minimumRefreshingInterval = 5;
|
|
19
|
-
const defaultRefreshInterval = 60;
|
|
20
|
-
|
|
21
|
-
export const useFeedRefresh = ({ reloadData, component }: Props): void => {
|
|
22
|
-
const isDataRefreshingEnabled = isTrue(
|
|
23
|
-
path(["rules", "enable_data_refreshing"], component)
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const refreshing_interval = toNumberWithDefault(
|
|
27
|
-
defaultRefreshInterval,
|
|
28
|
-
component?.rules?.refreshing_interval
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const refreshingIntervalInMilliseconds =
|
|
32
|
-
max(refreshing_interval, minimumRefreshingInterval) * 1000;
|
|
33
|
-
|
|
34
|
-
const isScreenActive = useIsScreenActive();
|
|
35
|
-
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
if (isDataRefreshingEnabled && refreshing_interval && isScreenActive) {
|
|
38
|
-
if (refreshing_interval < minimumRefreshingInterval) {
|
|
39
|
-
feedRefreshLogger.warning({
|
|
40
|
-
message: `You set your feed refresh interval to ${refreshing_interval} when minimum value is ${minimumRefreshingInterval}seconds.Your feed will refresh after ${minimumRefreshingInterval}seconds.`,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!reloadData || typeof reloadData !== "function") {
|
|
45
|
-
feedRefreshLogger.warning({
|
|
46
|
-
message:
|
|
47
|
-
"reloadData function is undefined, feed refresh feature won't work properly",
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (previousTimersMap[component?.id]) {
|
|
52
|
-
reloadData?.();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const refreshInterval = setInterval(() => {
|
|
56
|
-
reloadData?.();
|
|
57
|
-
}, refreshingIntervalInMilliseconds);
|
|
58
|
-
|
|
59
|
-
return () => {
|
|
60
|
-
previousTimersMap[component?.id] = true;
|
|
61
|
-
clearInterval(refreshInterval);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}, [reloadData, isScreenActive]);
|
|
65
|
-
};
|