@applicaster/zapp-react-native-ui-components 14.0.0-alpha.1661204539 → 14.0.0-alpha.1740013076

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.
Files changed (157) hide show
  1. package/Components/AnimatedInOut/index.tsx +5 -3
  2. package/Components/AudioPlayer/index.tsx +15 -0
  3. package/Components/AudioPlayer/mobile/Layout.tsx +66 -0
  4. package/Components/AudioPlayer/{__tests__/__snapshots__/audioPlayer.test.js.snap → mobile/__tests__/__snapshots__/audioPlayerMobileLayout.test.js.snap} +2 -2
  5. package/Components/AudioPlayer/mobile/__tests__/audioPlayerMobileLayout.test.js +18 -0
  6. package/Components/AudioPlayer/mobile/index.tsx +18 -0
  7. package/Components/AudioPlayer/tv/Artwork.tsx +41 -0
  8. package/Components/AudioPlayer/{Channel.tsx → tv/Channel.tsx} +7 -7
  9. package/Components/AudioPlayer/tv/Layout.tsx +168 -0
  10. package/Components/AudioPlayer/{Runtime.tsx → tv/Runtime.tsx} +9 -2
  11. package/Components/AudioPlayer/{Summary.tsx → tv/Summary.tsx} +17 -10
  12. package/Components/AudioPlayer/tv/Title.tsx +46 -0
  13. package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/Runtime.test.js.snap +4 -4
  14. package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/artWork.test.js.snap +9 -4
  15. package/Components/AudioPlayer/tv/__tests__/__snapshots__/audioPlayer.test.js.snap +164 -0
  16. package/Components/AudioPlayer/tv/__tests__/__snapshots__/channel.test.js.snap +19 -0
  17. package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/summary.test.js.snap +2 -3
  18. package/Components/AudioPlayer/{__tests__ → tv/__tests__}/__snapshots__/title.test.js.snap +2 -3
  19. package/Components/AudioPlayer/{__tests__ → tv/__tests__}/audioPlayer.test.js +7 -3
  20. package/Components/AudioPlayer/{helpers.tsx → tv/helpers.tsx} +13 -7
  21. package/Components/AudioPlayer/{AudioPlayer.tsx → tv/index.tsx} +18 -57
  22. package/Components/AudioPlayer/types.ts +40 -0
  23. package/Components/BaseFocusable/index.tsx +23 -12
  24. package/Components/Cell/Cell.tsx +91 -64
  25. package/Components/Cell/CellWithFocusable.tsx +3 -0
  26. package/Components/Cell/__tests__/CellWIthFocusable.test.js +3 -2
  27. package/Components/Cell/index.js +7 -3
  28. package/Components/ComponentResolver/index.ts +1 -1
  29. package/Components/FeedLoader/FeedLoader.tsx +7 -16
  30. package/Components/FeedLoader/FeedLoaderHOC.tsx +21 -0
  31. package/Components/FeedLoader/index.js +2 -8
  32. package/Components/Focusable/Focusable.tsx +12 -3
  33. package/Components/Focusable/FocusableTvOS.tsx +5 -5
  34. package/Components/Focusable/FocusableiOS.tsx +2 -2
  35. package/Components/Focusable/__tests__/index.android.test.tsx +3 -0
  36. package/Components/Focusable/index.android.tsx +12 -8
  37. package/Components/Focusable/index.tsx +1 -1
  38. package/Components/FocusableGroup/FocusableTvOS.tsx +1 -1
  39. package/Components/FocusableList/index.tsx +6 -2
  40. package/Components/FreezeWithCallback/__tests__/index.test.tsx +67 -43
  41. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +0 -2
  42. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +42 -59
  43. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +13 -10
  44. package/Components/HandlePlayable/HandlePlayable.tsx +25 -9
  45. package/Components/Layout/TV/LayoutBackground.tsx +1 -1
  46. package/Components/Layout/TV/__tests__/index.test.tsx +0 -1
  47. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +6 -2
  48. package/Components/MasterCell/DefaultComponents/Button.tsx +1 -1
  49. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -39
  50. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +1 -1
  51. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +1 -1
  52. package/Components/MasterCell/DefaultComponents/Text/index.tsx +27 -6
  53. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +10 -10
  54. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +18 -18
  55. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/index.test.tsx +10 -10
  56. package/Components/MasterCell/elementMapper.tsx +1 -2
  57. package/Components/MasterCell/index.tsx +1 -1
  58. package/Components/MasterCell/utils/behaviorProvider.ts +19 -6
  59. package/Components/MasterCell/utils/index.ts +9 -13
  60. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +13 -18
  61. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +9 -0
  62. package/Components/OfflineHandler/__tests__/index.test.tsx +26 -35
  63. package/Components/PlayerContainer/ErrorDisplay/index.ts +1 -1
  64. package/Components/PlayerContainer/PlayerContainer.tsx +66 -67
  65. package/Components/PlayerContainer/ProgramInfo/index.tsx +1 -1
  66. package/Components/PlayerContainer/index.ts +1 -1
  67. package/Components/PlayerImageBackground/index.tsx +1 -1
  68. package/Components/River/ComponentsMap/ComponentsMap.tsx +1 -6
  69. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +378 -0
  70. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +2 -2
  71. package/Components/River/RefreshControl.tsx +11 -17
  72. package/Components/River/RiverItem.tsx +8 -8
  73. package/Components/River/TV/River.tsx +2 -20
  74. package/Components/River/TV/index.tsx +3 -1
  75. package/Components/River/TV/withPipesV1DataLoader.tsx +43 -0
  76. package/Components/River/TV/withRiverDataLoader.tsx +17 -0
  77. package/Components/River/TV/withTVEventHandler.tsx +1 -1
  78. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -6
  79. package/Components/River/__tests__/river.test.js +12 -26
  80. package/Components/River/index.tsx +1 -1
  81. package/Components/Screen/__tests__/Screen.test.tsx +28 -29
  82. package/Components/Screen/__tests__/navigationHandler.test.ts +133 -22
  83. package/Components/Screen/navigationHandler.ts +20 -2
  84. package/Components/ScreenRevealManager/ScreenRevealManager.ts +76 -0
  85. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +107 -0
  86. package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +96 -0
  87. package/Components/ScreenRevealManager/index.ts +1 -0
  88. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +79 -0
  89. package/Components/Tabs/TV/Tabs.android.tsx +1 -3
  90. package/Components/Tabs/Tabs.tsx +2 -3
  91. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +13 -0
  92. package/Components/TextInputTv/index.tsx +11 -0
  93. package/Components/TopMarginApplicator/TopMarginApplicator.tsx +16 -15
  94. package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +34 -0
  95. package/Components/Touchable/__tests__/touchable.test.tsx +12 -17
  96. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +15 -9
  97. package/Components/VideoLive/animationUtils.ts +3 -3
  98. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +3 -9
  99. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +294 -0
  100. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +93 -0
  101. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +32 -8
  102. package/Components/VideoModal/PlayerDetails.tsx +24 -2
  103. package/Components/VideoModal/PlayerWrapper.tsx +26 -142
  104. package/Components/VideoModal/VideoModal.tsx +3 -17
  105. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -5
  106. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -7
  107. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +44 -180
  108. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +17 -55
  109. package/Components/VideoModal/hooks/index.ts +0 -2
  110. package/Components/VideoModal/hooks/useDelayedPlayerDetails.ts +15 -26
  111. package/Components/VideoModal/hooks/useModalSize.ts +18 -2
  112. package/Components/VideoModal/utils.ts +6 -0
  113. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +12 -16
  114. package/Components/Viewport/ViewportTracker/__tests__/viewportTracker.test.js +84 -24
  115. package/Components/Viewport/VisibilitySensor/VisibilitySensor.tsx +3 -3
  116. package/Components/default-cell-renderer/viewTrees/tv/DefaultCell/index.ts +3 -3
  117. package/Contexts/CellFocusedStateContext/index.tsx +27 -0
  118. package/Contexts/ConfigutaionContext/__tests__/ConfigurationProvider.test.tsx +3 -3
  119. package/Contexts/ScreenContext/index.tsx +46 -6
  120. package/Decorators/ConfigurationWrapper/__tests__/withConfigurationProvider.test.tsx +3 -3
  121. package/Decorators/ConfigurationWrapper/withConfigurationProvider.tsx +2 -2
  122. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +221 -209
  123. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +14 -16
  124. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -20
  125. package/Decorators/RiverFeedLoader/index.tsx +21 -9
  126. package/Decorators/RiverFeedLoader/utils/index.ts +0 -23
  127. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +3 -6
  128. package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -0
  129. package/Decorators/ZappPipesDataConnector/__tests__/NullFeedResolver.test.tsx +78 -0
  130. package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +205 -0
  131. package/Decorators/ZappPipesDataConnector/__tests__/StaticFeedResolver.test.tsx +251 -0
  132. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +368 -0
  133. package/Decorators/ZappPipesDataConnector/__tests__/utils.test.ts +39 -0
  134. package/Decorators/ZappPipesDataConnector/index.tsx +27 -308
  135. package/Decorators/ZappPipesDataConnector/resolvers/NullFeedResolver.tsx +25 -0
  136. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +87 -0
  137. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +266 -0
  138. package/Decorators/ZappPipesDataConnector/types.ts +29 -0
  139. package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +738 -0
  140. package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +157 -0
  141. package/events/index.ts +1 -0
  142. package/index.d.ts +0 -1
  143. package/package.json +5 -10
  144. package/Components/AudioPlayer/Artwork.tsx +0 -35
  145. package/Components/AudioPlayer/AudioPlayerLayout.tsx +0 -202
  146. package/Components/AudioPlayer/Title.tsx +0 -39
  147. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayerLayout.test.js.snap +0 -66
  148. package/Components/AudioPlayer/__tests__/__snapshots__/channel.test.js.snap +0 -28
  149. package/Components/AudioPlayer/__tests__/audioPlayerLayout.test.js +0 -26
  150. package/Components/AudioPlayer/index.ts +0 -1
  151. package/Components/River/__tests__/__snapshots__/river.test.js.snap +0 -27
  152. package/Components/VideoModal/hooks/useBackgroundColor.ts +0 -10
  153. /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/Runtime.test.js +0 -0
  154. /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/artWork.test.js +0 -0
  155. /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/channel.test.js +0 -0
  156. /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/summary.test.js +0 -0
  157. /package/Components/AudioPlayer/{__tests__ → tv/__tests__}/title.test.js +0 -0
