@cuemath/leap 2.8.61-rj-8 → 2.8.61-rj-10
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/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.js +137 -126
- package/dist/features/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.js.map +1 -1
- package/dist/features/journey/use-journey/journey-context-provider.js +34 -32
- package/dist/features/journey/use-journey/journey-context-provider.js.map +1 -1
- package/package.json +1 -1
@@ -1,5 +1,5 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { useRef as A, useCallback as
|
1
|
+
import { jsx as r, Fragment as N } from "react/jsx-runtime";
|
2
|
+
import { useRef as A, useCallback as C, useEffect as V } from "react";
|
3
3
|
import X from "../../../../../assets/line-icons/icons/carat-right.js";
|
4
4
|
import { PLATFORM_EVENTS_STUDENT as G } from "../../../../analytics-events/platform-events-student.js";
|
5
5
|
import { JOURNEY_ID_STUDENT as K } from "../../../../journey/journey-id/journey-id-student.js";
|
@@ -7,203 +7,214 @@ import { IndicatorType as u } from "../../../../journey/use-journey/constants.js
|
|
7
7
|
import { useJourney as j } from "../../../../journey/use-journey/use-journey.js";
|
8
8
|
import Z from "../../../../ui/buttons/icon-button/icon-button.js";
|
9
9
|
import { useUIContext as q } from "../../../../ui/context/context.js";
|
10
|
-
import
|
10
|
+
import b from "../../../../ui/layout/flex-view.js";
|
11
11
|
import m from "../../../../ui/text/text.js";
|
12
12
|
import { CIRCLE_ONBOARDING_ANALYTICS_STEPS as v } from "../../../enum/circle-onboarding-steps.js";
|
13
13
|
import { useCircleSounds as z } from "../../../hooks/use-circle-sounds/use-circle-sounds.js";
|
14
|
-
import { TablesCard as
|
14
|
+
import { TablesCard as J } from "../../comps/tables-card/tables-card.js";
|
15
15
|
import { GAME_LAUNCHER_ANALYTICS_EVENTS as Q } from "../../game-launcher-analytics-events.js";
|
16
|
-
import { SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS as ee, SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS as te, START_ANIMATING_CLONED_ELEM as
|
16
|
+
import { SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS as ee, SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS as te, START_ANIMATING_CLONED_ELEM as M, TABLE_CARD_INDEX as $, GO_TO_TABLE_LAUNCHER_DURATION_MS as re, SHOW_CLICK_TABLE_NUDGE_AFTER_MS as ne, PUZZLE_CARD_INDEX as oe, SHOW_INITIAL_COACHMARK_AFTER_MS as x, LESSON_CARD_INDEX as ie, SHOW_INITIAL_TOOLTIP_AFTER_MS as le } from "./constants.js";
|
17
17
|
import { Indicator as ce } from "./use-table-launcher-journey-styled.js";
|
18
18
|
const Re = ({
|
19
19
|
carouselRefs: s,
|
20
|
-
onTableSegmentClick:
|
20
|
+
onTableSegmentClick: S
|
21
21
|
}) => {
|
22
|
-
const
|
23
|
-
(
|
24
|
-
var
|
25
|
-
|
22
|
+
const t = K.CIRCLE_TABLES_INTRO_JOURNEY, e = A(null), _ = A(null), I = A(!1), T = A([]), { playButtonSound: y } = z(), { nextCoachmark: c, setJourney: L, addCoachmark: d, endJourney: H } = j(), { onEvent: f } = q(), O = C(
|
23
|
+
(n) => {
|
24
|
+
var a, o;
|
25
|
+
n && S(n), f(G.ONBOARDING_STEP_COMPLETED, {
|
26
26
|
step: v.TABLES
|
27
|
-
}), (
|
27
|
+
}), (a = e == null ? void 0 : e.current) == null || a.setLabelVisiblity(!0), (o = e == null ? void 0 : e.current) == null || o.stopLabelAnimation(), H(t);
|
28
28
|
},
|
29
|
-
[
|
30
|
-
),
|
31
|
-
(
|
29
|
+
[H, t, S, f]
|
30
|
+
), P = C(
|
31
|
+
(n, a) => {
|
32
32
|
var g, E, h;
|
33
|
-
if (!((g =
|
33
|
+
if (!((g = e.current) != null && g.segmentedCardWrapperRef.current) || !((E = e.current) != null && E.labelRef.current))
|
34
34
|
return;
|
35
|
-
const o =
|
36
|
-
|
37
|
-
originalElementToHighlightRef:
|
35
|
+
const o = e.current.labelRef.current.getBoundingClientRect(), i = (h = e.current) == null ? void 0 : h.segmentedCardWrapperRef.current.getBoundingClientRect();
|
36
|
+
d(t, {
|
37
|
+
originalElementToHighlightRef: e.current.segmentedCardWrapperRef,
|
38
38
|
isActive: !1,
|
39
39
|
type: u.TOOLTIP,
|
40
|
-
elementToHighlight: /* @__PURE__ */
|
41
|
-
|
40
|
+
elementToHighlight: /* @__PURE__ */ r(
|
41
|
+
J,
|
42
42
|
{
|
43
|
-
ref:
|
44
|
-
defaultTable:
|
45
|
-
label:
|
46
|
-
data:
|
47
|
-
onPress:
|
48
|
-
onGoBackFromTableLevel:
|
43
|
+
ref: _,
|
44
|
+
defaultTable: a,
|
45
|
+
label: n.label,
|
46
|
+
data: n.data,
|
47
|
+
onPress: O,
|
48
|
+
onGoBackFromTableLevel: O
|
49
49
|
}
|
50
50
|
),
|
51
51
|
indicator: {
|
52
52
|
position: "left",
|
53
53
|
backgroundColor: "YELLOW_4",
|
54
54
|
width: 236,
|
55
|
-
tooltipItem: /* @__PURE__ */
|
55
|
+
tooltipItem: /* @__PURE__ */ r(b, { children: /* @__PURE__ */ r(m, { $renderAs: "ab2-bold", children: "Each table has 3 levels—clear them and earn 3 stars!" }) }),
|
56
56
|
tooltipXCoOrdinates: 0,
|
57
57
|
tooltipYCoOrdinates: o.height * 0.35
|
58
58
|
}
|
59
|
-
}),
|
60
|
-
originalElementToHighlightRef:
|
59
|
+
}), d(t, {
|
60
|
+
originalElementToHighlightRef: e.current.segmentedCardWrapperRef,
|
61
61
|
isActive: !1,
|
62
62
|
type: u.NUDGE,
|
63
63
|
indicator: {
|
64
64
|
nudge: "click",
|
65
|
-
content: /* @__PURE__ */
|
65
|
+
content: /* @__PURE__ */ r(m, { $renderAs: "ab1", $color: "WHITE", children: "Pick a level" }),
|
66
66
|
nudgePointerX: i.width / 2 + 50,
|
67
67
|
nudgePointerY: i.height * 0.4
|
68
68
|
},
|
69
|
-
elementToHighlight: /* @__PURE__ */
|
70
|
-
}), c(
|
71
|
-
const
|
72
|
-
var
|
73
|
-
clearTimeout(
|
74
|
-
},
|
75
|
-
T.current.push(
|
69
|
+
elementToHighlight: /* @__PURE__ */ r(N, {})
|
70
|
+
}), c(t, !1, ee), c(t, !0, te);
|
71
|
+
const l = setTimeout(() => {
|
72
|
+
var p;
|
73
|
+
clearTimeout(l), (p = _.current) == null || p.startLabelAnimation("YELLOW_4");
|
74
|
+
}, M);
|
75
|
+
T.current.push(l);
|
76
76
|
},
|
77
|
-
[
|
78
|
-
),
|
77
|
+
[d, O, t, c]
|
78
|
+
), R = C(() => {
|
79
79
|
var o;
|
80
|
-
|
80
|
+
y(), (o = s.current) == null || o.goToIndex($), c(t, !1, re), f(G.ONBOARDING_STEP_VIEWED, {
|
81
81
|
step: v.TABLES
|
82
82
|
});
|
83
|
-
const
|
83
|
+
const n = setTimeout(() => {
|
84
84
|
var i;
|
85
|
-
clearTimeout(
|
85
|
+
clearTimeout(n), (i = e.current) == null || i.setLabelVisiblity(!1), c(t, !0);
|
86
86
|
}, ne);
|
87
|
-
T.current.push(
|
88
|
-
const
|
87
|
+
T.current.push(n);
|
88
|
+
const a = setTimeout(() => {
|
89
89
|
var i;
|
90
|
-
clearTimeout(
|
91
|
-
},
|
92
|
-
T.current.push(
|
93
|
-
}, [s,
|
94
|
-
(
|
95
|
-
var h,
|
96
|
-
if (console.log("startJourney", { tablesData:
|
90
|
+
clearTimeout(a), (i = _.current) == null || i.startLabelAnimation("YELLOW_4");
|
91
|
+
}, M);
|
92
|
+
T.current.push(a);
|
93
|
+
}, [s, t, c, y, f]), w = C(
|
94
|
+
(n, a = !1) => {
|
95
|
+
var h, p, W, D, Y, B, U, k;
|
96
|
+
if (console.log("startJourney", { tablesData: n, isTutorialOnboardingDone: a }), I.current)
|
97
97
|
return;
|
98
|
-
const o = (h = s.current) == null ? void 0 : h.indicatorRefs, i = (
|
99
|
-
if (!((W =
|
98
|
+
const o = (h = s.current) == null ? void 0 : h.indicatorRefs, i = (p = s.current) == null ? void 0 : p.nextBtnRef, l = o == null ? void 0 : o[$];
|
99
|
+
if (!((W = e.current) != null && W.segmentedCardWrapperRef.current) || !((D = e.current) != null && D.labelRef.current) || !o || !(i != null && i.current) || !(l != null && l.current)) {
|
100
100
|
console.log("SOMETHING IS NOT AVAILABLE");
|
101
101
|
return;
|
102
102
|
}
|
103
|
-
|
104
|
-
const g =
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
103
|
+
I.current = !0;
|
104
|
+
const g = e.current.labelRef.current.getBoundingClientRect(), E = (Y = e.current) == null ? void 0 : Y.segmentedCardWrapperRef.current.getBoundingClientRect();
|
105
|
+
a ? (console.log("JOURNEY 2", !!(l != null && l.current)), L(t, [
|
106
|
+
{
|
107
|
+
originalElementToHighlightRef: l,
|
108
|
+
isActive: !1,
|
109
|
+
type: u.TOOLTIP,
|
110
|
+
elementToHighlight: /* @__PURE__ */ r(ce, { $isActive: !1 }),
|
111
|
+
indicator: {
|
112
|
+
position: "bottom",
|
113
|
+
backgroundColor: "YELLOW_4",
|
114
|
+
width: 52,
|
115
|
+
tooltipItem: /* @__PURE__ */ r(
|
116
|
+
b,
|
117
|
+
{
|
118
|
+
$position: "absolute",
|
119
|
+
$flexDirection: "row",
|
120
|
+
style: { top: 6, left: 8, cursor: "pointer" },
|
121
|
+
onClick: R,
|
122
|
+
children: /* @__PURE__ */ r(m, { $renderAs: "ab2-bold", children: "NEW" })
|
123
|
+
}
|
124
|
+
),
|
125
|
+
tooltipYCoOrdinates: 14
|
126
|
+
// Need some offset in Y direction from top
|
127
|
+
}
|
128
|
+
},
|
129
|
+
{
|
130
|
+
originalElementToHighlightRef: l,
|
131
|
+
isActive: !1,
|
132
|
+
type: u.NUDGE,
|
133
|
+
indicator: {
|
134
|
+
nudge: "click",
|
135
|
+
content: "",
|
136
|
+
nudgePointerY: 20
|
137
|
+
},
|
138
|
+
elementToHighlight: /* @__PURE__ */ r(N, {})
|
139
|
+
}
|
140
|
+
]), (k = s.current) == null || k.goToIndex(ie), requestAnimationFrame(() => {
|
141
|
+
if (!l.current) {
|
142
|
+
console.warn("Still no pagination!");
|
143
|
+
return;
|
144
|
+
}
|
145
|
+
c(t, !1, x), c(t, !0, le);
|
146
|
+
})) : (console.log("JOURNEY 1"), L(t, [
|
147
|
+
{
|
148
|
+
originalElementToHighlightRef: (B = s.current) == null ? void 0 : B.nextBtnRef,
|
149
|
+
isActive: !1,
|
150
|
+
type: u.NUDGE,
|
151
|
+
indicator: {
|
152
|
+
nudge: "click",
|
153
|
+
content: /* @__PURE__ */ r(m, { $renderAs: "ab1", $color: "WHITE", children: "Click to proceed" }),
|
154
|
+
nudgePointerX: 0,
|
155
|
+
nudgePointerY: 0
|
156
|
+
},
|
157
|
+
elementToHighlight: /* @__PURE__ */ r(
|
158
|
+
Z,
|
116
159
|
{
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
children: /* @__PURE__ */ n(m, { $renderAs: "ab2-bold", children: "NEW" })
|
160
|
+
renderAs: "secondary",
|
161
|
+
Icon: X,
|
162
|
+
onClick: R,
|
163
|
+
analyticsLabel: Q.JOURNEY_NEXT_ACTIVITY
|
122
164
|
}
|
123
|
-
)
|
124
|
-
tooltipYCoOrdinates: 14
|
125
|
-
// Need some offset in Y direction from top
|
165
|
+
)
|
126
166
|
}
|
127
|
-
|
128
|
-
originalElementToHighlightRef:
|
129
|
-
isActive: !1,
|
130
|
-
type: u.NUDGE,
|
131
|
-
indicator: {
|
132
|
-
nudge: "click",
|
133
|
-
content: "",
|
134
|
-
nudgePointerY: 20
|
135
|
-
},
|
136
|
-
elementToHighlight: /* @__PURE__ */ n(R, {})
|
137
|
-
}), (Y = s.current) == null || Y.goToIndex(ie), c(e, !1, J), c(e, !0, le)) : (console.log("TURIRTUAK NOT DONE", { tablesData: r, isTutorialOnboardingDone: l }), a(e, {
|
138
|
-
originalElementToHighlightRef: (k = s.current) == null ? void 0 : k.nextBtnRef,
|
139
|
-
isActive: !1,
|
140
|
-
type: u.NUDGE,
|
141
|
-
indicator: {
|
142
|
-
nudge: "click",
|
143
|
-
content: /* @__PURE__ */ n(m, { $renderAs: "ab1", $color: "WHITE", children: "Click to proceed" }),
|
144
|
-
nudgePointerX: 0,
|
145
|
-
nudgePointerY: 0
|
146
|
-
},
|
147
|
-
elementToHighlight: /* @__PURE__ */ n(
|
148
|
-
Z,
|
149
|
-
{
|
150
|
-
renderAs: "secondary",
|
151
|
-
Icon: X,
|
152
|
-
onClick: O,
|
153
|
-
analyticsLabel: Q.JOURNEY_NEXT_ACTIVITY
|
154
|
-
}
|
155
|
-
)
|
156
|
-
}), (B = s.current) == null || B.goToIndex(oe), c(e, !1, J)), a(e, {
|
157
|
-
originalElementToHighlightRef: t.current.labelRef,
|
167
|
+
]), (U = s.current) == null || U.goToIndex(oe), c(t, !1, x)), d(t, {
|
168
|
+
originalElementToHighlightRef: e.current.labelRef,
|
158
169
|
isActive: !1,
|
159
170
|
type: u.TOOLTIP,
|
160
|
-
elementToHighlight: /* @__PURE__ */
|
171
|
+
elementToHighlight: /* @__PURE__ */ r(N, {}),
|
161
172
|
indicator: {
|
162
173
|
position: "right",
|
163
174
|
backgroundColor: "YELLOW_4",
|
164
175
|
width: 264,
|
165
|
-
tooltipItem: /* @__PURE__ */
|
176
|
+
tooltipItem: /* @__PURE__ */ r(b, { children: /* @__PURE__ */ r(m, { $renderAs: "ab2-bold", children: "Get faster at multiplication! Practice everyday and become a Tables champ." }) }),
|
166
177
|
tooltipXCoOrdinates: g.width + 50,
|
167
178
|
tooltipYCoOrdinates: g.height / 2
|
168
179
|
}
|
169
|
-
}),
|
170
|
-
originalElementToHighlightRef:
|
180
|
+
}), d(t, {
|
181
|
+
originalElementToHighlightRef: e.current.segmentedCardWrapperRef,
|
171
182
|
isActive: !1,
|
172
183
|
type: u.NUDGE,
|
173
184
|
indicator: {
|
174
185
|
nudge: "click",
|
175
|
-
content: /* @__PURE__ */
|
186
|
+
content: /* @__PURE__ */ r(m, { $renderAs: "ab1", $color: "WHITE", children: "Pick a table to start" }),
|
176
187
|
nudgePointerX: E.width / 2 + 50,
|
177
188
|
nudgePointerY: E.height / 2
|
178
189
|
},
|
179
|
-
elementToHighlight: /* @__PURE__ */
|
180
|
-
|
190
|
+
elementToHighlight: /* @__PURE__ */ r(
|
191
|
+
J,
|
181
192
|
{
|
182
|
-
ref:
|
183
|
-
label:
|
184
|
-
data:
|
193
|
+
ref: _,
|
194
|
+
label: n.label,
|
195
|
+
data: n.data,
|
185
196
|
onPress: () => {
|
186
197
|
},
|
187
|
-
onPressTableSegment: (
|
198
|
+
onPressTableSegment: (F) => P(n, F)
|
188
199
|
}
|
189
200
|
)
|
190
201
|
});
|
191
202
|
},
|
192
203
|
[
|
193
|
-
|
204
|
+
d,
|
194
205
|
s,
|
195
|
-
|
196
|
-
|
197
|
-
|
206
|
+
R,
|
207
|
+
P,
|
208
|
+
t,
|
198
209
|
c,
|
199
|
-
|
210
|
+
L
|
200
211
|
]
|
201
212
|
);
|
202
|
-
return
|
203
|
-
T.current.forEach((
|
204
|
-
}, [
|
205
|
-
tableRef:
|
206
|
-
startJourney:
|
213
|
+
return V(() => () => {
|
214
|
+
T.current.forEach((n) => clearTimeout(n)), T.current = [], I.current = !1;
|
215
|
+
}, [t]), {
|
216
|
+
tableRef: e,
|
217
|
+
startJourney: w
|
207
218
|
};
|
208
219
|
};
|
209
220
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-launcher-journey.js","sources":["../../../../../../src/features/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.tsx"],"sourcesContent":["/* eslint-disable react-native/no-inline-styles */\nimport type { IArrowTooltipProps } from '../../../../ui/arrow-tooltip/arrow-tooltip-types';\nimport type { INudgeProps } from '../../../../ui/nudge/nudge-types';\nimport type { ITableCardRef, ITableDetails } from '../../comps/tables-card/tables-card-types';\nimport type {\n ITableInfo,\n ITables,\n} from '../../dal/use-get-circle-home-details-dal/use-get-circle-home-dal-types';\nimport type { IUseTableJourneyProps } from './use-table-launcher-journey-types';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport CaratRightIcon from '../../../../../assets/line-icons/icons/carat-right';\nimport { PLATFORM_EVENTS_STUDENT } from '../../../../analytics-events/platform-events-student';\nimport { JOURNEY_ID_STUDENT } from '../../../../journey/journey-id/journey-id-student';\nimport { IndicatorType } from '../../../../journey/use-journey/constants';\nimport { useJourney } from '../../../../journey/use-journey/use-journey';\nimport IconButton from '../../../../ui/buttons/icon-button/icon-button';\nimport { useUIContext } from '../../../../ui/context/context';\nimport FlexView from '../../../../ui/layout/flex-view';\nimport Text from '../../../../ui/text/text';\nimport { CIRCLE_ONBOARDING_ANALYTICS_STEPS as Action } from '../../../enum/circle-onboarding-steps';\nimport { useCircleSounds } from '../../../hooks/use-circle-sounds/use-circle-sounds';\nimport { TablesCard } from '../../comps/tables-card/tables-card';\nimport { GAME_LAUNCHER_ANALYTICS_EVENTS } from '../../game-launcher-analytics-events';\nimport {\n LESSON_CARD_INDEX,\n PUZZLE_CARD_INDEX,\n SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS,\n SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS,\n TABLE_CARD_INDEX,\n} from './constants';\nimport {\n GO_TO_TABLE_LAUNCHER_DURATION_MS,\n SHOW_CLICK_TABLE_NUDGE_AFTER_MS,\n SHOW_INITIAL_COACHMARK_AFTER_MS,\n SHOW_INITIAL_TOOLTIP_AFTER_MS,\n START_ANIMATING_CLONED_ELEM,\n} from './constants';\nimport * as S from './use-table-launcher-journey-styled';\n\nexport const useTableLauncherJourney = ({\n carouselRefs,\n onTableSegmentClick,\n}: IUseTableJourneyProps) => {\n const journeyId = JOURNEY_ID_STUDENT.CIRCLE_TABLES_INTRO_JOURNEY;\n const originalTableRef = useRef<ITableCardRef>(null);\n const highlightedTableRef = useRef<ITableCardRef>(null);\n const isJourneyInProgress = useRef(false);\n\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { playButtonSound } = useCircleSounds();\n const { nextCoachmark, setJourney, addCoachmark, endJourney } = useJourney();\n const { onEvent: trackAnalytics } = useUIContext();\n\n const handleEndJourney = useCallback(\n (tableDetails?: ITableDetails) => {\n // Only when User clicked on play\n if (tableDetails) {\n onTableSegmentClick(tableDetails);\n }\n trackAnalytics(PLATFORM_EVENTS_STUDENT.ONBOARDING_STEP_COMPLETED, {\n step: Action.TABLES,\n });\n\n // Reset original table card ref label\n originalTableRef?.current?.setLabelVisiblity(true);\n originalTableRef?.current?.stopLabelAnimation();\n endJourney(journeyId);\n },\n [endJourney, journeyId, onTableSegmentClick, trackAnalytics],\n );\n\n const handleTableSegmentClick = useCallback(\n (launcherData: ITables, tableData: ITableInfo) => {\n if (\n !originalTableRef.current?.segmentedCardWrapperRef.current ||\n !originalTableRef.current?.labelRef.current\n ) {\n return;\n }\n\n const segmentedCardDims = originalTableRef.current.labelRef.current.getBoundingClientRect();\n const tableCardDims =\n originalTableRef.current?.segmentedCardWrapperRef.current.getBoundingClientRect();\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: (\n <TablesCard\n ref={highlightedTableRef}\n defaultTable={tableData}\n label={launcherData.label}\n data={launcherData.data}\n onPress={handleEndJourney}\n onGoBackFromTableLevel={handleEndJourney}\n />\n ),\n indicator: {\n position: 'left',\n backgroundColor: 'YELLOW_4',\n width: 236,\n tooltipItem: (\n <FlexView>\n <Text $renderAs=\"ab2-bold\">Each table has 3 levels—clear them and earn 3 stars!</Text>\n </FlexView>\n ),\n tooltipXCoOrdinates: 0,\n tooltipYCoOrdinates: segmentedCardDims.height * 0.35,\n } as IArrowTooltipProps,\n });\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n Pick a level\n </Text>\n ),\n nudgePointerX: tableCardDims.width / 2 + 50,\n nudgePointerY: tableCardDims.height * 0.4,\n } as INudgeProps,\n elementToHighlight: <></>,\n });\n\n nextCoachmark(journeyId, false, SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS); // Show coachmark => Each table has 3... and Hide the previous two\n nextCoachmark(journeyId, true, SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS); // Show nudge => Pick a level\n\n const startAnimationOnLabelAgain = setTimeout(() => {\n clearTimeout(startAnimationOnLabelAgain);\n highlightedTableRef.current?.startLabelAnimation('YELLOW_4');\n }, START_ANIMATING_CLONED_ELEM);\n\n timerRefs.current.push(startAnimationOnLabelAgain);\n },\n [addCoachmark, handleEndJourney, journeyId, nextCoachmark],\n );\n\n const goToTableLauncher = useCallback(() => {\n playButtonSound();\n carouselRefs.current?.goToIndex(TABLE_CARD_INDEX);\n nextCoachmark(journeyId, false, GO_TO_TABLE_LAUNCHER_DURATION_MS);\n\n trackAnalytics(PLATFORM_EVENTS_STUDENT.ONBOARDING_STEP_VIEWED, {\n step: Action.TABLES,\n });\n\n const showNudge = setTimeout(() => {\n clearTimeout(showNudge);\n originalTableRef.current?.setLabelVisiblity(false);\n nextCoachmark(journeyId, true);\n }, SHOW_CLICK_TABLE_NUDGE_AFTER_MS);\n\n timerRefs.current.push(showNudge);\n\n const animateLabel = setTimeout(() => {\n clearTimeout(animateLabel);\n highlightedTableRef.current?.startLabelAnimation('YELLOW_4');\n }, START_ANIMATING_CLONED_ELEM);\n\n timerRefs.current.push(animateLabel);\n }, [carouselRefs, journeyId, nextCoachmark, playButtonSound, trackAnalytics]);\n\n const startJourney = useCallback(\n (tablesData: ITables, isTutorialOnboardingDone: boolean = false) => {\n console.log('startJourney', { tablesData, isTutorialOnboardingDone });\n\n if (isJourneyInProgress.current) {\n return;\n }\n\n const paginationList = carouselRefs.current?.indicatorRefs;\n const carouselNextBtnRef = carouselRefs.current?.nextBtnRef;\n const tablePaginationRef = paginationList?.[TABLE_CARD_INDEX];\n\n if (\n !originalTableRef.current?.segmentedCardWrapperRef.current ||\n !originalTableRef.current?.labelRef.current ||\n !paginationList ||\n !carouselNextBtnRef?.current ||\n !tablePaginationRef ||\n !tablePaginationRef.current\n ) {\n console.log('SOMETHING IS NOT AVAILABLE');\n\n return;\n }\n\n isJourneyInProgress.current = true;\n\n const labelDims = originalTableRef.current.labelRef.current.getBoundingClientRect();\n const tableCardDims =\n originalTableRef.current?.segmentedCardWrapperRef.current.getBoundingClientRect();\n\n setJourney(journeyId, []);\n\n // TAKE THE USER TO THE TABLE CARD\n if (!isTutorialOnboardingDone) {\n console.log('TURIRTUAK NOT DONE', { tablesData, isTutorialOnboardingDone });\n addCoachmark(journeyId, {\n originalElementToHighlightRef: carouselRefs.current?.nextBtnRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n Click to proceed\n </Text>\n ),\n nudgePointerX: 0,\n nudgePointerY: 0,\n } as INudgeProps,\n elementToHighlight: (\n <IconButton\n renderAs=\"secondary\"\n Icon={CaratRightIcon}\n onClick={goToTableLauncher}\n analyticsLabel={GAME_LAUNCHER_ANALYTICS_EVENTS.JOURNEY_NEXT_ACTIVITY}\n />\n ),\n });\n carouselRefs.current?.goToIndex(PUZZLE_CARD_INDEX);\n nextCoachmark(journeyId, false, SHOW_INITIAL_COACHMARK_AFTER_MS); // Show nudge => Click to proceed\n } else {\n console.log('TUTORIAL DONE 2', { tablePaginationRef });\n addCoachmark(journeyId, {\n originalElementToHighlightRef: tablePaginationRef as React.RefObject<HTMLDivElement>,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: <S.Indicator id=\"kill-me\" $isActive={false} />,\n indicator: {\n position: 'bottom',\n backgroundColor: 'YELLOW_4',\n width: 52,\n tooltipItem: (\n <FlexView\n $position=\"absolute\"\n $flexDirection=\"row\"\n style={{ top: 6, left: 8, cursor: 'pointer' }}\n onClick={goToTableLauncher}\n >\n <Text $renderAs=\"ab2-bold\">NEW</Text>\n </FlexView>\n ),\n tooltipYCoOrdinates: 14, // Need some offset in Y direction from top\n } as IArrowTooltipProps,\n });\n addCoachmark(journeyId, {\n originalElementToHighlightRef: tablePaginationRef as React.RefObject<HTMLDivElement>,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: '',\n nudgePointerY: 20,\n } as INudgeProps,\n elementToHighlight: <></>,\n });\n carouselRefs.current?.goToIndex(LESSON_CARD_INDEX);\n nextCoachmark(journeyId, false, SHOW_INITIAL_COACHMARK_AFTER_MS); // Show Coachmark => NEW\n nextCoachmark(journeyId, true, SHOW_INITIAL_TOOLTIP_AFTER_MS); // Show Nudge over Coachmark\n }\n\n // SHOW THE USER SELECT A TABLE\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.labelRef,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: <></>,\n indicator: {\n position: 'right',\n backgroundColor: 'YELLOW_4',\n width: 264,\n tooltipItem: (\n <FlexView>\n <Text $renderAs=\"ab2-bold\">\n Get faster at multiplication! Practice everyday and become a Tables champ.\n </Text>\n </FlexView>\n ),\n tooltipXCoOrdinates: labelDims.width + 50,\n tooltipYCoOrdinates: labelDims.height / 2,\n } as IArrowTooltipProps,\n });\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n {'Pick a table to start'}\n </Text>\n ),\n nudgePointerX: tableCardDims.width / 2 + 50,\n nudgePointerY: tableCardDims.height / 2,\n } as INudgeProps,\n elementToHighlight: (\n <TablesCard\n ref={highlightedTableRef}\n label={tablesData.label}\n data={tablesData.data}\n onPress={() => {}}\n onPressTableSegment={tableInfo => handleTableSegmentClick(tablesData, tableInfo)}\n />\n ),\n });\n },\n [\n addCoachmark,\n carouselRefs,\n goToTableLauncher,\n handleTableSegmentClick,\n journeyId,\n nextCoachmark,\n setJourney,\n ],\n );\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n timerRefs.current.forEach(timer => clearTimeout(timer));\n timerRefs.current = [];\n isJourneyInProgress.current = false;\n };\n }, [journeyId]);\n\n return {\n tableRef: originalTableRef,\n startJourney,\n };\n};\n"],"names":["useTableLauncherJourney","carouselRefs","onTableSegmentClick","journeyId","JOURNEY_ID_STUDENT","originalTableRef","useRef","highlightedTableRef","isJourneyInProgress","timerRefs","playButtonSound","useCircleSounds","nextCoachmark","setJourney","addCoachmark","endJourney","useJourney","trackAnalytics","useUIContext","handleEndJourney","useCallback","tableDetails","PLATFORM_EVENTS_STUDENT","Action","_a","_b","handleTableSegmentClick","launcherData","tableData","segmentedCardDims","tableCardDims","_c","IndicatorType","jsx","TablesCard","FlexView","Text","Fragment","SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS","SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS","startAnimationOnLabelAgain","START_ANIMATING_CLONED_ELEM","goToTableLauncher","TABLE_CARD_INDEX","GO_TO_TABLE_LAUNCHER_DURATION_MS","showNudge","SHOW_CLICK_TABLE_NUDGE_AFTER_MS","animateLabel","startJourney","tablesData","isTutorialOnboardingDone","paginationList","carouselNextBtnRef","tablePaginationRef","_d","labelDims","_e","S.Indicator","_h","LESSON_CARD_INDEX","SHOW_INITIAL_COACHMARK_AFTER_MS","SHOW_INITIAL_TOOLTIP_AFTER_MS","_f","IconButton","CaratRightIcon","GAME_LAUNCHER_ANALYTICS_EVENTS","_g","PUZZLE_CARD_INDEX","tableInfo","useEffect","timer"],"mappings":";;;;;;;;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qBAAqB,CAAAmB,MAAa1C,EAAwBuB,GAAYmB,CAAS;AAAA,UAAA;AAAA,QACjF;AAAA,MAAA,CAEH;AAAA,IACH;AAAA,IACA;AAAA,MACEtD;AAAA,MACAb;AAAA,MACAyC;AAAA,MACAhB;AAAA,MACAvB;AAAA,MACAS;AAAA,MACAC;AAAA,IACF;AAAA,EAAA;AAIF,SAAAwD,EAAU,MACD,MAAM;AACX,IAAA5D,EAAU,QAAQ,QAAQ,CAAS6D,MAAA,aAAaA,CAAK,CAAC,GACtD7D,EAAU,UAAU,IACpBD,EAAoB,UAAU;AAAA,EAAA,GAE/B,CAACL,CAAS,CAAC,GAEP;AAAA,IACL,UAAUE;AAAA,IACV,cAAA2C;AAAA,EAAA;AAEJ;"}
|
1
|
+
{"version":3,"file":"use-table-launcher-journey.js","sources":["../../../../../../src/features/circle-games/game-launcher/hooks/use-table-launcher-journey/use-table-launcher-journey.tsx"],"sourcesContent":["/* eslint-disable react-native/no-inline-styles */\nimport type { IArrowTooltipProps } from '../../../../ui/arrow-tooltip/arrow-tooltip-types';\nimport type { INudgeProps } from '../../../../ui/nudge/nudge-types';\nimport type { ITableCardRef, ITableDetails } from '../../comps/tables-card/tables-card-types';\nimport type {\n ITableInfo,\n ITables,\n} from '../../dal/use-get-circle-home-details-dal/use-get-circle-home-dal-types';\nimport type { IUseTableJourneyProps } from './use-table-launcher-journey-types';\n\nimport { useCallback, useEffect, useRef } from 'react';\n\nimport CaratRightIcon from '../../../../../assets/line-icons/icons/carat-right';\nimport { PLATFORM_EVENTS_STUDENT } from '../../../../analytics-events/platform-events-student';\nimport { JOURNEY_ID_STUDENT } from '../../../../journey/journey-id/journey-id-student';\nimport { IndicatorType } from '../../../../journey/use-journey/constants';\nimport { useJourney } from '../../../../journey/use-journey/use-journey';\nimport IconButton from '../../../../ui/buttons/icon-button/icon-button';\nimport { useUIContext } from '../../../../ui/context/context';\nimport FlexView from '../../../../ui/layout/flex-view';\nimport Text from '../../../../ui/text/text';\nimport { CIRCLE_ONBOARDING_ANALYTICS_STEPS as Action } from '../../../enum/circle-onboarding-steps';\nimport { useCircleSounds } from '../../../hooks/use-circle-sounds/use-circle-sounds';\nimport { TablesCard } from '../../comps/tables-card/tables-card';\nimport { GAME_LAUNCHER_ANALYTICS_EVENTS } from '../../game-launcher-analytics-events';\nimport {\n LESSON_CARD_INDEX,\n PUZZLE_CARD_INDEX,\n SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS,\n SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS,\n TABLE_CARD_INDEX,\n} from './constants';\nimport {\n GO_TO_TABLE_LAUNCHER_DURATION_MS,\n SHOW_CLICK_TABLE_NUDGE_AFTER_MS,\n SHOW_INITIAL_COACHMARK_AFTER_MS,\n SHOW_INITIAL_TOOLTIP_AFTER_MS,\n START_ANIMATING_CLONED_ELEM,\n} from './constants';\nimport * as S from './use-table-launcher-journey-styled';\n\nexport const useTableLauncherJourney = ({\n carouselRefs,\n onTableSegmentClick,\n}: IUseTableJourneyProps) => {\n const journeyId = JOURNEY_ID_STUDENT.CIRCLE_TABLES_INTRO_JOURNEY;\n const originalTableRef = useRef<ITableCardRef>(null);\n const highlightedTableRef = useRef<ITableCardRef>(null);\n const isJourneyInProgress = useRef(false);\n\n const timerRefs = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n const { playButtonSound } = useCircleSounds();\n const { nextCoachmark, setJourney, addCoachmark, endJourney } = useJourney();\n const { onEvent: trackAnalytics } = useUIContext();\n\n const handleEndJourney = useCallback(\n (tableDetails?: ITableDetails) => {\n // Only when User clicked on play\n if (tableDetails) {\n onTableSegmentClick(tableDetails);\n }\n trackAnalytics(PLATFORM_EVENTS_STUDENT.ONBOARDING_STEP_COMPLETED, {\n step: Action.TABLES,\n });\n\n // Reset original table card ref label\n originalTableRef?.current?.setLabelVisiblity(true);\n originalTableRef?.current?.stopLabelAnimation();\n endJourney(journeyId);\n },\n [endJourney, journeyId, onTableSegmentClick, trackAnalytics],\n );\n\n const handleTableSegmentClick = useCallback(\n (launcherData: ITables, tableData: ITableInfo) => {\n if (\n !originalTableRef.current?.segmentedCardWrapperRef.current ||\n !originalTableRef.current?.labelRef.current\n ) {\n return;\n }\n\n const segmentedCardDims = originalTableRef.current.labelRef.current.getBoundingClientRect();\n const tableCardDims =\n originalTableRef.current?.segmentedCardWrapperRef.current.getBoundingClientRect();\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: (\n <TablesCard\n ref={highlightedTableRef}\n defaultTable={tableData}\n label={launcherData.label}\n data={launcherData.data}\n onPress={handleEndJourney}\n onGoBackFromTableLevel={handleEndJourney}\n />\n ),\n indicator: {\n position: 'left',\n backgroundColor: 'YELLOW_4',\n width: 236,\n tooltipItem: (\n <FlexView>\n <Text $renderAs=\"ab2-bold\">Each table has 3 levels—clear them and earn 3 stars!</Text>\n </FlexView>\n ),\n tooltipXCoOrdinates: 0,\n tooltipYCoOrdinates: segmentedCardDims.height * 0.35,\n } as IArrowTooltipProps,\n });\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n Pick a level\n </Text>\n ),\n nudgePointerX: tableCardDims.width / 2 + 50,\n nudgePointerY: tableCardDims.height * 0.4,\n } as INudgeProps,\n elementToHighlight: <></>,\n });\n\n nextCoachmark(journeyId, false, SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS); // Show coachmark => Each table has 3... and Hide the previous two\n nextCoachmark(journeyId, true, SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS); // Show nudge => Pick a level\n\n const startAnimationOnLabelAgain = setTimeout(() => {\n clearTimeout(startAnimationOnLabelAgain);\n highlightedTableRef.current?.startLabelAnimation('YELLOW_4');\n }, START_ANIMATING_CLONED_ELEM);\n\n timerRefs.current.push(startAnimationOnLabelAgain);\n },\n [addCoachmark, handleEndJourney, journeyId, nextCoachmark],\n );\n\n const goToTableLauncher = useCallback(() => {\n playButtonSound();\n carouselRefs.current?.goToIndex(TABLE_CARD_INDEX);\n nextCoachmark(journeyId, false, GO_TO_TABLE_LAUNCHER_DURATION_MS);\n\n trackAnalytics(PLATFORM_EVENTS_STUDENT.ONBOARDING_STEP_VIEWED, {\n step: Action.TABLES,\n });\n\n const showNudge = setTimeout(() => {\n clearTimeout(showNudge);\n originalTableRef.current?.setLabelVisiblity(false);\n nextCoachmark(journeyId, true);\n }, SHOW_CLICK_TABLE_NUDGE_AFTER_MS);\n\n timerRefs.current.push(showNudge);\n\n const animateLabel = setTimeout(() => {\n clearTimeout(animateLabel);\n highlightedTableRef.current?.startLabelAnimation('YELLOW_4');\n }, START_ANIMATING_CLONED_ELEM);\n\n timerRefs.current.push(animateLabel);\n }, [carouselRefs, journeyId, nextCoachmark, playButtonSound, trackAnalytics]);\n\n const startJourney = useCallback(\n (tablesData: ITables, isTutorialOnboardingDone: boolean = false) => {\n console.log('startJourney', { tablesData, isTutorialOnboardingDone });\n\n if (isJourneyInProgress.current) {\n return;\n }\n\n const paginationList = carouselRefs.current?.indicatorRefs;\n const carouselNextBtnRef = carouselRefs.current?.nextBtnRef;\n const tablePaginationRef = paginationList?.[TABLE_CARD_INDEX];\n\n if (\n !originalTableRef.current?.segmentedCardWrapperRef.current ||\n !originalTableRef.current?.labelRef.current ||\n !paginationList ||\n !carouselNextBtnRef?.current ||\n !tablePaginationRef?.current\n ) {\n console.log('SOMETHING IS NOT AVAILABLE');\n\n return;\n }\n\n isJourneyInProgress.current = true;\n\n const labelDims = originalTableRef.current.labelRef.current.getBoundingClientRect();\n const tableCardDims =\n originalTableRef.current?.segmentedCardWrapperRef.current.getBoundingClientRect();\n\n // TAKE THE USER TO THE TABLE CARD\n if (!isTutorialOnboardingDone) {\n console.log('JOURNEY 1');\n\n setJourney(journeyId, [\n {\n originalElementToHighlightRef: carouselRefs.current?.nextBtnRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n Click to proceed\n </Text>\n ),\n nudgePointerX: 0,\n nudgePointerY: 0,\n } as INudgeProps,\n elementToHighlight: (\n <IconButton\n renderAs=\"secondary\"\n Icon={CaratRightIcon}\n onClick={goToTableLauncher}\n analyticsLabel={GAME_LAUNCHER_ANALYTICS_EVENTS.JOURNEY_NEXT_ACTIVITY}\n />\n ),\n },\n ]);\n carouselRefs.current?.goToIndex(PUZZLE_CARD_INDEX);\n nextCoachmark(journeyId, false, SHOW_INITIAL_COACHMARK_AFTER_MS); // Show nudge => Click to proceed\n } else {\n console.log('JOURNEY 2', Boolean(tablePaginationRef?.current));\n setJourney(journeyId, [\n {\n originalElementToHighlightRef: tablePaginationRef as React.RefObject<HTMLDivElement>,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: <S.Indicator $isActive={false} />,\n indicator: {\n position: 'bottom',\n backgroundColor: 'YELLOW_4',\n width: 52,\n tooltipItem: (\n <FlexView\n $position=\"absolute\"\n $flexDirection=\"row\"\n style={{ top: 6, left: 8, cursor: 'pointer' }}\n onClick={goToTableLauncher}\n >\n <Text $renderAs=\"ab2-bold\">NEW</Text>\n </FlexView>\n ),\n tooltipYCoOrdinates: 14, // Need some offset in Y direction from top\n } as IArrowTooltipProps,\n },\n {\n originalElementToHighlightRef: tablePaginationRef as React.RefObject<HTMLDivElement>,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: '',\n nudgePointerY: 20,\n } as INudgeProps,\n elementToHighlight: <></>,\n },\n ]);\n carouselRefs.current?.goToIndex(LESSON_CARD_INDEX);\n // after you call carouselRefs.current.goToIndex(...)\n requestAnimationFrame(() => {\n // now the DOM has updated\n if (!tablePaginationRef.current) {\n console.warn('Still no pagination!');\n return;\n }\n // safe to setJourney/addCoachmark here\n nextCoachmark(journeyId, false, SHOW_INITIAL_COACHMARK_AFTER_MS); // Show Coachmark => NEW\n nextCoachmark(journeyId, true, SHOW_INITIAL_TOOLTIP_AFTER_MS); // Show Nudge over Coachmark\n });\n }\n\n // SHOW THE USER SELECT A TABLE\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.labelRef,\n isActive: false,\n type: IndicatorType.TOOLTIP,\n elementToHighlight: <></>,\n indicator: {\n position: 'right',\n backgroundColor: 'YELLOW_4',\n width: 264,\n tooltipItem: (\n <FlexView>\n <Text $renderAs=\"ab2-bold\">\n Get faster at multiplication! Practice everyday and become a Tables champ.\n </Text>\n </FlexView>\n ),\n tooltipXCoOrdinates: labelDims.width + 50,\n tooltipYCoOrdinates: labelDims.height / 2,\n } as IArrowTooltipProps,\n });\n\n addCoachmark(journeyId, {\n originalElementToHighlightRef: originalTableRef.current.segmentedCardWrapperRef,\n isActive: false,\n type: IndicatorType.NUDGE,\n indicator: {\n nudge: 'click',\n content: (\n <Text $renderAs=\"ab1\" $color=\"WHITE\">\n {'Pick a table to start'}\n </Text>\n ),\n nudgePointerX: tableCardDims.width / 2 + 50,\n nudgePointerY: tableCardDims.height / 2,\n } as INudgeProps,\n elementToHighlight: (\n <TablesCard\n ref={highlightedTableRef}\n label={tablesData.label}\n data={tablesData.data}\n onPress={() => {}}\n onPressTableSegment={tableInfo => handleTableSegmentClick(tablesData, tableInfo)}\n />\n ),\n });\n },\n [\n addCoachmark,\n carouselRefs,\n goToTableLauncher,\n handleTableSegmentClick,\n journeyId,\n nextCoachmark,\n setJourney,\n ],\n );\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n timerRefs.current.forEach(timer => clearTimeout(timer));\n timerRefs.current = [];\n isJourneyInProgress.current = false;\n };\n }, [journeyId]);\n\n return {\n tableRef: originalTableRef,\n startJourney,\n };\n};\n"],"names":["useTableLauncherJourney","carouselRefs","onTableSegmentClick","journeyId","JOURNEY_ID_STUDENT","originalTableRef","useRef","highlightedTableRef","isJourneyInProgress","timerRefs","playButtonSound","useCircleSounds","nextCoachmark","setJourney","addCoachmark","endJourney","useJourney","trackAnalytics","useUIContext","handleEndJourney","useCallback","tableDetails","PLATFORM_EVENTS_STUDENT","Action","_a","_b","handleTableSegmentClick","launcherData","tableData","segmentedCardDims","tableCardDims","_c","IndicatorType","jsx","TablesCard","FlexView","Text","Fragment","SHOW_PICK_A_LEVEL_TOOLTIP_AFTER_MS","SHOW_PICK_A_LEVEL_NUDGE_AFTER_MS","startAnimationOnLabelAgain","START_ANIMATING_CLONED_ELEM","goToTableLauncher","TABLE_CARD_INDEX","GO_TO_TABLE_LAUNCHER_DURATION_MS","showNudge","SHOW_CLICK_TABLE_NUDGE_AFTER_MS","animateLabel","startJourney","tablesData","isTutorialOnboardingDone","paginationList","carouselNextBtnRef","tablePaginationRef","_d","labelDims","_e","S.Indicator","_h","LESSON_CARD_INDEX","SHOW_INITIAL_COACHMARK_AFTER_MS","SHOW_INITIAL_TOOLTIP_AFTER_MS","_f","IconButton","CaratRightIcon","GAME_LAUNCHER_ANALYTICS_EVENTS","_g","PUZZLE_CARD_INDEX","tableInfo","useEffect","timer"],"mappings":";;;;;;;;;;;;;;;;;AAyCO,MAAMA,KAA0B,CAAC;AAAA,EACtC,cAAAC;AAAA,EACA,qBAAAC;AACF,MAA6B;AAC3B,QAAMC,IAAYC,EAAmB,6BAC/BC,IAAmBC,EAAsB,IAAI,GAC7CC,IAAsBD,EAAsB,IAAI,GAChDE,IAAsBF,EAAO,EAAK,GAElCG,IAAYH,EAAwC,CAAA,CAAE,GAEtD,EAAE,iBAAAI,MAAoBC,KACtB,EAAE,eAAAC,GAAe,YAAAC,GAAY,cAAAC,GAAc,YAAAC,EAAA,IAAeC,KAC1D,EAAE,SAASC,EAAe,IAAIC,EAAa,GAE3CC,IAAmBC;AAAA,IACvB,CAACC,MAAiC;;AAEhC,MAAIA,KACFnB,EAAoBmB,CAAY,GAElCJ,EAAeK,E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,CAACL,CAAS,CAAC,GAEP;AAAA,IACL,UAAUE;AAAA,IACV,cAAA2C;AAAA,EAAA;AAEJ;"}
|
@@ -1,14 +1,16 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { createContext as
|
3
|
-
import { Coachmark as
|
4
|
-
import { usePostUserJourney as
|
5
|
-
import { Overlay as
|
6
|
-
const
|
7
|
-
const [k, x] = h([]), [
|
1
|
+
import { jsxs as b, jsx as w } from "react/jsx-runtime";
|
2
|
+
import { createContext as q, useState as h, useRef as g, useCallback as m, useMemo as D, useEffect as O } from "react";
|
3
|
+
import { Coachmark as L } from "../comps/coachmark/coachmark.js";
|
4
|
+
import { usePostUserJourney as N, useGetUserJourney as z } from "../user-journey-api/user-journey-api.js";
|
5
|
+
import { Overlay as G } from "./journey-styled.js";
|
6
|
+
const M = q(null), K = ({ children: R, appId: n, userId: u }) => {
|
7
|
+
const [k, x] = h([]), [s, a] = h([]), [y, $] = h(!1), J = g(-1), r = g(), d = g([]), { post: p } = N(), {
|
8
8
|
data: f = null,
|
9
9
|
get: v,
|
10
10
|
isProcessing: T
|
11
|
-
} =
|
11
|
+
} = z();
|
12
|
+
(n === "" || f && !T) && s.length > 0;
|
13
|
+
const _ = m(
|
12
14
|
(e, o) => {
|
13
15
|
if (console.log(`setJourney: ${e}`), y) {
|
14
16
|
console.error(
|
@@ -19,21 +21,21 @@ const S = D(null), Q = ({ children: R, appId: n, userId: u }) => {
|
|
19
21
|
$(!0), r.current = e, J.current = -1, a([...o]);
|
20
22
|
},
|
21
23
|
[y]
|
22
|
-
),
|
24
|
+
), c = m(() => {
|
23
25
|
console.log(`clearJourney: ${r.current}`), d.current.forEach((e) => {
|
24
26
|
clearTimeout(e);
|
25
27
|
}), d.current = [], r.current = void 0, J.current = -1, a([]), $(!1);
|
26
|
-
}, []),
|
28
|
+
}, []), A = m(
|
27
29
|
(e) => {
|
28
30
|
console.log(`endJOurney: ${r.current}`), x((o) => [...o, e]), p({
|
29
31
|
app_id: n,
|
30
32
|
user_id: u,
|
31
33
|
journey_id: e,
|
32
34
|
journey_status: "COMPLETED"
|
33
|
-
}),
|
35
|
+
}), c();
|
34
36
|
},
|
35
|
-
[n,
|
36
|
-
),
|
37
|
+
[n, c, p, u]
|
38
|
+
), E = m((e, o) => {
|
37
39
|
if (console.log({ addCoachmark: { id: e, coachmark: o } }), !r.current || e !== r.current) {
|
38
40
|
console.error(
|
39
41
|
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"
|
@@ -41,7 +43,7 @@ const S = D(null), Q = ({ children: R, appId: n, userId: u }) => {
|
|
41
43
|
return;
|
42
44
|
}
|
43
45
|
a((l) => [...l, o]);
|
44
|
-
}, []),
|
46
|
+
}, []), P = m(
|
45
47
|
(e, o = !1, l = 0) => {
|
46
48
|
if (console.log({ addCoachmark: { id: e, keepPrevActive: o, delayInMs: l } }), !r.current || e !== r.current) {
|
47
49
|
console.error(
|
@@ -50,38 +52,38 @@ const S = D(null), Q = ({ children: R, appId: n, userId: u }) => {
|
|
50
52
|
return;
|
51
53
|
}
|
52
54
|
l !== 0 && a((t) => t.map((i) => ({ ...i, isActive: !1 })));
|
53
|
-
const
|
54
|
-
clearTimeout(
|
55
|
+
const j = setTimeout(() => {
|
56
|
+
clearTimeout(j);
|
55
57
|
const t = J.current + 1;
|
56
58
|
a((i) => {
|
57
59
|
if (t >= i.length || i.length === 0)
|
58
|
-
return
|
60
|
+
return c(), [];
|
59
61
|
J.current = t;
|
60
62
|
const C = [...i];
|
61
63
|
return C[t].isActive = !0, t > 0 && (C[t - 1].isActive = o), C;
|
62
64
|
});
|
63
65
|
}, l);
|
64
|
-
d.current.push(
|
66
|
+
d.current.push(j);
|
65
67
|
},
|
66
|
-
[
|
67
|
-
),
|
68
|
+
[c]
|
69
|
+
), U = D(
|
68
70
|
() => ({
|
69
|
-
nextCoachmark:
|
71
|
+
nextCoachmark: P,
|
70
72
|
setJourney: _,
|
71
|
-
addCoachmark:
|
72
|
-
clearJourney:
|
73
|
-
endJourney:
|
74
|
-
coachmarks:
|
73
|
+
addCoachmark: E,
|
74
|
+
clearJourney: c,
|
75
|
+
endJourney: A,
|
76
|
+
coachmarks: s,
|
75
77
|
userCompletedJourneyIds: k,
|
76
78
|
isJourneyActive: y
|
77
79
|
}),
|
78
80
|
[
|
79
|
-
|
81
|
+
P,
|
80
82
|
_,
|
83
|
+
E,
|
84
|
+
c,
|
81
85
|
A,
|
82
86
|
s,
|
83
|
-
w,
|
84
|
-
c,
|
85
87
|
k,
|
86
88
|
y
|
87
89
|
]
|
@@ -97,13 +99,13 @@ const S = D(null), Q = ({ children: R, appId: n, userId: u }) => {
|
|
97
99
|
const e = f.map((o) => o.journey_id);
|
98
100
|
x(e);
|
99
101
|
}
|
100
|
-
}, [f]), /* @__PURE__ */
|
101
|
-
|
102
|
+
}, [f]), /* @__PURE__ */ b(M.Provider, { value: U, children: [
|
103
|
+
s.length > 0 && /* @__PURE__ */ w(G, { children: s.map((e, o) => /* @__PURE__ */ w(L, { coachmark: e }, `coachmark-${o}`)) }),
|
102
104
|
R
|
103
105
|
] });
|
104
106
|
};
|
105
107
|
export {
|
106
|
-
|
107
|
-
|
108
|
+
M as JourneyContext,
|
109
|
+
K as JourneyProvider
|
108
110
|
};
|
109
111
|
//# 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[]>([]);\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: ${id}`);\n if (isJourneyActive) {\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 [isJourneyActive],\n );\n\n const clearJourney = useCallback(() => {\n console.log(`clearJourney: ${currentJourneyId.current}`);\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 console.log(`endJOurney: ${currentJourneyId.current}`);\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 console.log({ addCoachmark: { id, coachmark } });\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 console.log({ addCoachmark: { id, keepPrevActive, delayInMs } });\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 {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,GAClE,CAACG,GAAiBC,CAAkB,IAAIJ,EAAS,EAAK,GACtDK,IAAeC,EAAO,EAAE,GACxBC,IAAmBD,KACnBE,IAAYF,E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CAACD,CAAY;AAAA,EAAA,GAGTc,IAAwCC;AAAA,IAC5C,OAAO;AAAA,MACL,eAAAR;AAAA,MACA,YAAAX;AAAA,MACA,cAAAS;AAAA,MACA,cAAAL;AAAA,MACA,YAAAE;AAAA,MACA,YAAYrB;AAAA,MACZ,yBAAAH;AAAA,MACA,iBAAAK;AAAA,IAAA;AAAA,IAEF;AAAA,MACEwB;AAAA,MACAX;AAAA,MACAS;AAAA,MACAL;AAAA,MACAE;AAAA,MACArB;AAAA,MACAH;AAAA,MACAK;AAAA,IACF;AAAA,EAAA;AAIF,SAAAiC,EAAU,MAAM;AACd,IAAIxC,KAASC,KACXe,EAAmBf,GAAQ;AAAA,MACzB,QAAQD;AAAA,MACR,SAASC;AAAA,MACT,gBAAgB;AAAA,IAAA,CACjB;AAAA,EAEF,GAAA,CAACD,GAAOgB,GAAoBf,CAAM,CAAC,GAGtCuC,EAAU,MAAM;AACd,QAAIzB,GAAuB;AACzB,YAAM0B,IAA2B1B,EAAsB,IAAI,CAAA2B,MAAWA,EAAQ,UAAU;AAExF,MAAAvC,EAA2BsC,CAAwB;AAAA,IACrD;AAAA,EAAA,GACC,CAAC1B,CAAqB,CAAC,GAGvB,gBAAA4B,EAAA/C,EAAe,UAAf,EAAwB,OAAO0C,GAC7B,UAAA;AAAA,IAAAnB,uBACEyB,GAAA,EACE,UAAAvC,EAAc,IAAI,CAACyB,GAAWe,MAC7B,gBAAAC,EAACC,KAAqC,WAAAjB,KAAtB,aAAae,CAAK,EAA0B,CAC7D,GACH;AAAA,IAED9C;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: ${id}`);\n if (isJourneyActive) {\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 [isJourneyActive],\n );\n\n const clearJourney = useCallback(() => {\n console.log(`clearJourney: ${currentJourneyId.current}`);\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 console.log(`endJOurney: ${currentJourneyId.current}`);\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 console.log({ addCoachmark: { id, coachmark } });\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 console.log({ addCoachmark: { id, keepPrevActive, delayInMs } });\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 {coachmarkList.length > 0 && (\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","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,IAA6C,CAAC,EAAE,UAAAC,GAAU,OAAAC,GAAO,QAAAC,QAAa;AACzF,QAAM,CAACC,GAAyBC,CAA0B,IAAIC,EAAuB,CAAE,CAAA,GACjF,CAACC,GAAeC,CAAgB,IAAIF,E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