@applicaster/zapp-react-native-utils 16.0.0-rc.9 → 16.0.0-rc.90
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/ActionExecutor.ts +57 -12
- package/actionsExecutor/ActionExecutorContext.tsx +113 -314
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +42 -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 +137 -0
- package/actionsExecutor/actions/openBottomSheet.ts +329 -0
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/refreshComponent.ts +85 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +93 -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/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +87 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/consts.ts +27 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +59 -0
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
- package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
- package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/index.js +20 -0
- package/analyticsUtils/analyticsMapper.ts +4 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
- package/appUtils/HooksManager/index.ts +12 -8
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/index.ts +1 -1
- package/appUtils/contextKeysManager/utils/index.ts +38 -25
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +115 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +6 -4
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +136 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/index.ts +33 -8
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +296 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +195 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +14 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +41 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/keys.js +9 -0
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/defaults.js +3 -1
- package/manifestUtils/modalBlocks.js +304 -0
- package/manifestUtils/platformIsTV.js +1 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +211 -0
- package/modalState/RemoteEditableCollection.ts +235 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +109 -0
- package/modalState/types.ts +160 -0
- package/modalState/useBottomSheetContent.ts +109 -0
- 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 +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
- package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
- package/pipesUtils/index.ts +1 -0
- package/pipesUtils/withPipesEndpoint.tsx +54 -0
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +41 -18
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/actions/index.ts +117 -2
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +39 -24
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/feed/index.ts +5 -1
- package/reactHooks/feed/useBatchLoading.ts +9 -1
- package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +3 -1
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +13 -2
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
- package/riverComponetsMeasurementProvider/index.tsx +12 -8
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -0
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference types="@applicaster/applicaster-types" />
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
import { Context, useContext, useState } from "react";
|
|
3
|
+
import { Context, useCallback, useContext, useEffect, useState } from "react";
|
|
4
4
|
import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ActionsContext";
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
observeEntryState,
|
|
8
|
+
RegisteredActionValue,
|
|
9
|
+
uiActionsRegistry,
|
|
10
|
+
} from "../../uiActionsRegistrator";
|
|
6
11
|
import { reactHooksLogger } from "../logger";
|
|
7
12
|
|
|
8
13
|
const logger = reactHooksLogger.addSubsystem("actions");
|
|
@@ -30,7 +35,13 @@ export function useActions<T = unknown>(plugId: string): any {
|
|
|
30
35
|
if (!logged) {
|
|
31
36
|
logger.warning({
|
|
32
37
|
message: `useActions: Couldn't find an action for ${plugId} plugin`,
|
|
33
|
-
|
|
38
|
+
// Identifiers only. The action map holds every plugin's module and
|
|
39
|
+
// live React context, which is far too large for a log line and can
|
|
40
|
+
// carry whatever state those plugins hold.
|
|
41
|
+
data: {
|
|
42
|
+
plugId,
|
|
43
|
+
availableActions: Object.keys(context?.actions ?? {}),
|
|
44
|
+
},
|
|
34
45
|
});
|
|
35
46
|
|
|
36
47
|
setLogged(true);
|
|
@@ -46,3 +57,107 @@ export function useActions<T = unknown>(plugId: string): any {
|
|
|
46
57
|
|
|
47
58
|
return context;
|
|
48
59
|
}
|
|
60
|
+
|
|
61
|
+
export type UseEntryActionState = {
|
|
62
|
+
state: CellActionEntryState | undefined;
|
|
63
|
+
invokeAction: (options?: InvokeArgsOptions) => void;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Subscribes a component to a single action's state for a given `entry`.
|
|
68
|
+
*
|
|
69
|
+
* It observes state changes reactively via `observeEntryState` (which is backed
|
|
70
|
+
* by the action's `addListener`), seeds the initial value synchronously from
|
|
71
|
+
* `initialEntryState`, and returns a memoized `invokeAction` that forwards
|
|
72
|
+
* optimistic `updateState` updates back into local state.
|
|
73
|
+
*
|
|
74
|
+
* This is the single, unified way to drive an action button - it works the same
|
|
75
|
+
* for registry actions, legacy context-provider actions and entry actions.
|
|
76
|
+
*/
|
|
77
|
+
export function useEntryActionState(
|
|
78
|
+
action: RegisteredActionValue | undefined,
|
|
79
|
+
entry: ZappEntry | ZappFeed
|
|
80
|
+
): UseEntryActionState {
|
|
81
|
+
const [state, setState] = useState<CellActionEntryState | undefined>(() =>
|
|
82
|
+
action?.initialEntryState?.(entry)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const entryId = (entry as ZappEntry)?.id;
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!action) return undefined;
|
|
89
|
+
|
|
90
|
+
// An action's stream is third-party code. Subscribing with only a `next`
|
|
91
|
+
// handler lets RxJS rethrow an error notification asynchronously, where no
|
|
92
|
+
// error boundary catches it - one plugin faulting would take the app down
|
|
93
|
+
// rather than this one button. The button keeps its last known state.
|
|
94
|
+
let subscription;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
subscription = observeEntryState(action, entry).subscribe({
|
|
98
|
+
next: setState,
|
|
99
|
+
error: (error) =>
|
|
100
|
+
logger.warning({
|
|
101
|
+
message:
|
|
102
|
+
"useEntryActionState: the action's state stream failed - the button keeps its last state",
|
|
103
|
+
data: { entryId, error },
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
logger.warning({
|
|
108
|
+
message:
|
|
109
|
+
"useEntryActionState: could not observe the action - the button keeps its initial state",
|
|
110
|
+
data: { entryId, error },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return () => subscription.unsubscribe();
|
|
117
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
118
|
+
}, [action, entryId]);
|
|
119
|
+
|
|
120
|
+
const invokeAction = useCallback(
|
|
121
|
+
(options: InvokeArgsOptions = {}) => {
|
|
122
|
+
if (typeof action?.invokeAction !== "function") {
|
|
123
|
+
// A button was rendered and pressed, and the press goes nowhere. Only
|
|
124
|
+
// reachable on a user interaction, so it costs nothing on render. The
|
|
125
|
+
// action value carries no identifier, so the label is what locates the
|
|
126
|
+
// button that misbehaved.
|
|
127
|
+
logger.warning({
|
|
128
|
+
message:
|
|
129
|
+
"useEntryActionState: the pressed action has no invokeAction - the press did nothing",
|
|
130
|
+
data: { entryId, label: state?.label },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
action?.invokeAction?.(entry, { updateState: setState, ...options });
|
|
135
|
+
},
|
|
136
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
137
|
+
[action, entryId]
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return { state, invokeAction };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A value that changes whenever a provider is added to or removed from
|
|
145
|
+
* `uiActionsRegistry`.
|
|
146
|
+
*
|
|
147
|
+
* Providers can register after the UI that wants them has rendered - the audio
|
|
148
|
+
* player registers playback speed only once its controller has state, and
|
|
149
|
+
* plugin-backed actions are bridged in from an effect. Put this in the
|
|
150
|
+
* dependency list of anything that resolves actions, so the list is re-read
|
|
151
|
+
* instead of being frozen at first paint.
|
|
152
|
+
*/
|
|
153
|
+
export function useRegistryRevision(): number {
|
|
154
|
+
const [revision, setRevision] = useState(0);
|
|
155
|
+
|
|
156
|
+
useEffect(
|
|
157
|
+
() =>
|
|
158
|
+
uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
|
|
159
|
+
[]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return revision;
|
|
163
|
+
}
|
|
@@ -5,6 +5,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
5
5
|
|
|
6
6
|
const mockNavigator = {
|
|
7
7
|
getPathname: () => "pathnameMock",
|
|
8
|
+
currentRoute: "pathnameMock",
|
|
8
9
|
push: jest.fn(),
|
|
9
10
|
data: {},
|
|
10
11
|
};
|
|
@@ -29,6 +30,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
|
29
30
|
),
|
|
30
31
|
useTargetScreenData: jest.fn(() => ({})),
|
|
31
32
|
useCurrentScreenData: jest.fn(() => ({})),
|
|
33
|
+
useScreenContext: jest.fn(() => ({})),
|
|
32
34
|
}));
|
|
33
35
|
|
|
34
36
|
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
@@ -66,6 +68,12 @@ const wrapper = ({ children }) => (
|
|
|
66
68
|
</CellTapContext.Provider>
|
|
67
69
|
);
|
|
68
70
|
|
|
71
|
+
const actionExecutorWrapper = ({ children }) => (
|
|
72
|
+
<ActionExecutorContext.Provider value={actionExecutor}>
|
|
73
|
+
{children}
|
|
74
|
+
</ActionExecutorContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
|
|
69
77
|
describe("useCellClick", () => {
|
|
70
78
|
it("returns a function", () => {
|
|
71
79
|
const { result } = renderHook(() => useCellClick(mockProps));
|
|
@@ -95,4 +103,60 @@ describe("useCellClick", () => {
|
|
|
95
103
|
|
|
96
104
|
cleanup();
|
|
97
105
|
});
|
|
106
|
+
|
|
107
|
+
it("does not push when the cell finishes a hook", async () => {
|
|
108
|
+
mockNavigator.push.mockClear();
|
|
109
|
+
|
|
110
|
+
const item = {
|
|
111
|
+
id: "profile-1",
|
|
112
|
+
type: { value: "feed" },
|
|
113
|
+
extensions: {
|
|
114
|
+
tap_actions: {
|
|
115
|
+
actions: [
|
|
116
|
+
{ type: "sessionStorageSet" },
|
|
117
|
+
{ type: "finishHook", options: { success: true } },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
124
|
+
wrapper: actionExecutorWrapper,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await result.current();
|
|
128
|
+
|
|
129
|
+
await waitFor(() => {
|
|
130
|
+
expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(mockNavigator.push).not.toHaveBeenCalled();
|
|
134
|
+
cleanup();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("pushes after tap actions that do not finish a hook", async () => {
|
|
138
|
+
mockNavigator.push.mockClear();
|
|
139
|
+
|
|
140
|
+
const item = {
|
|
141
|
+
id: "episode-1",
|
|
142
|
+
type: { value: "feed" },
|
|
143
|
+
extensions: {
|
|
144
|
+
tap_actions: {
|
|
145
|
+
actions: [{ type: "sessionStorageSet" }],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
151
|
+
wrapper: actionExecutorWrapper,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await result.current();
|
|
155
|
+
|
|
156
|
+
await waitFor(() => {
|
|
157
|
+
expect(mockNavigator.push).toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
cleanup();
|
|
161
|
+
});
|
|
98
162
|
});
|
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import * as R from "ramda";
|
|
5
5
|
import { handleActionSchemeUrl } from "@applicaster/quick-brick-core/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler";
|
|
6
6
|
import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
|
|
7
|
+
import { useUIComponentContext } from "@applicaster/zapp-react-native-ui-components/Contexts/UIComponentContext";
|
|
7
8
|
import {
|
|
8
9
|
useNavigation,
|
|
9
10
|
useProfilerLogging,
|
|
@@ -28,7 +29,6 @@ import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
|
28
29
|
type Props = {
|
|
29
30
|
item?: ZappEntry;
|
|
30
31
|
index?: number;
|
|
31
|
-
component?: ZappUIComponent;
|
|
32
32
|
zappPipesData?: ZappPipesData;
|
|
33
33
|
};
|
|
34
34
|
|
|
@@ -37,24 +37,25 @@ type onPressReturnFn =
|
|
|
37
37
|
| (() => void);
|
|
38
38
|
|
|
39
39
|
export const useCellClick = ({
|
|
40
|
-
component,
|
|
41
40
|
zappPipesData,
|
|
42
41
|
item,
|
|
43
|
-
}: Props): onPressReturnFn => {
|
|
42
|
+
}: Props = {}): onPressReturnFn => {
|
|
44
43
|
const { push, currentRoute } = useNavigation();
|
|
45
44
|
const { pathname } = useRoute();
|
|
46
45
|
const screenStateStore = useScreenStateStore();
|
|
47
46
|
|
|
48
47
|
const onCellTap: Option<Function> = React.useContext(CellTapContext);
|
|
49
48
|
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
49
|
+
const component = useUIComponentContext();
|
|
50
50
|
const screenData = useCurrentScreenData();
|
|
51
51
|
const screenState = useScreenContext()?.options;
|
|
52
|
+
const entry = useScreenContext()?.entry;
|
|
52
53
|
|
|
53
54
|
const cellSelectable = toBooleanWithDefaultTrue(
|
|
54
55
|
component?.rules?.component_cells_selectable
|
|
55
56
|
);
|
|
56
57
|
|
|
57
|
-
const [
|
|
58
|
+
const [_entryContext, setEntryContext] =
|
|
58
59
|
ZappPipesEntryContext.useZappPipesContext(pathname);
|
|
59
60
|
|
|
60
61
|
const logTimestamp = useProfilerLogging();
|
|
@@ -82,6 +83,12 @@ export const useCellClick = ({
|
|
|
82
83
|
|
|
83
84
|
logOnPress(selectedItem, pathname, component, onCellTap);
|
|
84
85
|
|
|
86
|
+
const tapActions = selectedItem?.extensions?.tap_actions?.actions;
|
|
87
|
+
|
|
88
|
+
const finishesHook =
|
|
89
|
+
Array.isArray(tapActions) &&
|
|
90
|
+
tapActions.some((action) => action?.type === "finishHook");
|
|
91
|
+
|
|
85
92
|
if (selectedItem) {
|
|
86
93
|
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
87
94
|
component,
|
|
@@ -89,7 +96,8 @@ export const useCellClick = ({
|
|
|
89
96
|
screenState,
|
|
90
97
|
screenRoute: pathname,
|
|
91
98
|
screenStateStore,
|
|
92
|
-
entryContext,
|
|
99
|
+
entryContext: selectedItem,
|
|
100
|
+
screenEntry: entry,
|
|
93
101
|
});
|
|
94
102
|
}
|
|
95
103
|
|
|
@@ -99,32 +107,39 @@ export const useCellClick = ({
|
|
|
99
107
|
url: selectedItem.link.href,
|
|
100
108
|
});
|
|
101
109
|
}
|
|
102
|
-
} else {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
} else if (isFunction(onCellTap)) {
|
|
111
|
+
onCellTap?.(selectedItem, _index);
|
|
112
|
+
} else if (!finishesHook) {
|
|
113
|
+
// finishHook already completes the hook and navigates to the original
|
|
114
|
+
// target. Pushing the cell as well stacks a second copy of that screen
|
|
115
|
+
// (e.g. home/home after a profile selector hook).
|
|
116
|
+
if (currentRoute === pathname || pathname.includes("video-modal")) {
|
|
117
|
+
const targetScreen = component?.data?.target;
|
|
118
|
+
|
|
119
|
+
push(
|
|
120
|
+
R.when(
|
|
121
|
+
() => targetScreen,
|
|
122
|
+
R.mergeLeft({ screen_type: targetScreen })
|
|
123
|
+
)(selectedItem)
|
|
124
|
+
);
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
},
|
|
119
128
|
[
|
|
120
|
-
|
|
121
|
-
currentRoute,
|
|
129
|
+
item,
|
|
122
130
|
setEntryContext,
|
|
123
|
-
pathname,
|
|
124
|
-
push,
|
|
125
131
|
sendAnalyticsOnPress,
|
|
132
|
+
logTimestamp,
|
|
133
|
+
pathname,
|
|
134
|
+
component,
|
|
135
|
+
onCellTap,
|
|
136
|
+
entry,
|
|
137
|
+
actionExecutor,
|
|
126
138
|
screenData,
|
|
127
139
|
screenState,
|
|
140
|
+
screenStateStore,
|
|
141
|
+
currentRoute,
|
|
142
|
+
push,
|
|
128
143
|
]
|
|
129
144
|
);
|
|
130
145
|
|
|
@@ -138,5 +153,5 @@ export const useCellClick = ({
|
|
|
138
153
|
onPressRef.current = onPress;
|
|
139
154
|
}
|
|
140
155
|
|
|
141
|
-
return React.useCallback(onPressRef.current, []);
|
|
156
|
+
return React.useCallback(onPressRef.current, [item]);
|
|
142
157
|
};
|
|
@@ -242,4 +242,29 @@ describe("useGetUrlInflater", () => {
|
|
|
242
242
|
const url = result.current(source, mapping);
|
|
243
243
|
expect(url).toBe("https://foo.com/shows/A123?q=user%20query");
|
|
244
244
|
});
|
|
245
|
+
|
|
246
|
+
it("handles search queries with apostrophes without HTML entity escaping or URL truncation", () => {
|
|
247
|
+
const source =
|
|
248
|
+
"https://api.pc-cms.tele.quebec/api/applicaster/v1/mobile/search?q={{q}}";
|
|
249
|
+
|
|
250
|
+
const mapping = {
|
|
251
|
+
q: { source: "search", property: "q" },
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const searchContext = getSearchContext("L'aventure", mapping);
|
|
255
|
+
|
|
256
|
+
const result = getInflatedDataSourceUrl({
|
|
257
|
+
source,
|
|
258
|
+
contexts: {
|
|
259
|
+
search: searchContext,
|
|
260
|
+
},
|
|
261
|
+
mapping,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(result).toBe(
|
|
265
|
+
"https://api.pc-cms.tele.quebec/api/applicaster/v1/mobile/search?q=L'aventure"
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(result).not.toContain("'");
|
|
269
|
+
});
|
|
245
270
|
});
|
package/reactHooks/feed/index.ts
CHANGED
|
@@ -6,7 +6,11 @@ export { useEntryScreenId } from "./useEntryScreenId";
|
|
|
6
6
|
|
|
7
7
|
export { useBuildPipesUrl } from "./useBuildPipesUrl";
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
useMarkPipesDataStale,
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
12
|
+
usePipesCacheReset,
|
|
13
|
+
} from "./useMarkPipesDataStale";
|
|
10
14
|
|
|
11
15
|
export { useBatchLoading } from "./useBatchLoading";
|
|
12
16
|
|
|
@@ -159,9 +159,17 @@ export const useBatchLoading = (
|
|
|
159
159
|
options.riverId,
|
|
160
160
|
]);
|
|
161
161
|
|
|
162
|
+
// Initial preload only. Batch loading warms the first batch of component
|
|
163
|
+
// feeds and signals readiness; the feed set is frozen at mount on purpose.
|
|
164
|
+
// Per-component loads and reloads (including stale revalidation) are owned by
|
|
165
|
+
// useFeedLoader in ZappPipesDataConnector. Re-running on `feeds`/input changes
|
|
166
|
+
// would re-fire on every store update and cause redundant dispatch storms, so
|
|
167
|
+
// this intentionally runs once on mount.
|
|
168
|
+
/* eslint-disable @wogns3623/better-exhaustive-deps/exhaustive-deps */
|
|
162
169
|
React.useEffect(() => {
|
|
163
170
|
runBatchLoading();
|
|
164
|
-
}, [
|
|
171
|
+
}, []);
|
|
172
|
+
/* eslint-enable @wogns3623/better-exhaustive-deps/exhaustive-deps */
|
|
165
173
|
|
|
166
174
|
React.useEffect(() => {
|
|
167
175
|
// check if all feeds are ready and set hasEverBeenReady to true
|
|
@@ -2,17 +2,19 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
|
|
4
4
|
import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
|
|
5
|
-
import {
|
|
5
|
+
import { markPipesDataStale } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
6
6
|
|
|
7
7
|
import { useRoute } from "../navigation";
|
|
8
8
|
import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Mark a river's `clear_cache_on_reload` feeds as stale when the screen is
|
|
12
|
+
* unmounted. The cached data is kept (so a screen sharing the same feed does
|
|
13
|
+
* not lose it mid-mount) and revalidated on next access.
|
|
12
14
|
* @param {string} riverId screen id
|
|
13
15
|
* @param {Array} riverComponents list of UI components
|
|
14
16
|
*/
|
|
15
|
-
export const
|
|
17
|
+
export const useMarkPipesDataStale = (riverId, riverComponents) => {
|
|
16
18
|
const dispatch = useAppDispatch();
|
|
17
19
|
const { screenData, pathname } = useRoute();
|
|
18
20
|
const pipesContexts = usePipesContexts(riverId, pathname);
|
|
@@ -35,10 +37,16 @@ export const usePipesCacheReset = (riverId, riverComponents) => {
|
|
|
35
37
|
);
|
|
36
38
|
|
|
37
39
|
if (url) {
|
|
38
|
-
dispatch(
|
|
40
|
+
dispatch(markPipesDataStale(url, { riverId }));
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
});
|
|
42
44
|
};
|
|
43
45
|
}, []);
|
|
44
46
|
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Renamed to `useMarkPipesDataStale`. Kept as an alias for backward
|
|
50
|
+
* compatibility with external consumers.
|
|
51
|
+
*/
|
|
52
|
+
export const usePipesCacheReset = useMarkPipesDataStale;
|
package/reactHooks/index.ts
CHANGED
|
@@ -38,3 +38,7 @@ export const useNavigationPluginData = jest.fn().mockReturnValue(mockMenu);
|
|
|
38
38
|
export const useIsNavBarVisible = jest.fn().mockReturnValue(true);
|
|
39
39
|
|
|
40
40
|
export const useIsScreenActive = jest.fn().mockReturnValue(true);
|
|
41
|
+
|
|
42
|
+
export const isScreenActiveForRoute = jest.fn(
|
|
43
|
+
(route, currentRoute) => route === currentRoute
|
|
44
|
+
);
|