@cuemath/leap 2.8.62-rj-release-X → 2.8.62
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/game-launcher.js +55 -57
- package/dist/features/circle-games/game-launcher/game-launcher.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 +47 -53
- package/dist/features/circle-games/games/web-view/web-view.js.map +1 -1
- package/dist/features/journey/hooks/use-get-eligible-journeys-via-route.js +6 -9
- 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 +39 -39
- package/dist/features/journey/use-journey/journey-context-provider.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
@@ -1,50 +1,49 @@
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
2
|
-
import { memo as
|
3
|
-
import { LOTTIE as
|
2
|
+
import { memo as g, useRef as x, useCallback as m, useMemo as z, useEffect as D } from "react";
|
3
|
+
import { LOTTIE as U } from "../../../assets/lottie/lottie.js";
|
4
4
|
import { JOURNEY_ID_STUDENT as G } from "../../journey/journey-id/journey-id-student.js";
|
5
|
-
import { useJourney as
|
6
|
-
import { CircularLoader as
|
7
|
-
import
|
8
|
-
import { useCircleSounds as
|
9
|
-
import { CircleSoundKey as
|
10
|
-
import { GAME_LAUNCHER_SIZE as
|
5
|
+
import { useJourney as Y } from "../../journey/use-journey/use-journey.js";
|
6
|
+
import { CircularLoader as B } from "../../ui/loader/circular-loader/circular-loader.js";
|
7
|
+
import K from "../../ui/lottie-animation/lottie-animation.js";
|
8
|
+
import { useCircleSounds as H } from "../hooks/use-circle-sounds/use-circle-sounds.js";
|
9
|
+
import { CircleSoundKey as t } from "../hooks/use-circle-sounds/use-circle-sounds-enums.js";
|
10
|
+
import { GAME_LAUNCHER_SIZE as Z } from "./comps/card-container/constants.js";
|
11
11
|
import { Carousel as V } from "./comps/carousel/carousel.js";
|
12
|
-
import { GAME_LAUNCHER_ASSET_PADDING as
|
13
|
-
import { SegmentedGameCard as
|
14
|
-
import { TablesCard as
|
12
|
+
import { GAME_LAUNCHER_ASSET_PADDING as w } from "./comps/segmented-game-card/constants.js";
|
13
|
+
import { SegmentedGameCard as E } from "./comps/segmented-game-card/segmented-game-card.js";
|
14
|
+
import { TablesCard as X } from "./comps/tables-card/tables-card.js";
|
15
15
|
import { GAME_LAUNCHER_ANALYTICS_EVENTS as S } from "./game-launcher-analytics-events.js";
|
16
|
-
import { useGameLauncherJourney as
|
17
|
-
import { useTableLauncherJourney as
|
18
|
-
import { ProjectType as
|
19
|
-
const M =
|
16
|
+
import { useGameLauncherJourney as j } from "./hooks/use-game-launcher-journey/use-game-launcher-journey.js";
|
17
|
+
import { useTableLauncherJourney as q } from "./hooks/use-table-launcher-journey/use-table-launcher-journey.js";
|
18
|
+
import { ProjectType as n } from "../games/web-view/enums/project-type-enum.js";
|
19
|
+
const M = Z + w, ce = g(
|
20
20
|
({
|
21
21
|
onSegmentClick: r,
|
22
|
-
journeyId:
|
22
|
+
journeyId: u,
|
23
23
|
data: e,
|
24
|
-
isLoading:
|
25
|
-
isTutorialOnboardingDone:
|
24
|
+
isLoading: f,
|
25
|
+
isTutorialOnboardingDone: a,
|
26
26
|
defaultIndex: J = 0,
|
27
|
-
showError: v,
|
28
27
|
onJourneyComplete: C
|
29
28
|
}) => {
|
30
|
-
const
|
29
|
+
const p = x(null), { isJourneyActive: L } = Y(), { playSwipSound: _, play: o } = H(), c = m(
|
31
30
|
(l) => {
|
32
|
-
o(
|
31
|
+
o(t.GAME_CARD_CLICK), r(l, n.TABLE);
|
33
32
|
},
|
34
33
|
[r, o]
|
35
|
-
), A =
|
34
|
+
), A = m(
|
36
35
|
(l) => {
|
37
|
-
l.status !== "completed" && (o(
|
36
|
+
l.status !== "completed" && (o(t.GAME_CARD_CLICK), r(l, n.LESSON));
|
38
37
|
},
|
39
38
|
[r, o]
|
40
|
-
), b =
|
39
|
+
), b = m(
|
41
40
|
(l) => {
|
42
|
-
o(
|
41
|
+
o(t.GAME_CARD_CLICK), r(l, n.GAME);
|
43
42
|
},
|
44
43
|
[r, o]
|
45
|
-
), T =
|
44
|
+
), T = m(
|
46
45
|
(l) => {
|
47
|
-
o(
|
46
|
+
o(t.GAME_CARD_CLICK), r(l, n.PUZZLE);
|
48
47
|
},
|
49
48
|
[r, o]
|
50
49
|
), {
|
@@ -52,20 +51,20 @@ const M = w + X, ae = x(
|
|
52
51
|
lessonRefs: R,
|
53
52
|
puzzleRefs: I,
|
54
53
|
startJourney: P
|
55
|
-
} =
|
56
|
-
carouselRefs:
|
54
|
+
} = j({
|
55
|
+
carouselRefs: p,
|
57
56
|
onSegmentClick: r,
|
58
57
|
onJourneyComplete: C
|
59
|
-
}), { startJourney: N, tableRef: h } =
|
60
|
-
carouselRefs:
|
58
|
+
}), { startJourney: N, tableRef: h } = q({
|
59
|
+
carouselRefs: p,
|
61
60
|
onTableSegmentClick: c,
|
62
61
|
onJourneyComplete: C
|
63
|
-
}),
|
62
|
+
}), v = z(() => {
|
64
63
|
let l = [];
|
65
64
|
return e && (e.lessons && (l = [
|
66
65
|
...l,
|
67
66
|
/* @__PURE__ */ i(
|
68
|
-
|
67
|
+
E,
|
69
68
|
{
|
70
69
|
ref: R,
|
71
70
|
label: e.lessons.label,
|
@@ -83,7 +82,7 @@ const M = w + X, ae = x(
|
|
83
82
|
]), l = [
|
84
83
|
...l,
|
85
84
|
/* @__PURE__ */ i(
|
86
|
-
|
85
|
+
E,
|
87
86
|
{
|
88
87
|
ref: y,
|
89
88
|
label: e.games.label,
|
@@ -99,7 +98,7 @@ const M = w + X, ae = x(
|
|
99
98
|
}
|
100
99
|
),
|
101
100
|
/* @__PURE__ */ i(
|
102
|
-
|
101
|
+
E,
|
103
102
|
{
|
104
103
|
ref: I,
|
105
104
|
label: e.puzzles.label,
|
@@ -117,7 +116,7 @@ const M = w + X, ae = x(
|
|
117
116
|
], e.tables && (l = [
|
118
117
|
...l,
|
119
118
|
/* @__PURE__ */ i(
|
120
|
-
|
119
|
+
X,
|
121
120
|
{
|
122
121
|
ref: h,
|
123
122
|
label: e.tables.label,
|
@@ -137,12 +136,12 @@ const M = w + X, ae = x(
|
|
137
136
|
T,
|
138
137
|
h,
|
139
138
|
c
|
140
|
-
]),
|
139
|
+
]), O = z(
|
141
140
|
() => [
|
142
141
|
/* @__PURE__ */ i(
|
143
|
-
|
142
|
+
K,
|
144
143
|
{
|
145
|
-
src:
|
144
|
+
src: U.SLEEPY_BOI,
|
146
145
|
width: M,
|
147
146
|
height: M
|
148
147
|
}
|
@@ -150,53 +149,52 @@ const M = w + X, ae = x(
|
|
150
149
|
],
|
151
150
|
[]
|
152
151
|
);
|
153
|
-
return
|
154
|
-
if (!(
|
155
|
-
if (e != null && e.puzzles &&
|
152
|
+
return D(() => {
|
153
|
+
if (!(f || !e || L)) {
|
154
|
+
if (e != null && e.puzzles && u === G.CIRCLE_ACTIVITIES_INTRO_JOURNEY) {
|
156
155
|
P(e == null ? void 0 : e.puzzles, !!(e != null && e.lessons));
|
157
156
|
return;
|
158
157
|
}
|
159
|
-
e != null && e.tables &&
|
158
|
+
e != null && e.tables && u === G.CIRCLE_TABLES_INTRO_JOURNEY && N(e == null ? void 0 : e.tables, a);
|
160
159
|
}
|
161
160
|
}, [
|
162
161
|
e,
|
163
162
|
L,
|
164
|
-
p,
|
165
|
-
E,
|
166
163
|
f,
|
164
|
+
a,
|
165
|
+
u,
|
167
166
|
P,
|
168
167
|
N
|
169
|
-
]),
|
168
|
+
]), f ? /* @__PURE__ */ i(B, {}) : e ? /* @__PURE__ */ i(
|
170
169
|
V,
|
171
170
|
{
|
172
|
-
ref:
|
173
|
-
items:
|
171
|
+
ref: p,
|
172
|
+
items: v,
|
173
|
+
defaultIndex: J,
|
174
|
+
onNext: _,
|
175
|
+
onPrev: _,
|
174
176
|
analyticsNext: {
|
175
|
-
analyticsLabel:
|
177
|
+
analyticsLabel: S.NEXT_ACTIVITY
|
176
178
|
},
|
177
179
|
analyticsPrev: {
|
178
|
-
analyticsLabel:
|
180
|
+
analyticsLabel: S.PREV_ACTIVITY
|
179
181
|
}
|
180
182
|
}
|
181
183
|
) : /* @__PURE__ */ i(
|
182
184
|
V,
|
183
185
|
{
|
184
|
-
ref: m,
|
185
186
|
items: O,
|
186
|
-
defaultIndex: J,
|
187
|
-
onNext: _,
|
188
|
-
onPrev: _,
|
189
187
|
analyticsNext: {
|
190
|
-
analyticsLabel:
|
188
|
+
analyticsLabel: ""
|
191
189
|
},
|
192
190
|
analyticsPrev: {
|
193
|
-
analyticsLabel:
|
191
|
+
analyticsLabel: ""
|
194
192
|
}
|
195
193
|
}
|
196
194
|
);
|
197
195
|
}
|
198
196
|
);
|
199
197
|
export {
|
200
|
-
|
198
|
+
ce as GameLauncher
|
201
199
|
};
|
202
200
|
//# sourceMappingURL=game-launcher.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"game-launcher.js","sources":["../../../../src/features/circle-games/game-launcher/game-launcher.tsx"],"sourcesContent":["import type { ICarouselRefs } from './comps/carousel/carousel-types';\nimport type { ITableDetails } from './comps/tables-card/tables-card-types';\nimport type {\n Game,\n Lesson,\n Puzzle,\n} from './dal/use-get-circle-home-details-dal/use-get-circle-home-dal-types';\nimport type { IGameLauncherProps } from './game-launcher-types';\nimport type { FC, ReactNode } from 'react';\n\nimport { memo, useCallback, useEffect, useMemo, useRef } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { JOURNEY_ID_STUDENT } from '../../journey/journey-id/journey-id-student';\nimport { useJourney } from '../../journey/use-journey/use-journey';\nimport { CircularLoader } from '../../ui/loader/circular-loader/circular-loader';\nimport LottieAnimation from '../../ui/lottie-animation/lottie-animation';\nimport { ProjectType } from '../games/web-view/enums';\nimport { useCircleSounds } from '../hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { GAME_LAUNCHER_SIZE } from './comps/card-container/constants';\nimport { Carousel } from './comps/carousel/carousel';\nimport { GAME_LAUNCHER_ASSET_PADDING } from './comps/segmented-game-card/constants';\nimport { SegmentedGameCard } from './comps/segmented-game-card/segmented-game-card';\nimport { TablesCard } from './comps/tables-card/tables-card';\nimport { GAME_LAUNCHER_ANALYTICS_EVENTS } from './game-launcher-analytics-events';\nimport { useGameLauncherJourney } from './hooks/use-game-launcher-journey/use-game-launcher-journey';\nimport { useTableLauncherJourney } from './hooks/use-table-launcher-journey/use-table-launcher-journey';\n\nconst sleepyBoiDimension = GAME_LAUNCHER_SIZE + GAME_LAUNCHER_ASSET_PADDING;\n\nexport const GameLauncher: FC<IGameLauncherProps> = memo(\n ({\n onSegmentClick,\n journeyId,\n data,\n isLoading,\n isTutorialOnboardingDone,\n defaultIndex = 0,\n showError,\n onJourneyComplete,\n }) => {\n const carouselRefs = useRef<ICarouselRefs>(null);\n\n const { isJourneyActive } = useJourney();\n\n const { playSwipSound, play } = useCircleSounds();\n\n const onTableSegmentClick = useCallback(\n (table: ITableDetails) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(table, ProjectType.TABLE);\n },\n [onSegmentClick, play],\n );\n\n const handleLessonSegmentClick = useCallback(\n (lesson: Lesson) => {\n if (lesson.status !== 'completed') {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(lesson, ProjectType.LESSON);\n }\n },\n [onSegmentClick, play],\n );\n\n const handleGameSegmentClick = useCallback(\n (game: Game) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(game, ProjectType.GAME);\n },\n [onSegmentClick, play],\n );\n\n const handlePuzzleSegmentClick = useCallback(\n (puzzle: Puzzle) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(puzzle, ProjectType.PUZZLE);\n },\n [onSegmentClick, play],\n );\n\n const {\n gameRefs,\n lessonRefs,\n puzzleRefs,\n startJourney: startLessonPuzzleGamesJourney,\n } = useGameLauncherJourney({\n carouselRefs,\n onSegmentClick,\n onJourneyComplete,\n });\n\n const { startJourney: startTablesJourney, tableRef } = useTableLauncherJourney({\n carouselRefs,\n onTableSegmentClick,\n onJourneyComplete,\n });\n\n const items = useMemo(() => {\n let itemTypes: ReactNode[] = [];\n\n if (data) {\n if (data.lessons) {\n itemTypes = [\n ...itemTypes,\n <SegmentedGameCard\n ref={lessonRefs}\n label={data.lessons.label}\n value={data.lessons.data.filter(lesson => lesson.status === 'completed').length}\n maxValue={data.lessons.data.length}\n initialValue={data.lessons.initialProgressValue}\n data={data?.lessons.data.map(lesson => ({\n card: lesson.cardLottie,\n name: lesson.name,\n isCompleted: lesson.status === 'completed',\n onPress: () => handleLessonSegmentClick(lesson),\n }))}\n />,\n ];\n }\n\n itemTypes = [\n ...itemTypes,\n <SegmentedGameCard\n ref={gameRefs}\n label={data.games.label}\n value={data.games.data.filter(game => game.isPlayed).length}\n maxValue={data.games.data.length}\n initialValue={data.games.initialProgressValue}\n data={data.games.data.map(game => ({\n card: game.cardLottie,\n name: game.name,\n isCompleted: false,\n onPress: () => handleGameSegmentClick(game),\n }))}\n />,\n <SegmentedGameCard\n ref={puzzleRefs}\n label={data.puzzles.label}\n value={data.puzzles.data.filter(puzzle => puzzle.solved).length}\n maxValue={data.puzzles.data.length}\n initialValue={data.puzzles.initialProgressValue}\n data={data.puzzles.data.map(puzzle => ({\n card: puzzle.cardLottie,\n name: puzzle.name,\n isCompleted: puzzle.solved,\n onPress: () => handlePuzzleSegmentClick(puzzle),\n }))}\n />,\n ];\n\n if (data.tables) {\n itemTypes = [\n ...itemTypes,\n <TablesCard\n ref={tableRef}\n label={data.tables.label}\n data={data.tables.data}\n onPress={onTableSegmentClick}\n openModesOfTable={data.tables.openModesOfTable}\n />,\n ];\n }\n }\n\n return itemTypes;\n }, [\n data,\n gameRefs,\n puzzleRefs,\n lessonRefs,\n handleLessonSegmentClick,\n handleGameSegmentClick,\n handlePuzzleSegmentClick,\n tableRef,\n onTableSegmentClick,\n ]);\n\n const sleepyBoiItem = useMemo(\n () => [\n <LottieAnimation\n src={LOTTIE.SLEEPY_BOI}\n width={sleepyBoiDimension}\n height={sleepyBoiDimension}\n />,\n ],\n [],\n );\n\n // Start game launcher journey only when isLoading has become false and data is available\n useEffect(() => {\n if (isLoading || !data || isJourneyActive) {\n return;\n }\n\n if (data?.puzzles && journeyId === JOURNEY_ID_STUDENT.CIRCLE_ACTIVITIES_INTRO_JOURNEY) {\n startLessonPuzzleGamesJourney(data?.puzzles, !!data?.lessons);\n\n return; // CIRCLE_ACTIVITIES_INTRO_JOURNEY has higher priority\n }\n\n if (data?.tables && journeyId === JOURNEY_ID_STUDENT.CIRCLE_TABLES_INTRO_JOURNEY) {\n startTablesJourney(data?.tables, isTutorialOnboardingDone);\n }\n }, [\n data,\n isJourneyActive,\n isLoading,\n isTutorialOnboardingDone,\n journeyId,\n startLessonPuzzleGamesJourney,\n startTablesJourney,\n ]);\n\n if (isLoading) {\n return <CircularLoader />;\n }\n\n if (showError) {\n return (\n <Carousel\n ref={carouselRefs}\n items={sleepyBoiItem}\n analyticsNext={{\n analyticsLabel: '',\n }}\n analyticsPrev={{\n analyticsLabel: '',\n }}\n />\n );\n }\n\n return (\n <Carousel\n ref={carouselRefs}\n items={items}\n defaultIndex={defaultIndex}\n onNext={playSwipSound}\n onPrev={playSwipSound}\n analyticsNext={{\n analyticsLabel: GAME_LAUNCHER_ANALYTICS_EVENTS.NEXT_ACTIVITY,\n }}\n analyticsPrev={{\n analyticsLabel: GAME_LAUNCHER_ANALYTICS_EVENTS.PREV_ACTIVITY,\n }}\n />\n );\n },\n);\n"],"names":["sleepyBoiDimension","GAME_LAUNCHER_SIZE","GAME_LAUNCHER_ASSET_PADDING","GameLauncher","memo","onSegmentClick","journeyId","data","isLoading","isTutorialOnboardingDone","defaultIndex","showError","onJourneyComplete","carouselRefs","useRef","isJourneyActive","useJourney","playSwipSound","play","useCircleSounds","onTableSegmentClick","useCallback","table","CircleSoundKey","ProjectType","handleLessonSegmentClick","lesson","handleGameSegmentClick","game","handlePuzzleSegmentClick","puzzle","gameRefs","lessonRefs","puzzleRefs","startLessonPuzzleGamesJourney","useGameLauncherJourney","startTablesJourney","tableRef","useTableLauncherJourney","items","useMemo","itemTypes","jsx","SegmentedGameCard","TablesCard","sleepyBoiItem","LottieAnimation","LOTTIE","useEffect","JOURNEY_ID_STUDENT","CircularLoader","Carousel","GAME_LAUNCHER_ANALYTICS_EVENTS"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,MAAMA,IAAqBC,IAAqBC,GAEnCC,KAAuCC;AAAA,EAClD,CAAC;AAAA,IACC,gBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,WAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,WAAAC;AAAA,IACA,mBAAAC;AAAA,EAAA,MACI;AACE,UAAAC,IAAeC,EAAsB,IAAI,GAEzC,EAAE,iBAAAC,MAAoBC,KAEtB,EAAE,eAAAC,GAAe,MAAAC,EAAK,IAAIC,EAAgB,GAE1CC,IAAsBC;AAAA,MAC1B,CAACC,MAAyB;AACxB,QAAAJ,EAAKK,EAAe,eAAe,GACpBlB,EAAAiB,GAAOE,EAAY,KAAK;AAAA,MACzC;AAAA,MACA,CAACnB,GAAgBa,CAAI;AAAA,IAAA,GAGjBO,IAA2BJ;AAAA,MAC/B,CAACK,MAAmB;AACd,QAAAA,EAAO,WAAW,gBACpBR,EAAKK,EAAe,eAAe,GACpBlB,EAAAqB,GAAQF,EAAY,MAAM;AAAA,MAE7C;AAAA,MACA,CAACnB,GAAgBa,CAAI;AAAA,IAAA,GAGjBS,IAAyBN;AAAA,MAC7B,CAACO,MAAe;AACd,QAAAV,EAAKK,EAAe,eAAe,GACpBlB,EAAAuB,GAAMJ,EAAY,IAAI;AAAA,MACvC;AAAA,MACA,CAACnB,GAAgBa,CAAI;A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version":3,"file":"game-launcher.js","sources":["../../../../src/features/circle-games/game-launcher/game-launcher.tsx"],"sourcesContent":["import type { ICarouselRefs } from './comps/carousel/carousel-types';\nimport type { ITableDetails } from './comps/tables-card/tables-card-types';\nimport type {\n Game,\n Lesson,\n Puzzle,\n} from './dal/use-get-circle-home-details-dal/use-get-circle-home-dal-types';\nimport type { IGameLauncherProps } from './game-launcher-types';\nimport type { FC, ReactNode } from 'react';\n\nimport { memo, useCallback, useEffect, useMemo, useRef } from 'react';\n\nimport { LOTTIE } from '../../../assets/lottie/lottie';\nimport { JOURNEY_ID_STUDENT } from '../../journey/journey-id/journey-id-student';\nimport { useJourney } from '../../journey/use-journey/use-journey';\nimport { CircularLoader } from '../../ui/loader/circular-loader/circular-loader';\nimport LottieAnimation from '../../ui/lottie-animation/lottie-animation';\nimport { ProjectType } from '../games/web-view/enums';\nimport { useCircleSounds } from '../hooks/use-circle-sounds/use-circle-sounds';\nimport { CircleSoundKey } from '../hooks/use-circle-sounds/use-circle-sounds-enums';\nimport { GAME_LAUNCHER_SIZE } from './comps/card-container/constants';\nimport { Carousel } from './comps/carousel/carousel';\nimport { GAME_LAUNCHER_ASSET_PADDING } from './comps/segmented-game-card/constants';\nimport { SegmentedGameCard } from './comps/segmented-game-card/segmented-game-card';\nimport { TablesCard } from './comps/tables-card/tables-card';\nimport { GAME_LAUNCHER_ANALYTICS_EVENTS } from './game-launcher-analytics-events';\nimport { useGameLauncherJourney } from './hooks/use-game-launcher-journey/use-game-launcher-journey';\nimport { useTableLauncherJourney } from './hooks/use-table-launcher-journey/use-table-launcher-journey';\n\nconst sleepyBoiDimension = GAME_LAUNCHER_SIZE + GAME_LAUNCHER_ASSET_PADDING;\n\nexport const GameLauncher: FC<IGameLauncherProps> = memo(\n ({\n onSegmentClick,\n journeyId,\n data,\n isLoading,\n isTutorialOnboardingDone,\n defaultIndex = 0,\n onJourneyComplete,\n }) => {\n const carouselRefs = useRef<ICarouselRefs>(null);\n\n const { isJourneyActive } = useJourney();\n\n const { playSwipSound, play } = useCircleSounds();\n\n const onTableSegmentClick = useCallback(\n (table: ITableDetails) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(table, ProjectType.TABLE);\n },\n [onSegmentClick, play],\n );\n\n const handleLessonSegmentClick = useCallback(\n (lesson: Lesson) => {\n if (lesson.status !== 'completed') {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(lesson, ProjectType.LESSON);\n }\n },\n [onSegmentClick, play],\n );\n\n const handleGameSegmentClick = useCallback(\n (game: Game) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(game, ProjectType.GAME);\n },\n [onSegmentClick, play],\n );\n\n const handlePuzzleSegmentClick = useCallback(\n (puzzle: Puzzle) => {\n play(CircleSoundKey.GAME_CARD_CLICK);\n onSegmentClick(puzzle, ProjectType.PUZZLE);\n },\n [onSegmentClick, play],\n );\n\n const {\n gameRefs,\n lessonRefs,\n puzzleRefs,\n startJourney: startLessonPuzzleGamesJourney,\n } = useGameLauncherJourney({\n carouselRefs,\n onSegmentClick,\n onJourneyComplete,\n });\n\n const { startJourney: startTablesJourney, tableRef } = useTableLauncherJourney({\n carouselRefs,\n onTableSegmentClick,\n onJourneyComplete,\n });\n\n const items = useMemo(() => {\n let itemTypes: ReactNode[] = [];\n\n if (data) {\n if (data.lessons) {\n itemTypes = [\n ...itemTypes,\n <SegmentedGameCard\n ref={lessonRefs}\n label={data.lessons.label}\n value={data.lessons.data.filter(lesson => lesson.status === 'completed').length}\n maxValue={data.lessons.data.length}\n initialValue={data.lessons.initialProgressValue}\n data={data?.lessons.data.map(lesson => ({\n card: lesson.cardLottie,\n name: lesson.name,\n isCompleted: lesson.status === 'completed',\n onPress: () => handleLessonSegmentClick(lesson),\n }))}\n />,\n ];\n }\n\n itemTypes = [\n ...itemTypes,\n <SegmentedGameCard\n ref={gameRefs}\n label={data.games.label}\n value={data.games.data.filter(game => game.isPlayed).length}\n maxValue={data.games.data.length}\n initialValue={data.games.initialProgressValue}\n data={data.games.data.map(game => ({\n card: game.cardLottie,\n name: game.name,\n isCompleted: false,\n onPress: () => handleGameSegmentClick(game),\n }))}\n />,\n <SegmentedGameCard\n ref={puzzleRefs}\n label={data.puzzles.label}\n value={data.puzzles.data.filter(puzzle => puzzle.solved).length}\n maxValue={data.puzzles.data.length}\n initialValue={data.puzzles.initialProgressValue}\n data={data.puzzles.data.map(puzzle => ({\n card: puzzle.cardLottie,\n name: puzzle.name,\n isCompleted: puzzle.solved,\n onPress: () => handlePuzzleSegmentClick(puzzle),\n }))}\n />,\n ];\n\n if (data.tables) {\n itemTypes = [\n ...itemTypes,\n <TablesCard\n ref={tableRef}\n label={data.tables.label}\n data={data.tables.data}\n onPress={onTableSegmentClick}\n openModesOfTable={data.tables.openModesOfTable}\n />,\n ];\n }\n }\n\n return itemTypes;\n }, [\n data,\n gameRefs,\n puzzleRefs,\n lessonRefs,\n handleLessonSegmentClick,\n handleGameSegmentClick,\n handlePuzzleSegmentClick,\n tableRef,\n onTableSegmentClick,\n ]);\n\n const sleepyBoiItem = useMemo(\n () => [\n <LottieAnimation\n src={LOTTIE.SLEEPY_BOI}\n width={sleepyBoiDimension}\n height={sleepyBoiDimension}\n />,\n ],\n [],\n );\n\n // Start game launcher journey only when isLoading has become false and data is available\n useEffect(() => {\n if (isLoading || !data || isJourneyActive) {\n return;\n }\n\n if (data?.puzzles && journeyId === JOURNEY_ID_STUDENT.CIRCLE_ACTIVITIES_INTRO_JOURNEY) {\n startLessonPuzzleGamesJourney(data?.puzzles, !!data?.lessons);\n\n return; // CIRCLE_ACTIVITIES_INTRO_JOURNEY has higher priority\n }\n\n if (data?.tables && journeyId === JOURNEY_ID_STUDENT.CIRCLE_TABLES_INTRO_JOURNEY) {\n startTablesJourney(data?.tables, isTutorialOnboardingDone);\n }\n }, [\n data,\n isJourneyActive,\n isLoading,\n isTutorialOnboardingDone,\n journeyId,\n startLessonPuzzleGamesJourney,\n startTablesJourney,\n ]);\n\n if (isLoading) {\n return <CircularLoader />;\n }\n\n if (!data) {\n return (\n <Carousel\n items={sleepyBoiItem}\n analyticsNext={{\n analyticsLabel: '',\n }}\n analyticsPrev={{\n analyticsLabel: '',\n }}\n />\n );\n }\n\n return (\n <Carousel\n ref={carouselRefs}\n items={items}\n defaultIndex={defaultIndex}\n onNext={playSwipSound}\n onPrev={playSwipSound}\n analyticsNext={{\n analyticsLabel: GAME_LAUNCHER_ANALYTICS_EVENTS.NEXT_ACTIVITY,\n }}\n analyticsPrev={{\n analyticsLabel: GAME_LAUNCHER_ANALYTICS_EVENTS.PREV_ACTIVITY,\n }}\n />\n );\n },\n);\n"],"names":["sleepyBoiDimension","GAME_LAUNCHER_SIZE","GAME_LAUNCHER_ASSET_PADDING","GameLauncher","memo","onSegmentClick","journeyId","data","isLoading","isTutorialOnboardingDone","defaultIndex","onJourneyComplete","carouselRefs","useRef","isJourneyActive","useJourney","playSwipSound","play","useCircleSounds","onTableSegmentClick","useCallback","table","CircleSoundKey","ProjectType","handleLessonSegmentClick","lesson","handleGameSegmentClick","game","handlePuzzleSegmentClick","puzzle","gameRefs","lessonRefs","puzzleRefs","startLessonPuzzleGamesJourney","useGameLauncherJourney","startTablesJourney","tableRef","useTableLauncherJourney","items","useMemo","itemTypes","jsx","SegmentedGameCard","TablesCard","sleepyBoiItem","LottieAnimation","LOTTIE","useEffect","JOURNEY_ID_STUDENT","CircularLoader","Carousel","GAME_LAUNCHER_ANALYTICS_EVENTS"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,MAAMA,IAAqBC,IAAqBC,GAEnCC,KAAuCC;AAAA,EAClD,CAAC;AAAA,IACC,gBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,WAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,mBAAAC;AAAA,EAAA,MACI;AACE,UAAAC,IAAeC,EAAsB,IAAI,GAEzC,EAAE,iBAAAC,MAAoBC,KAEtB,EA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,IAAA,CACD,GAEG3B,sBACMyC,GAAe,CAAA,CAAA,IAGpB1C,IAeH,gBAAAkC;AAAA,MAACS;AAAA,MAAA;AAAA,QACC,KAAKtC;AAAA,QACL,OAAA0B;AAAA,QACA,cAAA5B;AAAA,QACA,QAAQM;AAAA,QACR,QAAQA;AAAA,QACR,eAAe;AAAA,UACb,gBAAgBmC,EAA+B;AAAA,QACjD;AAAA,QACA,eAAe;AAAA,UACb,gBAAgBA,EAA+B;AAAA,QACjD;AAAA,MAAA;AAAA,IAAA,IAxBA,gBAAAV;AAAA,MAACS;AAAA,MAAA;AAAA,QACC,OAAON;AAAA,QACP,eAAe;AAAA,UACb,gBAAgB;AAAA,QAClB;AAAA,QACA,eAAe;AAAA,UACb,gBAAgB;AAAA,QAClB;AAAA,MAAA;AAAA,IAAA;AAAA,EAoBR;AACF;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"web-view-types.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view-types.ts"],"sourcesContent":["import type { IAvatarLayer } from '../../../ui/avatar/avatar-types';\nimport type { TUserTypes } from '../../../ui/types';\nimport type { WebViewEvent, ProjectOutcome, ProjectType } from './enums';\nimport type { WEBVIEW_ANALYTICS_EVENTS } from './web-view-analytics-events';\nimport type { IframeHTMLAttributes } from 'react';\n\nexport interface IPlayer {\n id: string;\n username: string;\n grade?: string;\n avatar?: IAvatarLayer[] | null;\n playerType: TUserTypes;\n countryCode: string;\n}\n\ninterface ISyncableWebGameProps {\n joinByRoomId?: string;\n enableSync?: boolean; // applicable for all except multiplayer games and tables\n}\n\ninterface IBaseWebGameProps {\n projectId: string;\n variant: string;\n projectType: ProjectType;\n enableCloseButton?: boolean;\n}\n\nexport interface IMultiplayerWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n enablePlayerTurnIndicators?: boolean;\n}\n\nexport interface IPuzzleWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n question: string;\n askHintPermission?: boolean;\n}\n\nexport interface ILessonWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n miniGameIdentifier: string;\n sessionId: string;\n targetQuestions: number;\n}\n\nexport interface ITableWebGameProps extends IBaseWebGameProps {\n tableNumber: number;\n infiniteModeHighScore?: number;\n}\n\nexport interface IVibrationPattern {\n pattern: number[] | number;\n}\n\nexport enum IStatsToAwardErrorCode {\n DEFAULT = 'default',\n SUCCESS = 'success',\n FAIL = 'fail',\n}\n\nexport interface IPlayerStats {\n points: number;\n accuracy: number;\n timeSpent: number;\n streakDays: number;\n streakStatusToday: 'pending' | 'completed';\n errorCode: IStatsToAwardErrorCode;\n outcome: ProjectOutcome;\n value: string;\n starEligibleTime?: number;\n starEligibleAccuracy?: number;\n starRewarded?: boolean;\n}\n\nexport interface IInfoMessage {\n message: string;\n position: 'top' | 'bottom';\n}\n\nexport interface ITrackEvent {\n eventName: typeof WEBVIEW_ANALYTICS_EVENTS;\n properties: Record<string, unknown>;\n}\n\nexport interface IWebViewProps extends IframeHTMLAttributes<HTMLIFrameElement> {\n baseUrl: string;\n projectDetails:\n | IMultiplayerWebGameProps\n | IPuzzleWebGameProps\n | ILessonWebGameProps\n | ITableWebGameProps;\n parentDomain: string;\n playerDetails: IPlayer;\n onBack?: () => void;\n onGameLoad?: () => void;\n onGamePlayFinish?: (playerStats: IPlayerStats) => void;\n handleInfoMessage?: (infoMessage: IInfoMessage) => void;\n}\n\nexport interface IMessageProps {\n event: `${WebViewEvent}`;\n payload: IVibrationPattern | IPlayerStats | IInfoMessage | null;\n}\n"],"names":["IStatsToAwardErrorCode"],"mappings":"
|
1
|
+
{"version":3,"file":"web-view-types.js","sources":["../../../../../src/features/circle-games/games/web-view/web-view-types.ts"],"sourcesContent":["import type { IAvatarLayer } from '../../../ui/avatar/avatar-types';\nimport type { TUserTypes } from '../../../ui/types';\nimport type { WebViewEvent, ProjectOutcome, ProjectType } from './enums';\nimport type { WEBVIEW_ANALYTICS_EVENTS } from './web-view-analytics-events';\nimport type { IframeHTMLAttributes } from 'react';\n\nexport interface IPlayer {\n id: string;\n username: string;\n grade?: string;\n avatar?: IAvatarLayer[] | null;\n playerType: TUserTypes;\n countryCode: string;\n isAdmin?: boolean;\n}\n\ninterface ISyncableWebGameProps {\n joinByRoomId?: string;\n enableSync?: boolean; // applicable for all except multiplayer games and tables\n}\n\ninterface IBaseWebGameProps {\n projectId: string;\n variant: string;\n projectType: ProjectType;\n enableCloseButton?: boolean;\n}\n\nexport interface IMultiplayerWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n enablePlayerTurnIndicators?: boolean;\n}\n\nexport interface IPuzzleWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n question: string;\n askHintPermission?: boolean;\n}\n\nexport interface ILessonWebGameProps extends IBaseWebGameProps, ISyncableWebGameProps {\n miniGameIdentifier: string;\n sessionId: string;\n targetQuestions: number;\n}\n\nexport interface ITableWebGameProps extends IBaseWebGameProps {\n tableNumber: number;\n infiniteModeHighScore?: number;\n}\n\nexport interface IVibrationPattern {\n pattern: number[] | number;\n}\n\nexport enum IStatsToAwardErrorCode {\n DEFAULT = 'default',\n SUCCESS = 'success',\n FAIL = 'fail',\n}\n\nexport interface IPlayerStats {\n points: number;\n accuracy: number;\n timeSpent: number;\n streakDays: number;\n streakStatusToday: 'pending' | 'completed';\n errorCode: IStatsToAwardErrorCode;\n outcome: ProjectOutcome;\n value: string;\n starEligibleTime?: number;\n starEligibleAccuracy?: number;\n starRewarded?: boolean;\n}\n\nexport interface IInfoMessage {\n message: string;\n position: 'top' | 'bottom';\n}\n\nexport interface ITrackEvent {\n eventName: typeof WEBVIEW_ANALYTICS_EVENTS;\n properties: Record<string, unknown>;\n}\n\nexport interface IWebViewProps extends IframeHTMLAttributes<HTMLIFrameElement> {\n baseUrl: string;\n projectDetails:\n | IMultiplayerWebGameProps\n | IPuzzleWebGameProps\n | ILessonWebGameProps\n | ITableWebGameProps;\n parentDomain: string;\n playerDetails: IPlayer;\n onBack?: () => void;\n onGameLoad?: () => void;\n onGamePlayFinish?: (playerStats: IPlayerStats) => void;\n handleInfoMessage?: (infoMessage: IInfoMessage) => void;\n}\n\nexport interface IMessageProps {\n event: `${WebViewEvent}`;\n payload: IVibrationPattern | IPlayerStats | IInfoMessage | null;\n}\n"],"names":["IStatsToAwardErrorCode"],"mappings":"AAoDY,IAAAA,sBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,UAAU,WACVA,EAAA,OAAO,QAHGA,IAAAA,KAAA,CAAA,CAAA;"}
|
@@ -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 V, useRef as G, useMemo as R, useCallback as v, useImperativeHandle as $, useEffect as B } from "react";
|
3
|
+
import { useUIContext as J } from "../../../ui/context/context.js";
|
4
|
+
import { ALLOWED_ORIGIN as C } 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 Z = V((I, b) => {
|
8
8
|
const {
|
9
|
-
baseUrl:
|
10
|
-
projectDetails:
|
11
|
-
playerDetails:
|
9
|
+
baseUrl: y,
|
10
|
+
projectDetails: T,
|
11
|
+
playerDetails: w,
|
12
12
|
onGameLoad: a,
|
13
|
-
onGamePlayFinish:
|
14
|
-
handleInfoMessage:
|
13
|
+
onGamePlayFinish: c,
|
14
|
+
handleInfoMessage: p,
|
15
15
|
onBack: f,
|
16
|
-
parentDomain:
|
17
|
-
...
|
18
|
-
} =
|
16
|
+
parentDomain: g,
|
17
|
+
...L
|
18
|
+
} = I, l = G(null), N = R(() => w, [w]), t = R(() => T, [T]);
|
19
19
|
let A = "";
|
20
|
-
const { onEvent: O } =
|
20
|
+
const { onEvent: O } = J();
|
21
21
|
t.projectType === s.LESSON && (A = t.miniGameIdentifier);
|
22
|
-
const m =
|
23
|
-
const { enableCloseButton:
|
22
|
+
const m = v(() => {
|
23
|
+
const { enableCloseButton: i = !0 } = t;
|
24
24
|
let e = {
|
25
|
-
enableCloseButton:
|
25
|
+
enableCloseButton: i
|
26
26
|
};
|
27
27
|
return t.projectType === s.GAME && (e = {
|
28
28
|
...e,
|
@@ -37,66 +37,60 @@ const F = G((C, I) => {
|
|
37
37
|
...e,
|
38
38
|
...t
|
39
39
|
}), e;
|
40
|
-
}, [t]),
|
40
|
+
}, [t]), d = v(() => {
|
41
41
|
var e, r;
|
42
|
-
const
|
42
|
+
const i = 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: i
|
47
47
|
}),
|
48
|
-
|
48
|
+
C
|
49
49
|
);
|
50
|
-
}, [m]),
|
50
|
+
}, [m]), D = v(() => {
|
51
51
|
var e, r;
|
52
|
-
const
|
52
|
+
const i = 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: N,
|
58
|
+
projectConfig: i,
|
59
|
+
parentDomain: g
|
60
60
|
}
|
61
61
|
}),
|
62
|
-
|
62
|
+
C
|
63
63
|
);
|
64
|
-
}, [
|
65
|
-
|
66
|
-
const
|
67
|
-
var j,
|
68
|
-
const r = e.data,
|
69
|
-
if (
|
70
|
-
const { pattern: u } =
|
71
|
-
(S = (j = window.navigator).vibrate) == null ||
|
64
|
+
}, [N, m, g]);
|
65
|
+
$(b, () => l.current, []), B(() => {
|
66
|
+
const i = (e) => {
|
67
|
+
var j, _;
|
68
|
+
const r = e.data, S = typeof r == "string" ? JSON.parse(r) : r, { event: n, payload: E = null } = S;
|
69
|
+
if (n === o.VIBRATE) {
|
70
|
+
const { pattern: u } = E;
|
71
|
+
window.ReactNativeWebView ? window.ReactNativeWebView.postMessage(JSON.stringify(S)) : (_ = (j = window.navigator).vibrate) == null || _.call(j, u);
|
72
72
|
}
|
73
|
-
if (
|
74
|
-
const { eventName: u, properties:
|
75
|
-
O(u,
|
73
|
+
if (n === o.GAME_BACK && (f == null || f()), n === o.HIDE_LOADER && (a == null || a()), n === o.LOAD_DATA_FROM_APP && (d == null || d()), n === o.GET_CONFIG && D(), n === o.UPDATE_STATS && (c == null || c(E)), n === o.SHOW_SNACKBAR && (p == null || p(E)), n === o.TRACK_EVENT) {
|
74
|
+
const { eventName: u, properties: W } = E;
|
75
|
+
O(u, W);
|
76
76
|
}
|
77
77
|
};
|
78
|
-
return window.addEventListener("message",
|
79
|
-
window.removeEventListener("message",
|
78
|
+
return window.addEventListener("message", i), () => {
|
79
|
+
window.removeEventListener("message", i);
|
80
80
|
};
|
81
81
|
}, [
|
82
|
-
c,
|
83
|
-
f,
|
84
82
|
p,
|
83
|
+
f,
|
84
|
+
c,
|
85
85
|
a,
|
86
|
-
|
87
|
-
|
86
|
+
D,
|
87
|
+
d,
|
88
88
|
O
|
89
|
-
])
|
90
|
-
|
91
|
-
|
92
|
-
...R,
|
93
|
-
ref: l,
|
94
|
-
src: `${L}/play-game/${t.projectId}/${t.variant}${A ? `/${A}` : ""}?version=2`,
|
95
|
-
allow: "autoplay"
|
96
|
-
}
|
97
|
-
);
|
89
|
+
]);
|
90
|
+
const M = w.isAdmin ? y : `${y}/play-game/${t.projectId}/${t.variant}${A ? `/${A}` : ""}`;
|
91
|
+
return /* @__PURE__ */ P("iframe", { ...L, ref: l, src: `${M}?version=2`, allow: "autoplay" });
|
98
92
|
});
|
99
93
|
export {
|
100
|
-
|
94
|
+
Z as WebView
|
101
95
|
};
|
102
96
|
//# 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":["declare global {\n interface IReactNativeWebview {\n postMessage: (data: string) => void;\n }\n\n interface Window {\n ReactNativeWebView?: IReactNativeWebview;\n }\n}\n\nimport 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 if (window.ReactNativeWebView) {\n window.ReactNativeWebView.postMessage(JSON.stringify(parsedData));\n } else {\n window.navigator.vibrate?.(pattern);\n }\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 const url = playerDetails.isAdmin\n ? baseUrl\n : `${baseUrl}/play-game/${memoizedProjectDetails.projectId}/${memoizedProjectDetails.variant}${\n miniGameIdentifier ? `/${miniGameIdentifier}` : ''\n }`;\n\n return <iframe {...rest} ref={webViewRef} src={`${url}?version=2`} allow=\"autoplay\" />;\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","url","jsx"],"mappings":";;;;;;AA6BO,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,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IA,CAAkB,KAAK,EAClD;AAEG,SAAA,gBAAAyB,EAAC,UAAQ,EAAA,GAAG/B,GAAM,KAAKC,GAAY,KAAK,GAAG6B,CAAG,cAAc,OAAM,WAAW,CAAA;AACtF,CAAC;"}
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import { useMemo as
|
2
|
-
import { useJourney as
|
3
|
-
const
|
4
|
-
const { userCompletedJourneyIds: e } =
|
5
|
-
return r(
|
6
|
-
() => i.filter((o) => !(e != null && e.includes(o))),
|
7
|
-
[i, e]
|
8
|
-
);
|
1
|
+
import { useMemo as i } from "react";
|
2
|
+
import { useJourney as s } from "../use-journey/use-journey.js";
|
3
|
+
const l = (r) => {
|
4
|
+
const { userCompletedJourneyIds: e } = s();
|
5
|
+
return i(() => Array.isArray(e) ? r.filter((o) => !e.includes(o)) : [], [r, e]);
|
9
6
|
};
|
10
7
|
export {
|
11
|
-
|
8
|
+
l as useGetEligibleJourneysViaRoute
|
12
9
|
};
|
13
10
|
//# 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(\n ()
|
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 if (!Array.isArray(userCompletedJourneyIds)) return [];\n\n return routeJourneyIds.filter(journeyId => !userCompletedJourneyIds.includes(journeyId));\n }, [routeJourneyIds, userCompletedJourneyIds]);\n\n return eligibleJourneys;\n};\n"],"names":["useGetEligibleJourneysViaRoute","routeJourneyIds","userCompletedJourneyIds","useJourney","useMemo","journeyId"],"mappings":";;AAMa,MAAAA,IAAiC,CAACC,MAAkC;AACzE,QAAA,EAAE,yBAAAC,MAA4BC;AAQ7B,SANkBC,EAAQ,MAC1B,MAAM,QAAQF,CAAuB,IAEnCD,EAAgB,OAAO,CAAAI,MAAa,CAACH,EAAwB,SAASG,CAAS,CAAC,IAFnC,CAAA,GAGnD,CAACJ,GAAiBC,CAAuB,CAAC;AAG/C;"}
|
@@ -1,100 +1,100 @@
|
|
1
1
|
import { jsxs as O, jsx as w } from "react/jsx-runtime";
|
2
|
-
import { createContext as U, useState as h, useRef as
|
2
|
+
import { createContext as U, useState as h, useRef as k, useCallback as l, useMemo as q, useEffect as R } from "react";
|
3
3
|
import { Coachmark as D } from "../comps/coachmark/coachmark.js";
|
4
4
|
import { usePostUserJourney as L, useGetUserJourney as N } from "../user-journey-api/user-journey-api.js";
|
5
5
|
import { Overlay as M } from "./journey-styled.js";
|
6
|
-
const z = U(null), H = ({ children: T, appId: s, userId:
|
7
|
-
const [
|
8
|
-
(e,
|
6
|
+
const z = U(null), H = ({ children: T, appId: s, userId: o }) => {
|
7
|
+
const [x, p] = h(null), [c, a] = h([]), [J, v] = h(!1), m = k(-1), t = k(), d = k([]), { post: _ } = L(), { data: f = null, get: g } = N(), A = l(
|
8
|
+
(e, r) => {
|
9
9
|
if (c.length > 0) {
|
10
10
|
console.error(
|
11
|
-
`setJourney: Other Journey is already active, Current Journey: ${
|
11
|
+
`setJourney: Other Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}`
|
12
12
|
);
|
13
13
|
return;
|
14
14
|
}
|
15
|
-
|
15
|
+
v(!0), t.current = e, m.current = -1, a([...r]);
|
16
16
|
},
|
17
17
|
[c.length]
|
18
18
|
), u = l(() => {
|
19
19
|
d.current.forEach((e) => {
|
20
20
|
clearTimeout(e);
|
21
|
-
}), d.current = [],
|
21
|
+
}), d.current = [], t.current = void 0, m.current = -1, a([]), v(!1);
|
22
22
|
}, []), $ = l(
|
23
23
|
(e) => {
|
24
|
-
u(),
|
24
|
+
u(), p((r) => r && !r.includes(e) ? [...r, e] : r), _({
|
25
25
|
app_id: s,
|
26
|
-
user_id:
|
26
|
+
user_id: o,
|
27
27
|
journey_id: e,
|
28
28
|
journey_status: "COMPLETED"
|
29
29
|
});
|
30
30
|
},
|
31
|
-
[s, u, _,
|
32
|
-
),
|
33
|
-
if (!
|
31
|
+
[s, u, _, o]
|
32
|
+
), E = l((e, r) => {
|
33
|
+
if (!t.current || e !== t.current) {
|
34
34
|
console.error(
|
35
|
-
|
35
|
+
t.current ? `A Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}` : "addCoachmark was called before setJourney and Journey ID is undefined"
|
36
36
|
);
|
37
37
|
return;
|
38
38
|
}
|
39
|
-
a((
|
40
|
-
}, []),
|
41
|
-
(e,
|
42
|
-
if (!
|
39
|
+
a((y) => [...y, r]);
|
40
|
+
}, []), P = l(
|
41
|
+
(e, r = !1, y = 0) => {
|
42
|
+
if (!t.current || e !== t.current) {
|
43
43
|
console.error(
|
44
|
-
|
44
|
+
t.current ? "nextCoachmark was called before setJourney" : `A Journey is already active, Current Journey: ${t.current}, New Journey Request: ${e}`
|
45
45
|
);
|
46
46
|
return;
|
47
47
|
}
|
48
|
-
|
49
|
-
const
|
50
|
-
clearTimeout(
|
51
|
-
const
|
48
|
+
y !== 0 && a((n) => n.map((i) => ({ ...i, isActive: !1 })));
|
49
|
+
const j = setTimeout(() => {
|
50
|
+
clearTimeout(j);
|
51
|
+
const n = m.current + 1;
|
52
52
|
a((i) => {
|
53
|
-
if (
|
53
|
+
if (n >= i.length || i.length === 0)
|
54
54
|
return u(), [];
|
55
|
-
|
55
|
+
m.current = n;
|
56
56
|
const C = [...i];
|
57
|
-
return C[
|
57
|
+
return C[n].isActive = !0, n > 0 && (C[n - 1].isActive = r), C;
|
58
58
|
});
|
59
|
-
},
|
60
|
-
d.current.push(
|
59
|
+
}, y);
|
60
|
+
d.current.push(j);
|
61
61
|
},
|
62
62
|
[u]
|
63
63
|
), b = q(
|
64
64
|
() => ({
|
65
|
-
nextCoachmark:
|
65
|
+
nextCoachmark: P,
|
66
66
|
setJourney: A,
|
67
|
-
addCoachmark:
|
67
|
+
addCoachmark: E,
|
68
68
|
clearJourney: u,
|
69
69
|
endJourney: $,
|
70
70
|
coachmarks: c,
|
71
|
-
userCompletedJourneyIds:
|
71
|
+
userCompletedJourneyIds: x,
|
72
72
|
isJourneyActive: J
|
73
73
|
}),
|
74
74
|
[
|
75
|
-
|
75
|
+
P,
|
76
76
|
A,
|
77
|
-
|
77
|
+
E,
|
78
78
|
u,
|
79
79
|
$,
|
80
80
|
c,
|
81
|
-
|
81
|
+
x,
|
82
82
|
J
|
83
83
|
]
|
84
84
|
);
|
85
85
|
return R(() => {
|
86
|
-
s &&
|
86
|
+
s && o && g(o, {
|
87
87
|
app_id: s,
|
88
|
-
user_id:
|
88
|
+
user_id: o,
|
89
89
|
journey_status: "COMPLETED"
|
90
90
|
});
|
91
|
-
}, [s, g,
|
91
|
+
}, [s, g, o]), R(() => {
|
92
92
|
if (f) {
|
93
|
-
const e = f.map((
|
94
|
-
|
93
|
+
const e = f.map((r) => r.journey_id);
|
94
|
+
p(e);
|
95
95
|
}
|
96
96
|
}, [f]), /* @__PURE__ */ O(z.Provider, { value: b, children: [
|
97
|
-
J && /* @__PURE__ */ w(M, { about: "journey-overlay", "data-testid":
|
97
|
+
J && /* @__PURE__ */ w(M, { about: "journey-overlay", "data-testid": t.current, children: c.map((e, r) => /* @__PURE__ */ w(D, { coachmark: e }, `coachmark-${r}`)) }),
|
98
98
|
T
|
99
99
|
] });
|
100
100
|
};
|
@@ -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 { 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 => [...prev, journeyId]);\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,IAA6C,CAAC,EAAE,UAAAC,GAAU,OAAAC,GAAO,QAAAC,QAAa;AACzF,QAAM,CAACC,GAAyBC,CAA0B,IAAIC,EAAuB,GAC/E,CAACC,GAAeC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ACA,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[] | 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,IAA6C,CAAC,EAAE,UAAAC,GAAU,OAAAC,GAAO,QAAAC,QAAa;AACzF,QAAM,CAACC,GAAyBC,CAA0B,IAAIC,EAA8B,IAAI,GAC1F,CAACC,GAAeC,CAAgB,IAAIF,EAA4B,CAAE,CAAA,GAClE,CAACG,GAAiBC,CAAkB,IAAIJ,EAAS,EAAK,GACtDK,IAAeC,EAAO,EAAE,GACxBC,IAAmBD,KACnBE,IAAYF,EAAwC,CAAA,CAAE,GAEtD,EAAE,MAAMG,EAAsB,IAAIC,EAAmB,GACrD,EAAE,MAAMC,IAAwB,MAAM,KAAKC,EAAA,IAAuBC,KAElEC,IAAaC;AAAA,IACjB,CAACC,GAAgBC,MAAkC;AAC7C,UAAAhB,EAAc,SAAS,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,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;"}
|
package/dist/index.d.ts
CHANGED
@@ -1111,7 +1111,6 @@ declare interface IGameLauncherProps {
|
|
1111
1111
|
defaultIndex?: number;
|
1112
1112
|
journeyId?: TJourneyId;
|
1113
1113
|
isTutorialOnboardingDone?: boolean;
|
1114
|
-
showError?: boolean;
|
1115
1114
|
onJourneyComplete: (journeyId: TJourneyId) => void;
|
1116
1115
|
}
|
1117
1116
|
|
@@ -2122,6 +2121,7 @@ export declare interface IPlayer {
|
|
2122
2121
|
avatar?: IAvatarLayer[] | null;
|
2123
2122
|
playerType: TUserTypes;
|
2124
2123
|
countryCode: string;
|
2124
|
+
isAdmin?: boolean;
|
2125
2125
|
}
|
2126
2126
|
|
2127
2127
|
export declare interface IPlayerStats {
|