@applicaster/zapp-react-native-utils 13.0.0-rc.83 → 13.0.0-rc.85

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.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
- import React, { createContext, useMemo } from "react";
3
+ import React, { createContext, useEffect, useMemo } from "react";
4
4
  import {
5
5
  actionExecutor as _actionExecutor,
6
6
  ActionResult,
@@ -19,8 +19,15 @@ import {
19
19
  EntryResolver,
20
20
  resolveObjectValues,
21
21
  } from "../appUtils/contextKeysManager/contextResolver";
22
+ import { useNavigation } from "../reactHooks";
23
+ import { get } from "lodash";
22
24
 
23
- const { log_error, log_info } = createLogger({
25
+ import {
26
+ useContentTypes,
27
+ usePickFromState,
28
+ } from "@applicaster/zapp-react-native-redux/hooks";
29
+
30
+ export const { log_error, log_info, log_debug } = createLogger({
24
31
  subsystem: "ActionExecutorContext",
25
32
  category: "General",
26
33
  });
@@ -169,8 +176,29 @@ const prepareDefaultActions = (actionExecutor) => {
169
176
  action: ActionType,
170
177
  context?: Record<string, any>
171
178
  ): Promise<ActionResult> => {
179
+ if (!context) {
180
+ log_error(
181
+ "handleAction: localStorageToggleFlag action missing context"
182
+ );
183
+
184
+ return ActionResult.Error;
185
+ }
186
+
187
+ const entry = context?.entry as ZappEntry;
188
+
189
+ if (!entry) {
190
+ log_error(
191
+ "handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
192
+ );
193
+
194
+ return ActionResult.Error;
195
+ }
196
+
197
+ const tag = action.options?.selector
198
+ ? get(entry, action.options.selector)
199
+ : (entry.extensions?.tag ?? entry.id);
200
+
172
201
  const keyNamespace = action.options?.key;
173
- const tag = context?.entry?.extensions?.tag;
174
202
 
175
203
  if (keyNamespace && tag) {
176
204
  const multiSelectProvider =
@@ -211,6 +239,10 @@ export function withActionExecutor(Component) {
211
239
  prepareDefaultActions(_actionExecutor);
212
240
 
213
241
  return function ActionExecutorComponent(props: Props) {
242
+ const navigator = useNavigation();
243
+ const { rivers } = usePickFromState(["rivers"]);
244
+ const contentTypes = useContentTypes();
245
+
214
246
  const handlers = useMemo(() => {
215
247
  return {
216
248
  unregisterAction: _actionExecutor.unregisterAction,
@@ -221,6 +253,43 @@ export function withActionExecutor(Component) {
221
253
  };
222
254
  }, []);
223
255
 
256
+ useEffect(() => {
257
+ return _actionExecutor.registerAction(
258
+ "navigateToScreen",
259
+ async (action: ActionType, _context?: Record<string, any>) => {
260
+ const screenType = action.options?.typeMapping;
261
+
262
+ if (!screenType) {
263
+ log_error("navigateToScreen: typeMapping option is missing");
264
+
265
+ return ActionResult.Error;
266
+ }
267
+
268
+ const screenId = contentTypes?.[screenType]?.screen_id || null;
269
+
270
+ if (!screenId) {
271
+ log_error(
272
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`
273
+ );
274
+
275
+ return ActionResult.Error;
276
+ }
277
+
278
+ const river = rivers[screenId];
279
+
280
+ if (!river) {
281
+ log_error("navigateToScreen: can not resolve river");
282
+
283
+ return ActionResult.Error;
284
+ }
285
+
286
+ navigator.replace(river);
287
+
288
+ return ActionResult.Success;
289
+ }
290
+ );
291
+ }, [navigator, rivers, contentTypes]);
292
+
224
293
  return (
225
294
  <ActionExecutorContext.Provider value={handlers}>
226
295
  <Component {...props} />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-rc.83",
3
+ "version": "13.0.0-rc.85",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "13.0.0-rc.83",
30
+ "@applicaster/applicaster-types": "13.0.0-rc.85",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",