@cuemath/leap 2.8.62-aa1 → 2.8.62-rj-1
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/dist/features/chapters/lpar-chapter/block-section/sheet-item/rewards-n-actions/student-actions/student-actions.js +46 -45
- package/dist/features/chapters/lpar-chapter/block-section/sheet-item/rewards-n-actions/student-actions/student-actions.js.map +1 -1
- package/dist/features/chapters/lpar-chapter/block-section/sheet-item/rewards-n-actions/teacher-actions/teacher-actions.js +26 -25
- package/dist/features/chapters/lpar-chapter/block-section/sheet-item/rewards-n-actions/teacher-actions/teacher-actions.js.map +1 -1
- package/dist/features/circle-games/game-launcher/comps/carousel/carousel.js +51 -49
- package/dist/features/circle-games/game-launcher/comps/carousel/carousel.js.map +1 -1
- package/dist/features/circle-games/game-launcher/game-launcher.js +87 -90
- package/dist/features/circle-games/game-launcher/game-launcher.js.map +1 -1
- package/dist/features/circle-games/game-launcher/hooks/use-game-launcher-journey/use-game-launcher-journey.js +83 -82
- package/dist/features/circle-games/game-launcher/hooks/use-game-launcher-journey/use-game-launcher-journey.js.map +1 -1
- package/dist/features/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.js +117 -116
- package/dist/features/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.js.map +1 -1
- package/dist/features/circle-games/games/web-view/web-view-types.js.map +1 -1
- package/dist/features/circle-games/games/web-view/web-view.js +53 -47
- package/dist/features/circle-games/games/web-view/web-view.js.map +1 -1
- package/dist/features/cue-canvas/cue-canvas-provider.js +8 -9
- package/dist/features/cue-canvas/cue-canvas-provider.js.map +1 -1
- package/dist/features/journey/hooks/use-get-eligible-journeys-via-route.js +7 -4
- package/dist/features/journey/hooks/use-get-eligible-journeys-via-route.js.map +1 -1
- package/dist/features/journey/use-journey/journey-context-provider.js +73 -69
- package/dist/features/journey/use-journey/journey-context-provider.js.map +1 -1
- package/dist/features/sheets/lessons-list/lesson-item/lesson-item-cta-info.js +60 -59
- package/dist/features/sheets/lessons-list/lesson-item/lesson-item-cta-info.js.map +1 -1
- package/dist/features/sheets/resources-list/resource-item/resource-item.js +90 -89
- package/dist/features/sheets/resources-list/resource-item/resource-item.js.map +1 -1
- package/dist/features/sheets/sheets-list/sheet-item/reward-n-actions/student-actions/student-actions.js +61 -60
- package/dist/features/sheets/sheets-list/sheet-item/reward-n-actions/student-actions/student-actions.js.map +1 -1
- package/dist/features/sheets/sheets-list/sheet-item/reward-n-actions/teacher-actions/teacher-actions.js +64 -63
- package/dist/features/sheets/sheets-list/sheet-item/reward-n-actions/teacher-actions/teacher-actions.js.map +1 -1
- package/dist/features/sheets/utils/is-v3-worksheet.js +14 -4
- package/dist/features/sheets/utils/is-v3-worksheet.js.map +1 -1
- package/dist/features/ui/section-list/section-list.js +12 -12
- package/dist/features/ui/section-list/section-list.js.map +1 -1
- package/dist/index.d.ts +14 -13
- package/dist/index.js +75 -74
- package/package.json +2 -4
- package/dist/library/polypad.js +0 -24965
- package/dist/library/polypad.js.map +0 -1
@@ -1,28 +1,28 @@
|
|
1
1
|
import { jsx as P } from "react/jsx-runtime";
|
2
|
-
import { forwardRef as
|
3
|
-
import { useUIContext as
|
4
|
-
import { ALLOWED_ORIGIN as
|
2
|
+
import { forwardRef as G, useRef as W, useMemo as _, useCallback as T, useImperativeHandle as V, useEffect as $ } from "react";
|
3
|
+
import { useUIContext as B } from "../../../ui/context/context.js";
|
4
|
+
import { ALLOWED_ORIGIN as N } from "./constants.js";
|
5
5
|
import { ProjectType as s } from "./enums/project-type-enum.js";
|
6
6
|
import { WebViewEvent as o } from "./enums/web-view-events-enum.js";
|
7
|
-
const
|
7
|
+
const F = G((C, I) => {
|
8
8
|
const {
|
9
|
-
baseUrl:
|
10
|
-
projectDetails:
|
11
|
-
playerDetails:
|
9
|
+
baseUrl: L,
|
10
|
+
projectDetails: y,
|
11
|
+
playerDetails: v,
|
12
12
|
onGameLoad: a,
|
13
|
-
onGamePlayFinish:
|
14
|
-
handleInfoMessage:
|
13
|
+
onGamePlayFinish: p,
|
14
|
+
handleInfoMessage: c,
|
15
15
|
onBack: f,
|
16
|
-
parentDomain:
|
17
|
-
...
|
18
|
-
} =
|
16
|
+
parentDomain: w,
|
17
|
+
...R
|
18
|
+
} = C, l = W(null), D = _(() => v, [v]), t = _(() => y, [y]);
|
19
19
|
let A = "";
|
20
|
-
const { onEvent: O } =
|
20
|
+
const { onEvent: O } = B();
|
21
21
|
t.projectType === s.LESSON && (A = t.miniGameIdentifier);
|
22
|
-
const m =
|
23
|
-
const { enableCloseButton:
|
22
|
+
const m = T(() => {
|
23
|
+
const { enableCloseButton: n = !0 } = t;
|
24
24
|
let e = {
|
25
|
-
enableCloseButton:
|
25
|
+
enableCloseButton: n
|
26
26
|
};
|
27
27
|
return t.projectType === s.GAME && (e = {
|
28
28
|
...e,
|
@@ -37,60 +37,66 @@ const Z = V((I, b) => {
|
|
37
37
|
...e,
|
38
38
|
...t
|
39
39
|
}), e;
|
40
|
-
}, [t]),
|
40
|
+
}, [t]), E = T(() => {
|
41
41
|
var e, r;
|
42
|
-
const
|
42
|
+
const n = m();
|
43
43
|
(r = (e = l.current) == null ? void 0 : e.contentWindow) == null || r.postMessage(
|
44
44
|
JSON.stringify({
|
45
45
|
event: o.GAME_DATA,
|
46
|
-
payload:
|
46
|
+
payload: n
|
47
47
|
}),
|
48
|
-
|
48
|
+
N
|
49
49
|
);
|
50
|
-
}, [m]),
|
50
|
+
}, [m]), g = T(() => {
|
51
51
|
var e, r;
|
52
|
-
const
|
52
|
+
const n = m();
|
53
53
|
(r = (e = l.current) == null ? void 0 : e.contentWindow) == null || r.postMessage(
|
54
54
|
JSON.stringify({
|
55
55
|
event: o.SET_CONFIG,
|
56
56
|
payload: {
|
57
|
-
user:
|
58
|
-
projectConfig:
|
59
|
-
parentDomain:
|
57
|
+
user: D,
|
58
|
+
projectConfig: n,
|
59
|
+
parentDomain: w
|
60
60
|
}
|
61
61
|
}),
|
62
|
-
|
62
|
+
N
|
63
63
|
);
|
64
|
-
}, [
|
65
|
-
|
66
|
-
const
|
67
|
-
var j,
|
68
|
-
const r = e.data,
|
69
|
-
if (
|
70
|
-
const { pattern: u } =
|
71
|
-
|
64
|
+
}, [D, m, w]);
|
65
|
+
return V(I, () => l.current, []), $(() => {
|
66
|
+
const n = (e) => {
|
67
|
+
var j, S;
|
68
|
+
const r = e.data, b = typeof r == "string" ? JSON.parse(r) : r, { event: i, payload: d = null } = b;
|
69
|
+
if (i === o.VIBRATE) {
|
70
|
+
const { pattern: u } = d;
|
71
|
+
(S = (j = window.navigator).vibrate) == null || S.call(j, u);
|
72
72
|
}
|
73
|
-
if (
|
74
|
-
const { eventName: u, properties:
|
75
|
-
O(u,
|
73
|
+
if (i === o.GAME_BACK && (f == null || f()), i === o.HIDE_LOADER && (a == null || a()), i === o.LOAD_DATA_FROM_APP && (E == null || E()), i === o.GET_CONFIG && g(), i === o.UPDATE_STATS && (p == null || p(d)), i === o.SHOW_SNACKBAR && (c == null || c(d)), i === o.TRACK_EVENT) {
|
74
|
+
const { eventName: u, properties: M } = d;
|
75
|
+
O(u, M);
|
76
76
|
}
|
77
77
|
};
|
78
|
-
return window.addEventListener("message",
|
79
|
-
window.removeEventListener("message",
|
78
|
+
return window.addEventListener("message", n), () => {
|
79
|
+
window.removeEventListener("message", n);
|
80
80
|
};
|
81
81
|
}, [
|
82
|
-
p,
|
83
|
-
f,
|
84
82
|
c,
|
83
|
+
f,
|
84
|
+
p,
|
85
85
|
a,
|
86
|
-
|
87
|
-
|
86
|
+
g,
|
87
|
+
E,
|
88
88
|
O
|
89
|
-
])
|
90
|
-
|
91
|
-
|
89
|
+
]), /* @__PURE__ */ P(
|
90
|
+
"iframe",
|
91
|
+
{
|
92
|
+
...R,
|
93
|
+
ref: l,
|
94
|
+
src: `${L}/play-game/${t.projectId}/${t.variant}${A ? `/${A}` : ""}?version=2`,
|
95
|
+
allow: "autoplay"
|
96
|
+
}
|
97
|
+
);
|
92
98
|
});
|
93
99
|
export {
|
94
|
-
|
100
|
+
F as WebView
|
95
101
|
};
|
96
102
|
//# sourceMappingURL=web-view.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"web-view.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view.tsx"],"sourcesContent":["
|
1
|
+
{"version":3,"file":"web-view.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view.tsx"],"sourcesContent":["import type {\n IInfoMessage,\n ILessonWebGameProps,\n IMessageProps,\n IMultiplayerWebGameProps,\n IPlayerStats,\n IPuzzleWebGameProps,\n ITableWebGameProps,\n IVibrationPattern,\n IWebViewProps,\n} from './web-view-types';\nimport type { ForwardedRef } from 'react';\n\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\n\nimport { useUIContext } from '../../../ui/context/context';\nimport { ALLOWED_ORIGIN } from './constants';\nimport { ProjectType, WebViewEvent } from './enums';\n\nexport const WebView = forwardRef((props: IWebViewProps, ref: ForwardedRef<HTMLIFrameElement>) => {\n const {\n baseUrl,\n projectDetails,\n playerDetails,\n onGameLoad,\n onGamePlayFinish,\n handleInfoMessage,\n onBack,\n parentDomain,\n ...rest\n } = props;\n const webViewRef = useRef<HTMLIFrameElement>(null);\n const memoizedPlayerDetails = useMemo(() => playerDetails, [playerDetails]);\n const memoizedProjectDetails = useMemo(() => projectDetails, [projectDetails]);\n\n let miniGameIdentifier = '';\n const { onEvent: trackEvent } = useUIContext();\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n miniGameIdentifier = (memoizedProjectDetails as ILessonWebGameProps).miniGameIdentifier;\n }\n\n const getProjectDetails = useCallback(() => {\n const { enableCloseButton = true } = memoizedProjectDetails;\n\n let payload = {\n enableCloseButton,\n } as IMultiplayerWebGameProps | IPuzzleWebGameProps | ILessonWebGameProps;\n\n if (memoizedProjectDetails.projectType === ProjectType.GAME) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IMultiplayerWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.PUZZLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as IPuzzleWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.LESSON) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ILessonWebGameProps;\n }\n\n if (memoizedProjectDetails.projectType === ProjectType.TABLE) {\n payload = {\n ...payload,\n ...memoizedProjectDetails,\n } as ITableWebGameProps;\n }\n\n return payload;\n }, [memoizedProjectDetails]);\n\n const sendGamesData = useCallback(() => {\n const payload = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.GAME_DATA,\n payload,\n }),\n ALLOWED_ORIGIN,\n );\n }, [getProjectDetails]);\n\n const setConfig = useCallback(() => {\n const projectConfig = getProjectDetails();\n\n webViewRef.current?.contentWindow?.postMessage(\n JSON.stringify({\n event: WebViewEvent.SET_CONFIG,\n payload: {\n user: memoizedPlayerDetails,\n projectConfig,\n parentDomain,\n },\n }),\n ALLOWED_ORIGIN,\n );\n }, [memoizedPlayerDetails, getProjectDetails, parentDomain]);\n\n useImperativeHandle(ref, () => webViewRef.current as HTMLIFrameElement, []);\n\n useEffect(() => {\n const handleMessage = (e: MessageEvent) => {\n const data: string = e.data;\n const parsedData = typeof data === 'string' ? JSON.parse(data) : (data as IMessageProps);\n\n const { event, payload = null } = parsedData;\n\n if (event === WebViewEvent.VIBRATE) {\n const { pattern } = payload as IVibrationPattern;\n\n window.navigator.vibrate?.(pattern);\n }\n\n if (event === WebViewEvent.GAME_BACK) {\n onBack?.();\n }\n\n if (event === WebViewEvent.HIDE_LOADER) {\n onGameLoad?.();\n }\n\n if (event === WebViewEvent.LOAD_DATA_FROM_APP) {\n sendGamesData?.();\n }\n\n if (event === WebViewEvent.GET_CONFIG) {\n setConfig();\n }\n\n if (event === WebViewEvent.UPDATE_STATS) {\n onGamePlayFinish?.(payload as IPlayerStats);\n }\n\n if (event === WebViewEvent.SHOW_SNACKBAR) {\n handleInfoMessage?.(payload as IInfoMessage);\n }\n\n if (event === WebViewEvent.TRACK_EVENT) {\n const { eventName, properties } = payload;\n\n trackEvent(eventName, properties);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n return () => {\n window.removeEventListener('message', handleMessage);\n };\n }, [\n handleInfoMessage,\n onBack,\n onGamePlayFinish,\n onGameLoad,\n setConfig,\n sendGamesData,\n trackEvent,\n ]);\n\n return (\n <iframe\n {...rest}\n ref={webViewRef}\n src={`${baseUrl}/play-game/${memoizedProjectDetails.projectId}/${\n memoizedProjectDetails.variant\n }${miniGameIdentifier ? `/${miniGameIdentifier}` : ''}?version=2`}\n allow=\"autoplay\"\n />\n );\n});\n"],"names":["WebView","forwardRef","props","ref","baseUrl","projectDetails","playerDetails","onGameLoad","onGamePlayFinish","handleInfoMessage","onBack","parentDomain","rest","webViewRef","useRef","memoizedPlayerDetails","useMemo","memoizedProjectDetails","miniGameIdentifier","trackEvent","useUIContext","ProjectType","getProjectDetails","useCallback","enableCloseButton","payload","sendGamesData","_b","_a","WebViewEvent","ALLOWED_ORIGIN","setConfig","projectConfig","useImperativeHandle","useEffect","handleMessage","data","parsedData","event","pattern","eventName","properties","jsx"],"mappings":";;;;;;AAmBO,MAAMA,IAAUC,EAAW,CAACC,GAAsBC,MAAyC;AAC1F,QAAA;AAAA,IACJ,SAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,YAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,QAAAC;AAAA,IACA,cAAAC;AAAA,IACA,GAAGC;AAAA,EACD,IAAAV,GACEW,IAAaC,EAA0B,IAAI,GAC3CC,IAAwBC,EAAQ,MAAMV,GAAe,CAACA,CAAa,CAAC,GACpEW,IAAyBD,EAAQ,MAAMX,GAAgB,CAACA,CAAc,CAAC;AAE7E,MAAIa,IAAqB;AACzB,QAAM,EAAE,SAASC,EAAW,IAAIC,EAAa;AAEzC,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AAM;AAAA,IAAA;AAAA,EAAA;AAGZ,CAAC;"}
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { jsx as d } from "react/jsx-runtime";
|
2
|
-
import "
|
3
|
-
import
|
4
|
-
import f from "./cue-canvas-context.js";
|
2
|
+
import { memo as f, useMemo as n, useState as o } from "react";
|
3
|
+
import p from "./cue-canvas-context.js";
|
5
4
|
import { getColorsForUser as x } from "./cue-canvas-helpers.js";
|
6
|
-
const A =
|
7
|
-
({ children:
|
8
|
-
const
|
5
|
+
const A = f(
|
6
|
+
({ children: a, userType: t }) => {
|
7
|
+
const i = n(() => x(t), [t]), [e, v] = o(), [r, m] = o("pen"), [s, l] = o(), [c, C] = o(i[0]), u = n(
|
9
8
|
() => ({
|
10
9
|
activeInstance: e,
|
11
10
|
setActiveInstance: v,
|
@@ -18,10 +17,10 @@ const A = p(
|
|
18
17
|
}),
|
19
18
|
[c, e, s, r]
|
20
19
|
);
|
21
|
-
return /* @__PURE__ */ d(
|
20
|
+
return /* @__PURE__ */ d(p.Provider, { value: u, children: a });
|
22
21
|
}
|
23
|
-
),
|
22
|
+
), g = A;
|
24
23
|
export {
|
25
|
-
|
24
|
+
g as default
|
26
25
|
};
|
27
26
|
//# sourceMappingURL=cue-canvas-provider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cue-canvas-provider.js","sources":["../../../src/features/cue-canvas/cue-canvas-provider.tsx"],"sourcesContent":["import type { TUserTypes } from '../ui/types';\nimport type { CueCanvasCore } from './cue-canvas-core';\nimport type { TCueCanvasColors, TCueCanvasSidebar, TCueCanvasTool } from './types/cue-canvas';\nimport '../../library/polypad';\nimport type { FC, PropsWithChildren } from 'react';\n\nimport { useState, memo, useMemo } from 'react';\n\nimport CueCanvasContext from './cue-canvas-context';\nimport { getColorsForUser } from './cue-canvas-helpers';\n\nconst CueCanvasProvider: FC<PropsWithChildren<{ userType: TUserTypes }>> = memo(\n ({ children, userType }) => {\n const colors = useMemo(() => getColorsForUser(userType), [userType]);\n\n const [activeInstance, setActiveInstance] = useState<CueCanvasCore>();\n const [activeTool, setActiveTool] = useState<TCueCanvasTool>('pen');\n const [activeSidebar, setActiveSidebar] = useState<TCueCanvasSidebar>();\n const [activeColor, setActiveColor] = useState<TCueCanvasColors>(colors[0] as TCueCanvasColors);\n const contextValue = useMemo(\n () => ({\n activeInstance: activeInstance,\n setActiveInstance: setActiveInstance,\n activeTool: activeTool,\n setActiveTool: setActiveTool,\n activeColor,\n setActiveColor,\n activeSidebar,\n setActiveSidebar,\n }),\n [activeColor, activeInstance, activeSidebar, activeTool],\n );\n\n return <CueCanvasContext.Provider value={contextValue}>{children}</CueCanvasContext.Provider>;\n },\n);\n\nexport default CueCanvasProvider;\n"],"names":["CueCanvasProvider","memo","children","userType","colors","useMemo","getColorsForUser","activeInstance","setActiveInstance","useState","activeTool","setActiveTool","activeSidebar","setActiveSidebar","activeColor","setActiveColor","contextValue","CueCanvasContext","CueCanvasProvider$1"],"mappings":"
|
1
|
+
{"version":3,"file":"cue-canvas-provider.js","sources":["../../../src/features/cue-canvas/cue-canvas-provider.tsx"],"sourcesContent":["import type { TUserTypes } from '../ui/types';\nimport type { CueCanvasCore } from './cue-canvas-core';\nimport type { TCueCanvasColors, TCueCanvasSidebar, TCueCanvasTool } from './types/cue-canvas';\nimport '../../library/polypad';\nimport type { FC, PropsWithChildren } from 'react';\n\nimport { useState, memo, useMemo } from 'react';\n\nimport CueCanvasContext from './cue-canvas-context';\nimport { getColorsForUser } from './cue-canvas-helpers';\n\nconst CueCanvasProvider: FC<PropsWithChildren<{ userType: TUserTypes }>> = memo(\n ({ children, userType }) => {\n const colors = useMemo(() => getColorsForUser(userType), [userType]);\n\n const [activeInstance, setActiveInstance] = useState<CueCanvasCore>();\n const [activeTool, setActiveTool] = useState<TCueCanvasTool>('pen');\n const [activeSidebar, setActiveSidebar] = useState<TCueCanvasSidebar>();\n const [activeColor, setActiveColor] = useState<TCueCanvasColors>(colors[0] as TCueCanvasColors);\n const contextValue = useMemo(\n () => ({\n activeInstance: activeInstance,\n setActiveInstance: setActiveInstance,\n activeTool: activeTool,\n setActiveTool: setActiveTool,\n activeColor,\n setActiveColor,\n activeSidebar,\n setActiveSidebar,\n }),\n [activeColor, activeInstance, activeSidebar, activeTool],\n );\n\n return <CueCanvasContext.Provider value={contextValue}>{children}</CueCanvasContext.Provider>;\n },\n);\n\nexport default CueCanvasProvider;\n"],"names":["CueCanvasProvider","memo","children","userType","colors","useMemo","getColorsForUser","activeInstance","setActiveInstance","useState","activeTool","setActiveTool","activeSidebar","setActiveSidebar","activeColor","setActiveColor","contextValue","CueCanvasContext","CueCanvasProvider$1"],"mappings":";;;;AAWA,MAAMA,IAAqEC;AAAA,EACzE,CAAC,EAAE,UAAAC,GAAU,UAAAC,QAAe;AACpB,UAAAC,IAASC,EAAQ,MAAMC,EAAiBH,CAAQ,GAAG,CAACA,CAAQ,CAAC,GAE7D,CAACI,GAAgBC,CAAiB,IAAIC,EAAwB,GAC9D,CAACC,GAAYC,CAAa,IAAIF,EAAyB,KAAK,GAC5D,CAACG,GAAeC,CAAgB,IAAIJ,EAA4B,GAChE,CAACK,GAAaC,CAAc,IAAIN,EAA2BL,EAAO,CAAC,CAAqB,GACxFY,IAAeX;AAAA,MACnB,OAAO;AAAA,QACL,gBAAAE;AAAA,QACA,mBAAAC;AAAA,QACA,YAAAE;AAAA,QACA,eAAAC;AAAA,QACA,aAAAG;AAAA,QACA,gBAAAC;AAAA,QACA,eAAAH;AAAA,QACA,kBAAAC;AAAA,MAAA;AAAA,MAEF,CAACC,GAAaP,GAAgBK,GAAeF,CAAU;AAAA,IAAA;AAGzD,6BAAQO,EAAiB,UAAjB,EAA0B,OAAOD,GAAe,UAAAd,EAAS,CAAA;AAAA,EACnE;AACF,GAEAgB,IAAelB;"}
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import { useMemo as i } from "react";
|
2
2
|
import { useJourney as s } from "../use-journey/use-journey.js";
|
3
|
-
const
|
4
|
-
const { userCompletedJourneyIds:
|
5
|
-
return i(
|
3
|
+
const n = (e) => {
|
4
|
+
const { userCompletedJourneyIds: o } = s();
|
5
|
+
return i(
|
6
|
+
() => e.filter((r) => !o.includes(r)),
|
7
|
+
[e, o]
|
8
|
+
);
|
6
9
|
};
|
7
10
|
export {
|
8
|
-
|
11
|
+
n as useGetEligibleJourneysViaRoute
|
9
12
|
};
|
10
13
|
//# sourceMappingURL=use-get-eligible-journeys-via-route.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-get-eligible-journeys-via-route.js","sources":["../../../../src/features/journey/hooks/use-get-eligible-journeys-via-route.tsx"],"sourcesContent":["import type { TJourneyId } from '../journey-id/journey-id-types';\n\nimport { useMemo } from 'react';\n\nimport { useJourney } from '../use-journey/use-journey';\n\nexport const useGetEligibleJourneysViaRoute = (routeJourneyIds: TJourneyId[]) => {\n const { userCompletedJourneyIds } = useJourney();\n\n const eligibleJourneys = useMemo(
|
1
|
+
{"version":3,"file":"use-get-eligible-journeys-via-route.js","sources":["../../../../src/features/journey/hooks/use-get-eligible-journeys-via-route.tsx"],"sourcesContent":["import type { TJourneyId } from '../journey-id/journey-id-types';\n\nimport { useMemo } from 'react';\n\nimport { useJourney } from '../use-journey/use-journey';\n\nexport const useGetEligibleJourneysViaRoute = (routeJourneyIds: TJourneyId[]) => {\n const { userCompletedJourneyIds } = useJourney();\n\n const eligibleJourneys = useMemo(\n () => routeJourneyIds.filter(journeyId => !userCompletedJourneyIds.includes(journeyId)),\n [routeJourneyIds, userCompletedJourneyIds],\n );\n\n return eligibleJourneys;\n};\n"],"names":["useGetEligibleJourneysViaRoute","routeJourneyIds","userCompletedJourneyIds","useJourney","useMemo","journeyId"],"mappings":";;AAMa,MAAAA,IAAiC,CAACC,MAAkC;AACzE,QAAA,EAAE,yBAAAC,MAA4BC;AAO7B,SALkBC;AAAA,IACvB,MAAMH,EAAgB,OAAO,CAAAI,MAAa,CAACH,EAAwB,SAASG,CAAS,CAAC;AAAA,IACtF,CAACJ,GAAiBC,CAAuB;AAAA,EAAA;AAI7C;"}
|
@@ -1,105 +1,109 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { createContext as
|
3
|
-
import { Coachmark as
|
4
|
-
import { usePostUserJourney as
|
5
|
-
import { Overlay as
|
6
|
-
const
|
7
|
-
const [
|
8
|
-
|
9
|
-
|
1
|
+
import { jsxs as b, jsx as j } from "react/jsx-runtime";
|
2
|
+
import { createContext as q, useState as d, useRef as C, useCallback as l, useMemo as L, useEffect as D } from "react";
|
3
|
+
import { Coachmark as N } from "../comps/coachmark/coachmark.js";
|
4
|
+
import { usePostUserJourney as M, useGetUserJourney as z } from "../user-journey-api/user-journey-api.js";
|
5
|
+
import { Overlay as G } from "./journey-styled.js";
|
6
|
+
const S = q(null), Q = ({ children: R, appId: u, userId: s }) => {
|
7
|
+
const [g, k] = d([]), [o, c] = d([]), [v, p] = d(!1), a = C(-1), r = C(), f = C([]), { post: x } = M(), {
|
8
|
+
data: y = null,
|
9
|
+
get: $,
|
10
|
+
isProcessing: T
|
11
|
+
} = z(), O = (u === "" || y && !T) && o.length > 0, _ = l(
|
12
|
+
(e, t) => {
|
13
|
+
if (console.log(`setJourney: Journey ID: ${e}`), o.length > 0) {
|
10
14
|
console.error(
|
11
|
-
`setJourney: Other Journey is already active, Current Journey: ${
|
15
|
+
`setJourney: Other Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}`
|
12
16
|
);
|
13
17
|
return;
|
14
18
|
}
|
15
|
-
|
19
|
+
console.log(`setJourney: Journey ID: ${e}`), p(!0), r.current = e, a.current = -1, c([...t]);
|
16
20
|
},
|
17
|
-
[
|
18
|
-
),
|
19
|
-
|
21
|
+
[o.length]
|
22
|
+
), m = l(() => {
|
23
|
+
f.current.forEach((e) => {
|
20
24
|
clearTimeout(e);
|
21
|
-
}),
|
22
|
-
}, []),
|
25
|
+
}), f.current = [], r.current = void 0, a.current = -1, c([]), p(!1);
|
26
|
+
}, []), A = l(
|
23
27
|
(e) => {
|
24
|
-
|
25
|
-
app_id:
|
26
|
-
user_id:
|
28
|
+
k((t) => [...t, e]), x({
|
29
|
+
app_id: u,
|
30
|
+
user_id: s,
|
27
31
|
journey_id: e,
|
28
32
|
journey_status: "COMPLETED"
|
29
|
-
});
|
33
|
+
}), m();
|
30
34
|
},
|
31
|
-
[
|
32
|
-
),
|
33
|
-
if (!
|
35
|
+
[u, m, x, s]
|
36
|
+
), P = l((e, t) => {
|
37
|
+
if (!r.current || e !== r.current) {
|
34
38
|
console.error(
|
35
|
-
|
39
|
+
r.current ? `A Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}` : "addCoachmark was called before setJourney and Journey ID is undefined"
|
36
40
|
);
|
37
41
|
return;
|
38
42
|
}
|
39
|
-
|
40
|
-
}, []),
|
41
|
-
(e,
|
42
|
-
if (!
|
43
|
+
c((J) => [...J, t]);
|
44
|
+
}, []), w = l(
|
45
|
+
(e, t = !1, J = 0) => {
|
46
|
+
if (!r.current || e !== r.current) {
|
43
47
|
console.error(
|
44
|
-
|
48
|
+
r.current ? "nextCoachmark was called before setJourney" : `A Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}`
|
45
49
|
);
|
46
50
|
return;
|
47
51
|
}
|
48
|
-
|
49
|
-
const
|
50
|
-
clearTimeout(
|
51
|
-
const n =
|
52
|
-
|
52
|
+
J !== 0 && c((n) => n.map((i) => ({ ...i, isActive: !1 })));
|
53
|
+
const E = setTimeout(() => {
|
54
|
+
clearTimeout(E);
|
55
|
+
const n = a.current + 1;
|
56
|
+
c((i) => {
|
53
57
|
if (n >= i.length || i.length === 0)
|
54
|
-
return
|
55
|
-
|
56
|
-
const
|
57
|
-
return
|
58
|
+
return r.current = void 0, a.current = -1, [];
|
59
|
+
a.current = n;
|
60
|
+
const h = [...i];
|
61
|
+
return h[n].isActive = !0, n > 0 && (h[n - 1].isActive = t), h;
|
58
62
|
});
|
59
|
-
},
|
60
|
-
|
63
|
+
}, J);
|
64
|
+
f.current.push(E);
|
61
65
|
},
|
62
|
-
[
|
63
|
-
),
|
66
|
+
[]
|
67
|
+
), U = L(
|
64
68
|
() => ({
|
65
|
-
nextCoachmark:
|
66
|
-
setJourney:
|
67
|
-
addCoachmark:
|
68
|
-
clearJourney:
|
69
|
-
endJourney:
|
70
|
-
coachmarks:
|
71
|
-
userCompletedJourneyIds:
|
72
|
-
isJourneyActive:
|
69
|
+
nextCoachmark: w,
|
70
|
+
setJourney: _,
|
71
|
+
addCoachmark: P,
|
72
|
+
clearJourney: m,
|
73
|
+
endJourney: A,
|
74
|
+
coachmarks: o,
|
75
|
+
userCompletedJourneyIds: g,
|
76
|
+
isJourneyActive: v
|
73
77
|
}),
|
74
78
|
[
|
79
|
+
w,
|
80
|
+
_,
|
75
81
|
P,
|
82
|
+
m,
|
76
83
|
A,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
c,
|
81
|
-
x,
|
82
|
-
J
|
84
|
+
o,
|
85
|
+
g,
|
86
|
+
v
|
83
87
|
]
|
84
88
|
);
|
85
|
-
return
|
86
|
-
|
87
|
-
app_id:
|
88
|
-
user_id:
|
89
|
+
return D(() => {
|
90
|
+
u && s && $(s, {
|
91
|
+
app_id: u,
|
92
|
+
user_id: s,
|
89
93
|
journey_status: "COMPLETED"
|
90
94
|
});
|
91
|
-
}, [
|
92
|
-
if (
|
93
|
-
const e =
|
94
|
-
|
95
|
+
}, [u, $, s]), D(() => {
|
96
|
+
if (y) {
|
97
|
+
const e = y.map((t) => t.journey_id);
|
98
|
+
k(e);
|
95
99
|
}
|
96
|
-
}, [
|
97
|
-
|
98
|
-
|
100
|
+
}, [y]), /* @__PURE__ */ b(S.Provider, { value: U, children: [
|
101
|
+
O && /* @__PURE__ */ j(G, { children: o.map((e, t) => /* @__PURE__ */ j(N, { coachmark: e }, `coachmark-${t}`)) }),
|
102
|
+
R
|
99
103
|
] });
|
100
104
|
};
|
101
105
|
export {
|
102
|
-
|
103
|
-
|
106
|
+
S as JourneyContext,
|
107
|
+
Q as JourneyProvider
|
104
108
|
};
|
105
109
|
//# sourceMappingURL=journey-context-provider.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"journey-context-provider.js","sources":["../../../../src/features/journey/use-journey/journey-context-provider.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { TJourneyId } from '../journey-id/journey-id-types';\nimport type {\n ICoachmarkProps,\n IJourneyContext,\n IJourneyProviderProps,\n} from './journey-context-types';\nimport type { FC } from 'react';\n\nimport { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { Coachmark } from '../comps/coachmark/coachmark';\nimport { useGetUserJourney, usePostUserJourney } from '../user-journey-api/user-journey-api';\nimport * as S from './journey-styled';\n\nexport const JourneyContext = createContext<IJourneyContext | null>(null);\n\nexport const JourneyProvider: FC<IJourneyProviderProps> = ({ children, appId, userId }) => {\n const [userCompletedJourneyIds, setUserCompletedJourneyIds] = useState<TJourneyId[] | null>(null);\n const [coachmarkList, setCoachmarkList] = useState<ICoachmarkProps[]>([]);\n const [isJourneyActive, setIsJourneyActive] = useState(false);\n const currentIndex = useRef(-1);\n const currentJourneyId = useRef<TJourneyId | undefined>();\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { post: postJourneyCompletion } = usePostUserJourney();\n const { data: userCompletedJourneys = null, get: getJourneyProgress } = useGetUserJourney();\n\n const setJourney = useCallback(\n (id: TJourneyId, coachmarks: ICoachmarkProps[]) => {\n if (coachmarkList.length > 0) {\n console.error(\n `setJourney: Other Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n setIsJourneyActive(true);\n currentJourneyId.current = id;\n currentIndex.current = -1;\n setCoachmarkList([...coachmarks]);\n },\n [coachmarkList.length],\n );\n\n const clearJourney = useCallback(() => {\n // Clear all timers\n timerRefs.current.forEach(timer => {\n clearTimeout(timer);\n });\n timerRefs.current = [];\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n setCoachmarkList([]);\n setIsJourneyActive(false);\n }, []);\n\n const endJourney = useCallback(\n (journeyId: TJourneyId) => {\n clearJourney();\n setUserCompletedJourneyIds(prev => {\n if (prev && !prev.includes(journeyId)) {\n return [...prev, journeyId];\n }\n\n return prev;\n });\n // fire the API (doesn’t block the UI)\n postJourneyCompletion({\n app_id: appId,\n user_id: userId,\n journey_id: journeyId,\n journey_status: 'COMPLETED',\n });\n },\n [appId, clearJourney, postJourneyCompletion, userId],\n );\n\n const addCoachmark = useCallback((id: TJourneyId, coachmark: ICoachmarkProps) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`\n : `addCoachmark was called before setJourney and Journey ID is undefined`,\n );\n\n return;\n }\n\n setCoachmarkList(prev => [...prev, coachmark]);\n }, []);\n\n const nextCoachmark = useCallback(\n (id: TJourneyId, keepPrevActive: boolean = false, delayInMs: number = 0) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `nextCoachmark was called before setJourney`\n : `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n\n if (delayInMs !== 0) {\n // If delay is not 0, we will hide all them coachmarks and reveal only after the delay\n setCoachmarkList(prevList => {\n return prevList.map((item: ICoachmarkProps) => {\n return { ...item, isActive: false };\n });\n });\n }\n\n const timer = setTimeout(() => {\n clearTimeout(timer);\n const currIndex = currentIndex.current + 1;\n\n setCoachmarkList(prevList => {\n // Finish onboarding\n if (currIndex >= prevList.length || prevList.length === 0) {\n clearJourney();\n\n return [];\n }\n\n currentIndex.current = currIndex;\n const updatedCoachmarkList = [...prevList];\n\n (updatedCoachmarkList[currIndex] as ICoachmarkProps).isActive = true;\n\n if (currIndex > 0) {\n (updatedCoachmarkList[currIndex - 1] as ICoachmarkProps).isActive = keepPrevActive;\n }\n\n return updatedCoachmarkList;\n });\n }, delayInMs);\n\n timerRefs.current.push(timer);\n },\n [clearJourney],\n );\n\n const memoizedContextValue: IJourneyContext = useMemo(\n () => ({\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarks: coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n }),\n [\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n ],\n );\n\n // Get the initial state of incompleteJourneys\n useEffect(() => {\n if (appId && userId) {\n getJourneyProgress(userId, {\n app_id: appId,\n user_id: userId,\n journey_status: 'COMPLETED',\n });\n }\n }, [appId, getJourneyProgress, userId]);\n\n // Set the data to context state initially\n useEffect(() => {\n if (userCompletedJourneys) {\n const completedUserJourneysIds = userCompletedJourneys.map(journey => journey.journey_id);\n\n setUserCompletedJourneyIds(completedUserJourneysIds);\n }\n }, [userCompletedJourneys]);\n\n return (\n <JourneyContext.Provider value={memoizedContextValue}>\n {isJourneyActive && (\n <S.Overlay about=\"journey-overlay\" data-testid={currentJourneyId.current}>\n {coachmarkList.map((coachmark, index) => (\n <Coachmark key={`coachmark-${index}`} coachmark={coachmark} />\n ))}\n </S.Overlay>\n )}\n {children}\n </JourneyContext.Provider>\n );\n};\n"],"names":["JourneyContext","createContext","JourneyProvider","children","appId","userId","userCompletedJourneyIds","setUserCompletedJourneyIds","useState","coachmarkList","setCoachmarkList","isJourneyActive","setIsJourneyActive","currentIndex","useRef","currentJourneyId","timerRefs","postJourneyCompletion","usePostUserJourney","userCompletedJourneys","getJourneyProgress","useGetUserJourney","setJourney","useCallback","id","coachmarks","clearJourney","timer","endJourney","journeyId","prev","addCoachmark","coachmark","nextCoachmark","keepPrevActive","delayInMs","prevList","item","currIndex","updatedCoachmarkList","memoizedContextValue","useMemo","useEffect","completedUserJourneysIds","journey","jsxs","jsx","S.Overlay","index","Coachmark"],"mappings":";;;;;AAea,MAAAA,IAAiBC,EAAsC,IAAI,GAE3DC,I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EAAA,GAGTc,IAAwCC;AAAA,IAC5C,OAAO;AAAA,MACL,eAAAR;AAAA,MACA,YAAAX;AAAA,MACA,cAAAS;AAAA,MACA,cAAAL;AAAA,MACA,YAAAE;AAAA,MACA,YAAYnB;AAAA,MACZ,yBAAAH;AAAA,MACA,iBAAAK;AAAA,IAAA;AAAA,IAEF;AAAA,MACEsB;AAAA,MACAX;AAAA,MACAS;AAAA,MACAL;AAAA,MACAE;AAAA,MACAnB;AAAA,MACAH;AAAA,MACAK;AAAA,IACF;AAAA,EAAA;AAIF,SAAA+B,EAAU,MAAM;AACd,IAAItC,KAASC,KACXe,EAAmBf,GAAQ;AAAA,MACzB,QAAQD;AAAA,MACR,SAASC;AAAA,MACT,gBAAgB;AAAA,IAAA,CACjB;AAAA,EAEF,GAAA,CAACD,GAAOgB,GAAoBf,CAAM,CAAC,GAGtCqC,EAAU,MAAM;AACd,QAAIvB,GAAuB;AACzB,YAAMwB,IAA2BxB,EAAsB,IAAI,CAAAyB,MAAWA,EAAQ,UAAU;AAExF,MAAArC,EAA2BoC,CAAwB;AAAA,IACrD;AAAA,EAAA,GACC,CAACxB,CAAqB,CAAC,GAGvB,gBAAA0B,EAAA7C,EAAe,UAAf,EAAwB,OAAOwC,GAC7B,UAAA;AAAA,IACC7B,KAAA,gBAAAmC,EAACC,GAAA,EAAU,OAAM,mBAAkB,eAAahC,EAAiB,SAC9D,UAAAN,EAAc,IAAI,CAACuB,GAAWgB,MAC5B,gBAAAF,EAAAG,GAAA,EAAqC,WAAAjB,KAAtB,aAAagB,CAAK,EAA0B,CAC7D,EACH,CAAA;AAAA,IAED7C;AAAA,EACH,EAAA,CAAA;AAEJ;"}
|
1
|
+
{"version":3,"file":"journey-context-provider.js","sources":["../../../../src/features/journey/use-journey/journey-context-provider.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { TJourneyId } from '../journey-id/journey-id-types';\nimport type {\n ICoachmarkProps,\n IJourneyContext,\n IJourneyProviderProps,\n} from './journey-context-types';\nimport type { FC } from 'react';\n\nimport { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { Coachmark } from '../comps/coachmark/coachmark';\nimport { useGetUserJourney, usePostUserJourney } from '../user-journey-api/user-journey-api';\nimport * as S from './journey-styled';\n\nexport const JourneyContext = createContext<IJourneyContext | null>(null);\n\nexport const JourneyProvider: FC<IJourneyProviderProps> = ({ children, appId, userId }) => {\n const [userCompletedJourneyIds, setUserCompletedJourneyIds] = useState<TJourneyId[]>([]);\n const [coachmarkList, setCoachmarkList] = useState<ICoachmarkProps[]>([]);\n const [isJourneyActive, setIsJourneyActive] = useState(false);\n const currentIndex = useRef(-1);\n const currentJourneyId = useRef<TJourneyId | undefined>();\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { post: postJourneyCompletion } = usePostUserJourney();\n const {\n data: userCompletedJourneys = null,\n get: getJourneyProgress,\n isProcessing,\n } = useGetUserJourney();\n\n const showCoachmarks =\n appId === '' // Otherwise coachmark stories wont work\n ? coachmarkList.length > 0\n : userCompletedJourneys && !isProcessing && coachmarkList.length > 0;\n\n const setJourney = useCallback(\n (id: TJourneyId, coachmarks: ICoachmarkProps[]) => {\n console.log(`setJourney: Journey ID: ${id}`);\n if (coachmarkList.length > 0) {\n console.error(\n `setJourney: Other Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n console.log(`setJourney: Journey ID: ${id}`);\n\n setIsJourneyActive(true);\n currentJourneyId.current = id;\n currentIndex.current = -1;\n setCoachmarkList([...coachmarks]);\n },\n [coachmarkList.length],\n );\n\n const clearJourney = useCallback(() => {\n // Clear all timers\n timerRefs.current.forEach(timer => {\n clearTimeout(timer);\n });\n timerRefs.current = [];\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n setCoachmarkList([]);\n setIsJourneyActive(false);\n }, []);\n\n const endJourney = useCallback(\n (journeyId: TJourneyId) => {\n setUserCompletedJourneyIds(prev => [...prev, journeyId]);\n postJourneyCompletion({\n app_id: appId,\n user_id: userId,\n journey_id: journeyId,\n journey_status: 'COMPLETED',\n });\n clearJourney();\n },\n [appId, clearJourney, postJourneyCompletion, userId],\n );\n\n const addCoachmark = useCallback((id: TJourneyId, coachmark: ICoachmarkProps) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`\n : `addCoachmark was called before setJourney and Journey ID is undefined`,\n );\n\n return;\n }\n\n setCoachmarkList(prev => [...prev, coachmark]);\n }, []);\n\n const nextCoachmark = useCallback(\n (id: TJourneyId, keepPrevActive: boolean = false, delayInMs: number = 0) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `nextCoachmark was called before setJourney`\n : `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n\n if (delayInMs !== 0) {\n // If delay is not 0, we will hide all them coachmarks and reveal only after the delay\n setCoachmarkList(prevList => {\n return prevList.map((item: ICoachmarkProps) => {\n return { ...item, isActive: false };\n });\n });\n }\n\n const timer = setTimeout(() => {\n clearTimeout(timer);\n const currIndex = currentIndex.current + 1;\n\n setCoachmarkList(prevList => {\n // Finish onboarding\n if (currIndex >= prevList.length || prevList.length === 0) {\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n\n return [];\n }\n\n currentIndex.current = currIndex;\n const updatedCoachmarkList = [...prevList];\n\n (updatedCoachmarkList[currIndex] as ICoachmarkProps).isActive = true;\n\n if (currIndex > 0) {\n (updatedCoachmarkList[currIndex - 1] as ICoachmarkProps).isActive = keepPrevActive;\n }\n\n return updatedCoachmarkList;\n });\n }, delayInMs);\n\n timerRefs.current.push(timer);\n },\n [],\n );\n\n const memoizedContextValue: IJourneyContext = useMemo(\n () => ({\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarks: coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n }),\n [\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n ],\n );\n\n // Get the initial state of incompleteJourneys\n useEffect(() => {\n if (appId && userId) {\n getJourneyProgress(userId, {\n app_id: appId,\n user_id: userId,\n journey_status: 'COMPLETED',\n });\n }\n }, [appId, getJourneyProgress, userId]);\n\n // Set the data to context state initially\n useEffect(() => {\n if (userCompletedJourneys) {\n const completedUserJourneysIds = userCompletedJourneys.map(journey => journey.journey_id);\n\n setUserCompletedJourneyIds(completedUserJourneysIds);\n }\n }, [userCompletedJourneys]);\n\n return (\n <JourneyContext.Provider value={memoizedContextValue}>\n {showCoachmarks && (\n <S.Overlay>\n {coachmarkList.map((coachmark, index) => (\n <Coachmark key={`coachmark-${index}`} coachmark={coachmark} />\n ))}\n </S.Overlay>\n )}\n {children}\n </JourneyContext.Provider>\n );\n};\n"],"names":["JourneyContext","createContext","JourneyProvider","children","appId","userId","userCompletedJourneyIds","setUserCompletedJourneyIds","useState","coachmarkList","setCoachmarkList","isJourneyActive","setIsJourneyActive","currentIndex","useRef","currentJourneyId","timerRefs","postJourneyCompletion","usePostUserJourney","userCompletedJourneys","getJourneyProgress","isProcessing","useGetUserJourney","showCoachmarks","setJourney","useCallback","id","coachmarks","clearJourney","timer","endJourney","journeyId","prev","addCoachmark","coachmark","nextCoachmark","keepPrevActive","delayInMs","prevList","item","currIndex","updatedCoachmarkList","memoizedContextValue","useMemo","useEffect","completedUserJourneysIds","journey","jsxs","S.Overlay","index","jsx","Coachmark"],"mappings":";;;;;AAea,MAAAA,IAAiBC,EAAsC,IAAI,GAE3DC,IAA6C,CAAC,EAAE,UAAAC,GAAU,OAAAC,GAAO,QAAAC,QAAa;AACzF,QAAM,CAACC,GAAyBC,CAA0B,IAAIC,EAAuB,CAAE,CAAA,GACjF,CAACC,GAAeC,CAAgB,IAAIF,EAA4B,CAAE,CAAA,GA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