@applicaster/zapp-react-native-utils 12.0.0-alpha.4155487673 → 12.0.0-alpha.4173603919
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/appUtils/accessibilityManager/index.ts +1 -12
- package/appUtils/platform/platformUtils.ts +35 -2
- package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/usePlayerState.tsx +19 -34
- package/arrayUtils/index.ts +11 -0
- package/focusManager/FocusManager.ts +20 -5
- package/focusManager/__tests__/FocusManager.test.ts +0 -1
- package/functionUtils/index.ts +38 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +121 -0
- package/manifestUtils/keys.js +2 -1
- package/navigationUtils/index.ts +1 -1
- package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +66 -0
- package/numberUtils/__tests__/toPositiveNumberWithDefaultZero.test.ts +66 -0
- package/numberUtils/index.ts +20 -0
- package/package.json +2 -2
- package/playerUtils/configurationGenerator.ts +120 -0
- package/reactHooks/cell-click/__tests__/index.test.js +3 -3
- package/reactHooks/cell-click/index.ts +17 -3
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +69 -6
- package/reactHooks/feed/useBatchLoading.ts +52 -28
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +134 -0
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -0
- package/reactHooks/navigation/index.ts +1 -1
- package/reactHooks/player/useAutoSeek.tsx +9 -7
- package/reactHooks/useConfiguration.ts +2 -2
- package/testUtils/index.tsx +42 -9
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { toPositiveNumberWithDefaultZero } from "..";
|
|
2
|
+
|
|
3
|
+
const DEFAULT = 0;
|
|
4
|
+
|
|
5
|
+
describe("toNumber", () => {
|
|
6
|
+
it("return number if input is positive number", () => {
|
|
7
|
+
const inputs = [0, 1, 2, 100, 200.12];
|
|
8
|
+
expect.assertions(inputs.length);
|
|
9
|
+
|
|
10
|
+
inputs.forEach((input) => {
|
|
11
|
+
const output = toPositiveNumberWithDefaultZero(input);
|
|
12
|
+
expect(output).toBe(input);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("return number if input is positive number as string", () => {
|
|
17
|
+
const inputs = ["0", "1", "2", "100", "200.12"];
|
|
18
|
+
expect.assertions(inputs.length);
|
|
19
|
+
|
|
20
|
+
inputs.forEach((input) => {
|
|
21
|
+
const output = toPositiveNumberWithDefaultZero(input);
|
|
22
|
+
expect(output).toBe(Number(input));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("return default number if input is negative number", () => {
|
|
27
|
+
const inputs = [-1, -2, -100];
|
|
28
|
+
expect.assertions(inputs.length);
|
|
29
|
+
|
|
30
|
+
inputs.forEach((input) => {
|
|
31
|
+
const output = toPositiveNumberWithDefaultZero(input);
|
|
32
|
+
expect(output).toBe(DEFAULT);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("return default number if input is negative number as string", () => {
|
|
37
|
+
const inputs = ["-1", "-2", "-100"];
|
|
38
|
+
expect.assertions(inputs.length);
|
|
39
|
+
|
|
40
|
+
inputs.forEach((input) => {
|
|
41
|
+
const output = toPositiveNumberWithDefaultZero(input);
|
|
42
|
+
expect(output).toBe(DEFAULT);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("return default if input is not a number or infinite", () => {
|
|
47
|
+
const inputs = [
|
|
48
|
+
"vfdvf",
|
|
49
|
+
null,
|
|
50
|
+
undefined,
|
|
51
|
+
NaN,
|
|
52
|
+
"",
|
|
53
|
+
{},
|
|
54
|
+
{ test: 1 },
|
|
55
|
+
[],
|
|
56
|
+
[1],
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
expect.assertions(inputs.length);
|
|
60
|
+
|
|
61
|
+
inputs.forEach((input) => {
|
|
62
|
+
const output = toPositiveNumberWithDefaultZero(input);
|
|
63
|
+
expect(output).toBe(DEFAULT);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
package/numberUtils/index.ts
CHANGED
|
@@ -66,3 +66,23 @@ export const isZero = (value: unknown): boolean =>
|
|
|
66
66
|
export const isMinusZero = (value: number) => {
|
|
67
67
|
return 1 / value === -Infinity;
|
|
68
68
|
};
|
|
69
|
+
|
|
70
|
+
export const toPositiveNumberWithDefault = (
|
|
71
|
+
defaultValue: number,
|
|
72
|
+
value: unknown
|
|
73
|
+
): number => {
|
|
74
|
+
const possibleNumber = toNumber(value);
|
|
75
|
+
|
|
76
|
+
if (R.isNil(possibleNumber)) {
|
|
77
|
+
return defaultValue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (possibleNumber < 0) {
|
|
81
|
+
return defaultValue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return possibleNumber;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const toPositiveNumberWithDefaultZero = (value: unknown): number =>
|
|
88
|
+
toPositiveNumberWithDefault(0, value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-alpha.
|
|
3
|
+
"version": "12.0.0-alpha.4173603919",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "12.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-alpha.4173603919",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -1798,6 +1798,30 @@ function getPlayerConfiguration({ platform }) {
|
|
|
1798
1798
|
key: "menu_header_samsung_letter_spacing",
|
|
1799
1799
|
initial_value: 0,
|
|
1800
1800
|
},
|
|
1801
|
+
{
|
|
1802
|
+
type: "vizio_font_selector",
|
|
1803
|
+
label: "Vizio Font Family",
|
|
1804
|
+
key: "menu_header_vizio_font_family",
|
|
1805
|
+
initial_value: "Ubuntu-Bold",
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
type: "number_input",
|
|
1809
|
+
label: "Vizio Font Size",
|
|
1810
|
+
key: "menu_header_vizio_font_size",
|
|
1811
|
+
initial_value: 30,
|
|
1812
|
+
},
|
|
1813
|
+
{
|
|
1814
|
+
type: "number_input",
|
|
1815
|
+
label: "Vizio Line Height",
|
|
1816
|
+
key: "menu_header_vizio_line_height",
|
|
1817
|
+
initial_value: 60,
|
|
1818
|
+
},
|
|
1819
|
+
{
|
|
1820
|
+
type: "number_input",
|
|
1821
|
+
label: "Vizio Letter Spacing",
|
|
1822
|
+
key: "menu_header_vizio_letter_spacing",
|
|
1823
|
+
initial_value: 0,
|
|
1824
|
+
},
|
|
1801
1825
|
]
|
|
1802
1826
|
),
|
|
1803
1827
|
// Captions Menu - Item Text Label
|
|
@@ -1877,6 +1901,30 @@ function getPlayerConfiguration({ platform }) {
|
|
|
1877
1901
|
key: "menu_item_samsung_letter_spacing",
|
|
1878
1902
|
initial_value: 0,
|
|
1879
1903
|
},
|
|
1904
|
+
{
|
|
1905
|
+
type: "vizio_font_selector",
|
|
1906
|
+
label: "Vizio Font Family",
|
|
1907
|
+
key: "menu_item_vizio_font_family",
|
|
1908
|
+
initial_value: "Ubuntu-Medium",
|
|
1909
|
+
},
|
|
1910
|
+
{
|
|
1911
|
+
type: "number_input",
|
|
1912
|
+
label: "Vizio Font Size",
|
|
1913
|
+
key: "menu_item_vizio_font_size",
|
|
1914
|
+
initial_value: 25,
|
|
1915
|
+
},
|
|
1916
|
+
{
|
|
1917
|
+
type: "number_input",
|
|
1918
|
+
label: "Vizio Line Height",
|
|
1919
|
+
key: "menu_item_vizio_line_height",
|
|
1920
|
+
initial_value: 40,
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
type: "number_input",
|
|
1924
|
+
label: "Vizio Letter Spacing",
|
|
1925
|
+
key: "menu_item_vizio_letter_spacing",
|
|
1926
|
+
initial_value: 0,
|
|
1927
|
+
},
|
|
1880
1928
|
]
|
|
1881
1929
|
),
|
|
1882
1930
|
// Captions Menu - Item Border
|
|
@@ -2020,6 +2068,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2020
2068
|
key: "samsung_tv_video_player_title_font_size",
|
|
2021
2069
|
initial_value: 58,
|
|
2022
2070
|
},
|
|
2071
|
+
{
|
|
2072
|
+
type: "vizio_font_selector",
|
|
2073
|
+
label: "Vizio Font Family",
|
|
2074
|
+
key: "vizio_video_player_title_font_family",
|
|
2075
|
+
initial_value: "Ubuntu-Bold",
|
|
2076
|
+
},
|
|
2077
|
+
{
|
|
2078
|
+
type: "number_input",
|
|
2079
|
+
label: "Vizio Font Size",
|
|
2080
|
+
key: "vizio_video_player_title_font_size",
|
|
2081
|
+
initial_value: 58,
|
|
2082
|
+
},
|
|
2023
2083
|
{
|
|
2024
2084
|
type: "tvos_font_selector",
|
|
2025
2085
|
label: "tvOS Font Family",
|
|
@@ -2093,6 +2153,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2093
2153
|
key: "samsung_tv_video_player_summary_font_size",
|
|
2094
2154
|
initial_value: 30,
|
|
2095
2155
|
},
|
|
2156
|
+
{
|
|
2157
|
+
type: "vizio_font_selector",
|
|
2158
|
+
label: "Vizio Font Family",
|
|
2159
|
+
key: "vizio_video_player_summary_font_family",
|
|
2160
|
+
initial_value: "Ubuntu-Medium",
|
|
2161
|
+
},
|
|
2162
|
+
{
|
|
2163
|
+
type: "number_input",
|
|
2164
|
+
label: "Vizio Font Size",
|
|
2165
|
+
key: "vizio_video_player_summary_font_size",
|
|
2166
|
+
initial_value: 30,
|
|
2167
|
+
},
|
|
2096
2168
|
{
|
|
2097
2169
|
type: "tvos_font_selector",
|
|
2098
2170
|
label: "tvOS Font Family",
|
|
@@ -2160,6 +2232,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2160
2232
|
key: "samsung_tv_audio_player_title_font_size",
|
|
2161
2233
|
initial_value: 40,
|
|
2162
2234
|
},
|
|
2235
|
+
{
|
|
2236
|
+
type: "vizio_font_selector",
|
|
2237
|
+
label: "Vizio Font Family",
|
|
2238
|
+
key: "vizio_audio_player_title_font_family",
|
|
2239
|
+
initial_value: "Ubuntu-Bold",
|
|
2240
|
+
},
|
|
2241
|
+
{
|
|
2242
|
+
type: "number_input",
|
|
2243
|
+
label: "Vizio Font Size",
|
|
2244
|
+
key: "vizio_audio_player_title_font_size",
|
|
2245
|
+
initial_value: 40,
|
|
2246
|
+
},
|
|
2163
2247
|
{
|
|
2164
2248
|
type: "tvos_font_selector",
|
|
2165
2249
|
label: "tvOS Font Family",
|
|
@@ -2215,6 +2299,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2215
2299
|
key: "samsung_tv_audio_player_summary_font_size",
|
|
2216
2300
|
initial_value: 22,
|
|
2217
2301
|
},
|
|
2302
|
+
{
|
|
2303
|
+
type: "vizio_font_selector",
|
|
2304
|
+
label: "Vizio Font Family",
|
|
2305
|
+
key: "vizio_audio_player_summary_font_family",
|
|
2306
|
+
initial_value: "Ubuntu-Medium",
|
|
2307
|
+
},
|
|
2308
|
+
{
|
|
2309
|
+
type: "number_input",
|
|
2310
|
+
label: "Vizio Font Size",
|
|
2311
|
+
key: "vizio_audio_player_summary_font_size",
|
|
2312
|
+
initial_value: 22,
|
|
2313
|
+
},
|
|
2218
2314
|
{
|
|
2219
2315
|
type: "tvos_font_selector",
|
|
2220
2316
|
label: "tvOS Font Family",
|
|
@@ -2270,6 +2366,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2270
2366
|
key: "samsung_tv_player_time_font_size",
|
|
2271
2367
|
initial_value: 20,
|
|
2272
2368
|
},
|
|
2369
|
+
{
|
|
2370
|
+
type: "vizio_font_selector",
|
|
2371
|
+
label: "Vizio Font Family",
|
|
2372
|
+
key: "vizio_player_time_font_family",
|
|
2373
|
+
initial_value: "Ubuntu-Medium",
|
|
2374
|
+
},
|
|
2375
|
+
{
|
|
2376
|
+
type: "number_input",
|
|
2377
|
+
label: "Vizio Font Size",
|
|
2378
|
+
key: "vizio_player_time_font_size",
|
|
2379
|
+
initial_value: 20,
|
|
2380
|
+
},
|
|
2273
2381
|
{
|
|
2274
2382
|
type: "android_font_selector",
|
|
2275
2383
|
label: "Android TV Font Family",
|
|
@@ -2325,6 +2433,18 @@ function getPlayerConfiguration({ platform }) {
|
|
|
2325
2433
|
key: "samsung_tv_audio_player_run_time_font_size",
|
|
2326
2434
|
initial_value: 20,
|
|
2327
2435
|
},
|
|
2436
|
+
{
|
|
2437
|
+
type: "vizio_font_selector",
|
|
2438
|
+
label: "Vizio Font Family",
|
|
2439
|
+
key: "vizio_audio_player_run_time_font_family",
|
|
2440
|
+
initial_value: "Ubuntu-Medium",
|
|
2441
|
+
},
|
|
2442
|
+
{
|
|
2443
|
+
type: "number_input",
|
|
2444
|
+
label: "Vizio Font Size",
|
|
2445
|
+
key: "vizio_audio_player_run_time_font_size",
|
|
2446
|
+
initial_value: 20,
|
|
2447
|
+
},
|
|
2328
2448
|
{
|
|
2329
2449
|
type: "tvos_font_selector",
|
|
2330
2450
|
label: "tvOS Font Family",
|
|
@@ -60,13 +60,13 @@ const wrapper = ({ children }) => (
|
|
|
60
60
|
describe("useCellClick", () => {
|
|
61
61
|
it("returns a function", () => {
|
|
62
62
|
const { result } = renderHook(() => useCellClick(mockProps));
|
|
63
|
-
expect(typeof result.current).toBe("function");
|
|
63
|
+
expect(typeof result.current.current).toBe("function");
|
|
64
64
|
cleanup();
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it("runs default logic", () => {
|
|
68
68
|
const { result } = renderHook(() => useCellClick(mockProps));
|
|
69
|
-
const useCellClickHook = result.current;
|
|
69
|
+
const useCellClickHook = result.current.current;
|
|
70
70
|
|
|
71
71
|
useCellClickHook();
|
|
72
72
|
|
|
@@ -76,7 +76,7 @@ describe("useCellClick", () => {
|
|
|
76
76
|
|
|
77
77
|
it("runs onCellTap", async () => {
|
|
78
78
|
const { result } = renderHook(() => useCellClick(mockProps), { wrapper });
|
|
79
|
-
const useCellClickHook = result.current;
|
|
79
|
+
const useCellClickHook = result.current.current;
|
|
80
80
|
|
|
81
81
|
useCellClickHook();
|
|
82
82
|
|
|
@@ -30,7 +30,15 @@ type Props = {
|
|
|
30
30
|
zappPipesData?: ZappPipesData;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
type onPressReturnFn =
|
|
34
|
+
| ((_item?: ZappEntry | any, _index?: number) => Promise<void>)
|
|
35
|
+
| (() => void);
|
|
36
|
+
|
|
37
|
+
export const useCellClick = ({
|
|
38
|
+
component,
|
|
39
|
+
zappPipesData,
|
|
40
|
+
item,
|
|
41
|
+
}: Props): React.MutableRefObject<onPressReturnFn> => {
|
|
34
42
|
const { push, currentRoute } = useNavigation();
|
|
35
43
|
const { pathname } = useRoute();
|
|
36
44
|
|
|
@@ -106,9 +114,15 @@ export const useCellClick = ({ component, zappPipesData, item }: Props) => {
|
|
|
106
114
|
]
|
|
107
115
|
);
|
|
108
116
|
|
|
117
|
+
const onPressRef = React.useRef<onPressReturnFn>();
|
|
118
|
+
|
|
109
119
|
if (!cellSelectable) {
|
|
110
|
-
|
|
120
|
+
// update ref with dummy function
|
|
121
|
+
onPressRef.current = noop;
|
|
122
|
+
} else {
|
|
123
|
+
// update ref with the latest onPress function
|
|
124
|
+
onPressRef.current = onPress;
|
|
111
125
|
}
|
|
112
126
|
|
|
113
|
-
return
|
|
127
|
+
return onPressRef;
|
|
114
128
|
};
|
|
@@ -77,8 +77,6 @@ describe("useBatchLoading", () => {
|
|
|
77
77
|
|
|
78
78
|
const actions = store.getActions();
|
|
79
79
|
|
|
80
|
-
expect(useDispatchSpy).toBeCalledTimes(1);
|
|
81
|
-
|
|
82
80
|
expect(actions).toHaveLength(2);
|
|
83
81
|
|
|
84
82
|
expect(actions[0]).toMatchObject({
|
|
@@ -129,6 +127,8 @@ describe("useBatchLoading", () => {
|
|
|
129
127
|
// ... more items
|
|
130
128
|
];
|
|
131
129
|
|
|
130
|
+
expect(useDispatchSpy).toBeCalledTimes(0);
|
|
131
|
+
|
|
132
132
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
133
133
|
wrapper,
|
|
134
134
|
initialProps: { store },
|
|
@@ -136,8 +136,6 @@ describe("useBatchLoading", () => {
|
|
|
136
136
|
|
|
137
137
|
const actions = store.getActions();
|
|
138
138
|
|
|
139
|
-
expect(useDispatchSpy).toBeCalledTimes(1);
|
|
140
|
-
|
|
141
139
|
expect(actions).toHaveLength(1);
|
|
142
140
|
|
|
143
141
|
expect(actions[0]).toMatchObject({
|
|
@@ -172,8 +170,6 @@ describe("useBatchLoading", () => {
|
|
|
172
170
|
initialProps: { store },
|
|
173
171
|
});
|
|
174
172
|
|
|
175
|
-
expect(useDispatchSpy).toBeCalledTimes(1);
|
|
176
|
-
|
|
177
173
|
const actions = store.getActions();
|
|
178
174
|
|
|
179
175
|
expect(actions).toHaveLength(3);
|
|
@@ -218,6 +214,73 @@ describe("useBatchLoading", () => {
|
|
|
218
214
|
|
|
219
215
|
expect(result.current).toBe(true);
|
|
220
216
|
});
|
|
217
|
+
|
|
218
|
+
it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
|
|
219
|
+
const store = mockStore({
|
|
220
|
+
zappPipes: {},
|
|
221
|
+
test: "true",
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
225
|
+
|
|
226
|
+
const initialBatchSize = 3;
|
|
227
|
+
const riverId = "123";
|
|
228
|
+
|
|
229
|
+
const data = [
|
|
230
|
+
{
|
|
231
|
+
component_type: "gallery-qb",
|
|
232
|
+
ui_components: [{ data: { source: "url1" } }],
|
|
233
|
+
},
|
|
234
|
+
{ data: { source: "url2" } },
|
|
235
|
+
{ data: { source: "url3" } },
|
|
236
|
+
{ data: { source: "url4" } },
|
|
237
|
+
{ data: { source: "url5" } },
|
|
238
|
+
{ data: { source: "url6" } },
|
|
239
|
+
// ... more items
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
243
|
+
wrapper,
|
|
244
|
+
initialProps: { store },
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const actions = store.getActions();
|
|
248
|
+
|
|
249
|
+
expect(actions).toHaveLength(1);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("gallery-qb: initial batch ready when all initial items loaded", () => {
|
|
253
|
+
const store = mockStore({
|
|
254
|
+
zappPipes: {
|
|
255
|
+
url1: {
|
|
256
|
+
loading: false,
|
|
257
|
+
error: false,
|
|
258
|
+
data: {},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
264
|
+
|
|
265
|
+
const initialBatchSize = 3;
|
|
266
|
+
const riverId = "123";
|
|
267
|
+
|
|
268
|
+
const data: Partial<ZappUIComponent>[] = [
|
|
269
|
+
{
|
|
270
|
+
component_type: "gallery-qb",
|
|
271
|
+
ui_components: [{ data: { source: "url1" } }],
|
|
272
|
+
},
|
|
273
|
+
{ data: { source: "url2" } },
|
|
274
|
+
{ data: { source: "url3" } },
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
const { result } = renderHook(
|
|
278
|
+
() => useBatchLoading(data, { initialBatchSize, riverId }),
|
|
279
|
+
{ wrapper, initialProps: { store } }
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
expect(result.current).toBe(true);
|
|
283
|
+
});
|
|
221
284
|
});
|
|
222
285
|
|
|
223
286
|
describe("allFeedsIsReady", () => {
|
|
@@ -45,19 +45,23 @@ const filterEmptyData = (data) => {
|
|
|
45
45
|
return true;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const getData = (rawData) =>
|
|
49
|
+
rawData.component_type === "gallery-qb"
|
|
50
|
+
? rawData.ui_components[0].data
|
|
51
|
+
: rawData.data;
|
|
52
|
+
|
|
53
|
+
const extractData = compose(uniq, map(getData));
|
|
49
54
|
|
|
50
55
|
export const allFeedsIsReady = (
|
|
51
56
|
feeds: ZappPipesCollection,
|
|
52
57
|
urls: (ZappDataSourceSource | null)[]
|
|
53
58
|
): boolean =>
|
|
54
|
-
urls
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.every(Boolean);
|
|
59
|
+
urls.every((url) =>
|
|
60
|
+
isNil(url) ? true : url && feeds[url] ? checkFeedIsReady(feeds[url]) : false
|
|
61
|
+
);
|
|
58
62
|
|
|
59
63
|
export const useBatchLoading = (
|
|
60
|
-
|
|
64
|
+
componentsToRender: { data?: ZappDataSource; component_type: string }[],
|
|
61
65
|
options: Options
|
|
62
66
|
) => {
|
|
63
67
|
const dispatch = useDispatch();
|
|
@@ -65,10 +69,18 @@ export const useBatchLoading = (
|
|
|
65
69
|
const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
|
|
66
70
|
const [hasEverBeenReady, setHasEverBeenReady] = React.useState(false);
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
// if first component is gallery-qb, take only one component for initial load
|
|
73
|
+
const takeSize =
|
|
74
|
+
componentsToRender?.[0]?.component_type === "gallery-qb"
|
|
75
|
+
? 1
|
|
76
|
+
: min(
|
|
77
|
+
options.initialBatchSize ?? DEFAULT_BATCH_SIZE,
|
|
78
|
+
componentsToRender.length
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const takeBatchSize = React.useCallback(take(takeSize), [takeSize]);
|
|
71
82
|
|
|
83
|
+
// Prepare inflated url for datasource
|
|
72
84
|
const getUrl = React.useCallback(
|
|
73
85
|
(data) => {
|
|
74
86
|
const mappedFeed = data.mapping
|
|
@@ -88,13 +100,16 @@ export const useBatchLoading = (
|
|
|
88
100
|
[entryContext, screenContext, searchContext]
|
|
89
101
|
);
|
|
90
102
|
|
|
91
|
-
|
|
103
|
+
// components for initial load
|
|
104
|
+
const batchComponents = takeBatchSize(componentsToRender);
|
|
92
105
|
|
|
106
|
+
// contains datasources from batch components loading
|
|
93
107
|
const feedData: ZappDataSource[] = React.useMemo(
|
|
94
|
-
() => extractData(
|
|
95
|
-
[
|
|
108
|
+
() => extractData(batchComponents).filter(filterEmptyData),
|
|
109
|
+
[batchComponents]
|
|
96
110
|
);
|
|
97
111
|
|
|
112
|
+
// contains inflated urls from batch components loading
|
|
98
113
|
const feedUrls: ZappDataSourceSource[] = React.useMemo(
|
|
99
114
|
() =>
|
|
100
115
|
feedData.map((data) => {
|
|
@@ -102,34 +117,43 @@ export const useBatchLoading = (
|
|
|
102
117
|
|
|
103
118
|
return mappedFeedUrl;
|
|
104
119
|
}),
|
|
105
|
-
[]
|
|
120
|
+
[]
|
|
106
121
|
);
|
|
107
122
|
|
|
108
123
|
const feeds = useZappPipesFeeds(feedUrls);
|
|
109
124
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.
|
|
114
|
-
const feed = feeds[data.source];
|
|
125
|
+
// dispatch loadPipesData for each feed that is not loaded
|
|
126
|
+
const runBatchLoading = React.useCallback(() => {
|
|
127
|
+
batchComponents.forEach((rawData: any) => {
|
|
128
|
+
// 1. get data (dataOf)
|
|
115
129
|
|
|
116
|
-
|
|
130
|
+
const data = getData(rawData);
|
|
117
131
|
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
// 2. filter out empty data filterEmptyData
|
|
133
|
+
if (!filterEmptyData(data)) return false;
|
|
120
134
|
|
|
121
|
-
|
|
122
|
-
const
|
|
135
|
+
// 3. filter out data that is already loaded (feeds[data.source]) & !feedHasData(feed) && !feedIsLoading(feed);
|
|
136
|
+
const feed = feeds[data?.source];
|
|
123
137
|
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
138
|
+
if (!feed || (!feedHasData(feed) && !feedIsLoading(feed))) {
|
|
139
|
+
const mappedFeedUrl = getUrl(data);
|
|
140
|
+
|
|
141
|
+
if (mappedFeedUrl) {
|
|
142
|
+
// 4. load data
|
|
143
|
+
return dispatch(
|
|
144
|
+
loadPipesData(mappedFeedUrl, { riverId: options.riverId })
|
|
145
|
+
);
|
|
146
|
+
}
|
|
128
147
|
}
|
|
129
148
|
});
|
|
130
|
-
}, []);
|
|
149
|
+
}, [feedUrls]);
|
|
150
|
+
|
|
151
|
+
React.useEffect(() => {
|
|
152
|
+
runBatchLoading();
|
|
153
|
+
}, []);
|
|
131
154
|
|
|
132
155
|
React.useEffect(() => {
|
|
156
|
+
// check if all feeds are ready and set hasEverBeenReady to true
|
|
133
157
|
if (allFeedsIsReady(feeds, feedUrls) && !hasEverBeenReady) {
|
|
134
158
|
setHasEverBeenReady(true);
|
|
135
159
|
}
|