@@ -1,28 +1,12 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  /// <reference types="@applicaster/zapp-react-native-ui-components" />
3
- import React, { useEffect, useMemo } from "react";
4
-
5
- import * as R from "ramda";
6
- import { Platform } from "react-native";
7
- import Url from "url";
8
- import { favoritesListener } from "@applicaster/zapp-react-native-bridge/Favorites";
9
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
3
+ import React from "react";
10
4
  import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
11
- import {
12
- getInflatedDataSourceUrl,
13
- getSearchContext,
14
- useFeedLoader,
15
- useFeedRefresh,
16
- } from "@applicaster/zapp-react-native-utils/reactHooks";
17
-
5
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
18
6
  import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
19
7
  import { useScreenContext } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
20
-
21
- import { isVerticalListOrGrid } from "./utils";
22
- import {
23
- subscribeForUrlContextKeyChanges,
24
- subscribeForUrlScreenKeyChanges,
25
- } from "@applicaster/zapp-pipes-v2-client";
8
+ import { ResolverSelector } from "./ResolverSelector";
9
+ import { ComponentDataSourceContext } from "./types";
26
10
 
27
11
  type Props = {
28
12
  component: ZappUIComponent;
@@ -30,186 +14,16 @@ type Props = {
30
14
  riverId: string;
31
15
  getStaticComponentFeed?: GeneralContentScreenProps["getStaticComponentFeed"];
32
16
  componentIndex?: number;
33
-
34
17
  isScreenWrappedInContainer?: boolean;
35
18
  isLast?: boolean;
36
19
  };
37
20
 
38
- const FAVORITES_TYPE = "FAVOURITES";
39
-
40
- function getDataSourceUrl({
41
- component,
42
- feedUrl,
43
- screenData,
44
- entryContext,
45
- searchContext,
46
- screenContext,
47
- }): { dataSourceUrl: string | null; type: string | null } {
48
- if (feedUrl) {
49
- return { dataSourceUrl: feedUrl, type: null };
50
- }
51
-
52
- if (component.data) {
53
- const {
54
- data: { source, type, mapping },
55
- } = component;
56
-
57
- if (type === FAVORITES_TYPE) {
58
- return { dataSourceUrl: source || FAVORITES_TYPE, type };
59
- }
60
-
61
- if (source) {
62
- if (type === "APPLICASTER_COLLECTION" && !R.includes("://", source)) {
63
- return {
64
- dataSourceUrl: `applicaster://fetchData?type=${type}&collectionId=${source}`,
65
- type,
66
- };
67
- }
68
-
69
- if (type === "APPLICASTER_CATEGORY" && !R.includes("://", source)) {
70
- return {
71
- dataSourceUrl: `applicaster://fetchData?type=${type}&categoryId=${source}&platform=${Platform.OS}`,
72
- type,
73
- };
74
- }
75
-
76
- if (mapping) {
77
- const contexts = {
78
- entry: entryContext,
79
- screen: screenContext || screenData,
80
- search: getSearchContext(searchContext, mapping),
81
- };
82
-
83
- const dataSourceUrl = getInflatedDataSourceUrl({
84
- source,
85
- mapping,
86
- contexts,
87
- });
88
-
89
- if (!dataSourceUrl) {
90
- return { dataSourceUrl: null, type: null };
91
- }
92
-
93
- return { dataSourceUrl, type };
94
- }
95
-
96
- return { dataSourceUrl: source, type };
97
- }
98
- }
99
-
100
- return { dataSourceUrl: null, type: null };
101
- }
102
-
103
- function applyItemLimit(zappPipesData, component) {
104
- if (!zappPipesData || !zappPipesData.data) {
105
- return zappPipesData;
106
- }
107
-
108
- const { data } = zappPipesData;
109
-
110
- const {
111
- rules: { item_limit },
112
- } = component;
113
-
114
- if (item_limit && data.entry && data.entry.length) {
115
- return {
116
- ...zappPipesData,
117
- data: {
118
- ...data,
119
- entry: R.slice(
120
- 0,
121
- Math.min(Number(item_limit), R.length(data.entry)),
122
- data.entry
123
- ),
124
- },
125
- };
126
- }
127
-
128
- return zappPipesData;
129
- }
130
-
131
- function getListenerFromPlugin(
132
- dataSourceUrl: string,
133
- plugins: QuickBrickPlugin[]
134
- ): AddDataSourceListener | void {
135
- const url = Url.parse(dataSourceUrl, false);
136
-
137
- const addListener = R.compose(
138
- R.path(["module", "addDataSourceListener"]),
139
- R.find(R.propEq("identifier", url.host))
140
- )(plugins);
141
-
142
- return addListener;
143
- }
144
-
145
- const getMethodAndParams = (component) => {
146
- const method: "get" | "post" = R.pathOr("get", ["data", "method"], component);
147
-
148
- const bodyParams: Record<string, unknown> = R.pathOr(
149
- {},
150
- ["data", "bodyParams"],
151
- component
152
- );
153
-
154
- return {
155
- method,
156
- bodyParams,
157
- };
158
- };
159
-
160
- const generateStaticUrl = (component: ZappUIComponent) => {
161
- const { id, position } = component || {};
162
-
163
- return `static://component?id=${id}&position=${position}`;
164
- };
165
-
166
- const reducer = (state, action) => {
167
- switch (action.type) {
168
- case "SET_DATA":
169
- return { ...state, data: action.payload, loading: false };
170
- case "SET_ERROR":
171
- return { ...state, error: action.payload, loading: false };
172
- default:
173
- return state;
174
- }
175
- };
176
-
177
- const useGetStaticFeed = (getter, component, index) => {
178
- const url = generateStaticUrl(component);
179
-
180
- // refactor above 3 states to use reducer
181
-
182
- const [{ loading, data, error }, dispatch] = React.useReducer(reducer, {
183
- loading: true,
184
- data: null,
185
- error: null,
186
- });
187
-
188
- React.useEffect(() => {
189
- const getData = async () => {
190
- try {
191
- const res = await getter({ index, component });
192
- dispatch({ type: "SET_DATA", payload: res });
193
- } catch (err) {
194
- dispatch({ type: "SET_ERROR", payload: err });
195
- }
196
- };
197
-
198
- if (getter) {
199
- getData();
200
- }
201
- }, [getter, component, index]);
202
-
203
- return { url, loading, data, error };
204
- };
205
-
206
21
  export function zappPipesDataConnector(
207
22
  Component: React.FC<any> | React.ComponentClass<any>
208
23
  ) {
209
24
  return function WrappedWithZappPipesData(props: Props) {
210
- const { screenData, pathname } = useRoute();
25
+ const { screenData } = useRoute();
211
26
  const { plugins } = usePickFromState(["plugins"]);
212
-
213
27
  const screenContextData = useScreenContext();
214
28
 
215
29
  const {
@@ -222,12 +36,8 @@ export function zappPipesDataConnector(
222
36
  isLast = false,
223
37
  } = props;
224
38
 
225
- /**
226
- * TODO: HACK for the tabs screen which needs to use 2 types of context.
227
- * ui_components rendered above tabs selector need to use entryContext
228
- * Screens rendered inside tabs selector need to use nested context.
229
- * This hack works because ui_components are rendered using ComponentsMap which doesn't have riverId prop
230
- **/
39
+ // Handle context determination
40
+ // HACK for the tabs screen which needs to use 2 types of context.
231
41
  const shouldUseNestedContext = isScreenWrappedInContainer && riverId;
232
42
 
233
43
  const entryContext =
@@ -243,119 +53,28 @@ export function zappPipesDataConnector(
243
53
 
244
54
  const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
245
55
 
246
- const { dataSourceUrl, type } = useMemo(
247
- () =>
248
- getDataSourceUrl({
249
- component,
250
- feedUrl,
251
- screenData,
252
- entryContext,
253
- searchContext,
254
- screenContext,
255
- }),
256
- [
257
- component.id,
258
- feedUrl,
259
- entryContext,
260
- searchContext,
261
- screenContext,
262
- screenData.id,
263
- ]
264
- );
265
-
266
- const shouldClearCache = useMemo(
267
- () => Boolean(component?.rules?.clear_cache_on_reload),
268
- [component?.id]
269
- );
270
-
271
- const pipesOptions = useMemo(
272
- () => ({
273
- clearCache: type === FAVORITES_TYPE,
274
- loadLocalFavorites: type === FAVORITES_TYPE,
275
- silentRefresh: !shouldClearCache,
276
- ...getMethodAndParams(component),
277
- }),
278
- [type, shouldClearCache, component]
279
- );
280
-
281
- const { reloadData, loadNext, error, loading, url, data } = useFeedLoader({
282
- feedUrl: dataSourceUrl ?? "",
283
- pipesOptions,
284
- });
285
-
286
- const staticFeed = useGetStaticFeed(
287
- getStaticComponentFeed,
56
+ // Prepare context for resolvers
57
+ const resolverProps: ComponentDataSourceContext = {
288
58
  component,
289
- componentIndex
290
- );
291
-
292
- useEffect(() => {
293
- if (!(dataSourceUrl?.includes("pipesv2://") && reloadData)) {
294
- return subscribeForUrlScreenKeyChanges(
295
- dataSourceUrl,
296
- pathname,
297
- {},
298
- reloadData
299
- );
300
- }
301
- }, [dataSourceUrl, reloadData]);
302
-
303
- useEffect(() => {
304
- if (dataSourceUrl?.includes("pipesv2://") && reloadData) {
305
- const addListener = getListenerFromPlugin(dataSourceUrl, plugins);
306
-
307
- if (addListener) {
308
- return addListener(reloadData);
309
- }
310
- } else {
311
- return subscribeForUrlContextKeyChanges(dataSourceUrl, {}, reloadData);
312
- }
313
- }, [dataSourceUrl, reloadData]);
314
-
315
- useEffect(() => {
316
- if (type === FAVORITES_TYPE && reloadData) {
317
- favoritesListener.on("FAVORITES_CHANGED", reloadData);
318
-
319
- return () => {
320
- favoritesListener.removeHandler("FAVORITES_CHANGED", reloadData);
321
- };
322
- }
323
- }, [type]);
324
-
325
- const getZappPipesData = React.useCallback(
326
- () =>
327
- getStaticComponentFeed && !url
328
- ? staticFeed
329
- : { error, loading, url, data },
330
- [staticFeed?.loading, staticFeed?.data, data?.next, loading, data]
331
- );
332
-
333
- const zappPipesDataProps = useMemo(() => {
334
- const loadNextData =
335
- !isLast && isVerticalListOrGrid(component) ? undefined : loadNext;
336
-
337
- return {
338
- zappPipesData: applyItemLimit(getZappPipesData(), component),
339
- reloadData,
340
- loadNextData,
341
- };
342
- }, [
343
- dataSourceUrl,
344
- data?.next,
345
- loading,
346
- reloadData,
347
- loadNext,
348
- getZappPipesData,
349
- data,
59
+ feedUrl,
60
+ getStaticComponentFeed,
61
+ componentIndex,
62
+ isScreenWrappedInContainer,
63
+ riverId,
350
64
  isLast,
351
- component,
352
- ]);
353
-
354
- useFeedRefresh({
355
- reloadData,
356
- component,
357
- });
65
+ entryContext,
66
+ screenContext,
67
+ searchContext,
68
+ screenData,
69
+ plugins,
70
+ };
358
71
 
359
- return <Component {...props} {...zappPipesDataProps} />;
72
+ return (
73
+ <ResolverSelector {...resolverProps}>
74
+ {(zappPipesDataProps) => (
75
+ <Component {...props} {...zappPipesDataProps} />
76
+ )}
77
+ </ResolverSelector>
78
+ );
360
79
  };
361
80
  }
@@ -0,0 +1,25 @@
1
+ // NullFeedResolver.tsx
2
+ import React, { useMemo } from "react";
3
+ import { ZappPipesDataProps } from "../types";
4
+
5
+ type NullFeedResolverProps = {
6
+ children: (dataProps: ZappPipesDataProps) => React.ReactNode;
7
+ };
8
+
9
+ export function NullFeedResolver({ children }: NullFeedResolverProps) {
10
+ const zappPipesDataProps = useMemo(
11
+ () => ({
12
+ zappPipesData: {
13
+ url: "",
14
+ loading: false,
15
+ data: null,
16
+ error: null,
17
+ },
18
+ reloadData: () => null,
19
+ loadNextData: undefined,
20
+ }),
21
+ []
22
+ );
23
+
24
+ return <>{children(zappPipesDataProps)}</>;
25
+ }
@@ -0,0 +1,87 @@
1
+ import React, { useEffect, useMemo, useReducer } from "react";
2
+ import { ComponentDataSourceContext, ZappPipesDataProps } from "../types";
3
+
4
+ const generateStaticUrl = (component: ZappUIComponent) => {
5
+ const { id, position } = component || {};
6
+
7
+ return `static://component?id=${id}&position=${position}`;
8
+ };
9
+
10
+ const reducer = (state, action) => {
11
+ switch (action.type) {
12
+ case "SET_DATA":
13
+ return { ...state, data: action.payload, loading: false };
14
+ case "SET_ERROR":
15
+ return { ...state, error: action.payload, loading: false };
16
+ default:
17
+ return state;
18
+ }
19
+ };
20
+
21
+ type StaticFeedResolverProps = ComponentDataSourceContext & {
22
+ children: (dataProps: ZappPipesDataProps) => React.ReactNode;
23
+ };
24
+
25
+ export function StaticFeedResolver({
26
+ children,
27
+ getStaticComponentFeed,
28
+ component,
29
+ componentIndex,
30
+ }: StaticFeedResolverProps) {
31
+ const url = generateStaticUrl(component);
32
+
33
+ const [{ loading, data, error }, dispatch] = useReducer(reducer, {
34
+ loading: true,
35
+ data: null,
36
+ error: null,
37
+ });
38
+
39
+ useEffect(() => {
40
+ const getData = async () => {
41
+ try {
42
+ const res = await getStaticComponentFeed({
43
+ index: componentIndex,
44
+ component,
45
+ });
46
+
47
+ dispatch({ type: "SET_DATA", payload: res });
48
+ } catch (err) {
49
+ dispatch({ type: "SET_ERROR", payload: err });
50
+ }
51
+ };
52
+
53
+ if (getStaticComponentFeed) {
54
+ getData();
55
+ }
56
+ }, [getStaticComponentFeed, component, componentIndex]);
57
+
58
+ const reloadData = async () => {
59
+ if (!getStaticComponentFeed) return Promise.resolve();
60
+
61
+ try {
62
+ const res = await getStaticComponentFeed({
63
+ index: componentIndex,
64
+ component,
65
+ });
66
+
67
+ dispatch({ type: "SET_DATA", payload: res });
68
+
69
+ return res;
70
+ } catch (err) {
71
+ dispatch({ type: "SET_ERROR", payload: err });
72
+
73
+ return Promise.reject(err);
74
+ }
75
+ };
76
+
77
+ const zappPipesDataProps = useMemo(
78
+ () => ({
79
+ zappPipesData: { url, loading, data, error },
80
+ reloadData,
81
+ loadNextData: undefined, // Static resolver doesn't support pagination
82
+ }),
83
+ [url, loading, data, error]
84
+ );
85
+
86
+ return <>{children(zappPipesDataProps)}</>;
87
+ }