@cuemath/leap 2.8.61-rj-0 → 2.8.61-rj-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- import { useMemo as m } from "react";
2
- import { useJourney as b } from "../use-journey/use-journey.js";
3
- const t = (i) => {
4
- const { userCompletedJourneyIds: l } = b();
5
- return m(
6
- () => i ? i == null ? void 0 : i.filter((c) => !(l != null && l.includes(c))) : [],
7
- [i, l]
1
+ import { useMemo as i } from "react";
2
+ import { useJourney as s } from "../use-journey/use-journey.js";
3
+ const n = (e) => {
4
+ const { userCompletedJourneyIds: o } = s();
5
+ return i(
6
+ () => e.filter((r) => !o.includes(r)),
7
+ [e, o]
8
8
  );
9
9
  };
10
10
  export {
11
- t as useGetEligibleJourneysViaRoute
11
+ n as useGetEligibleJourneysViaRoute
12
12
  };
13
13
  //# sourceMappingURL=use-get-eligible-journeys-via-route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-get-eligible-journeys-via-route.js","sources":["../../../../src/features/journey/hooks/use-get-eligible-journeys-via-route.tsx"],"sourcesContent":["import type { TJourneyId } from '../journey-id/journey-id-types';\n\nimport { useMemo } from 'react';\n\nimport { useJourney } from '../use-journey/use-journey';\n\n/**\n * Unless the useGetUserJourney API is resolved, this hook will return an empty array.\n * This is because the userCompletedJourneyIds are set from the API response.\n * And Unless the API is resolved, we cannot determine the eligible journeys.\n * So, we return an empty array.\n */\nexport const useGetEligibleJourneysViaRoute = (routeJourneyIds: TJourneyId[]) => {\n const { userCompletedJourneyIds } = useJourney();\n\n const eligibleJourneys: TJourneyId[] = useMemo(\n () =>\n routeJourneyIds\n ? routeJourneyIds?.filter(journeyId => !userCompletedJourneyIds?.includes(journeyId))\n : [],\n [routeJourneyIds, userCompletedJourneyIds],\n );\n\n return eligibleJourneys;\n};\n"],"names":["useGetEligibleJourneysViaRoute","routeJourneyIds","userCompletedJourneyIds","useJourney","useMemo","journeyId"],"mappings":";;AAYa,MAAAA,IAAiC,CAACC,MAAkC;AACzE,QAAA,EAAE,yBAAAC,MAA4BC;AAU7B,SARgCC;AAAA,IACrC,MACEH,IACIA,KAAA,gBAAAA,EAAiB,OAAO,CAAAI,MAAa,EAACH,KAAA,QAAAA,EAAyB,SAASG,OACxE,CAAC;AAAA,IACP,CAACJ,GAAiBC,CAAuB;AAAA,EAAA;AAI7C;"}
1
+ {"version":3,"file":"use-get-eligible-journeys-via-route.js","sources":["../../../../src/features/journey/hooks/use-get-eligible-journeys-via-route.tsx"],"sourcesContent":["import type { TJourneyId } from '../journey-id/journey-id-types';\n\nimport { useMemo } from 'react';\n\nimport { useJourney } from '../use-journey/use-journey';\n\nexport const useGetEligibleJourneysViaRoute = (routeJourneyIds: TJourneyId[]) => {\n const { userCompletedJourneyIds } = useJourney();\n\n const eligibleJourneys = useMemo(\n () => routeJourneyIds.filter(journeyId => !userCompletedJourneyIds.includes(journeyId)),\n [routeJourneyIds, userCompletedJourneyIds],\n );\n\n return eligibleJourneys;\n};\n"],"names":["useGetEligibleJourneysViaRoute","routeJourneyIds","userCompletedJourneyIds","useJourney","useMemo","journeyId"],"mappings":";;AAMa,MAAAA,IAAiC,CAACC,MAAkC;AACzE,QAAA,EAAE,yBAAAC,MAA4BC;AAO7B,SALkBC;AAAA,IACvB,MAAMH,EAAgB,OAAO,CAAAI,MAAa,CAACH,EAAwB,SAASG,CAAS,CAAC;AAAA,IACtF,CAACJ,GAAiBC,CAAuB;AAAA,EAAA;AAI7C;"}
@@ -1,105 +1,109 @@
1
- import { jsxs as U, jsx as w } from "react/jsx-runtime";
2
- import { createContext as b, useState as h, useRef as p, useCallback as l, useMemo as q, useEffect as R } from "react";
3
- import { Coachmark as D } from "../comps/coachmark/coachmark.js";
4
- import { usePostUserJourney as L, useGetUserJourney as N } from "../user-journey-api/user-journey-api.js";
5
- import { Overlay as M } from "./journey-styled.js";
6
- const z = b(null), H = ({ children: T, appId: u, userId: o }) => {
7
- const [v, k] = h([]), [c, s] = h([]), [J, x] = h(!1), a = p(-1), r = p(), d = p([]), { post: _ } = L(), { data: f = null, get: g } = N(), A = l(
8
- (e, t) => {
9
- if (c.length > 0) {
1
+ import { jsxs as b, jsx as P } from "react/jsx-runtime";
2
+ import { createContext as q, useState as h, useRef as g, useCallback as y, useMemo as D, useEffect as j } from "react";
3
+ import { Coachmark as L } from "../comps/coachmark/coachmark.js";
4
+ import { usePostUserJourney as S, 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), Q = ({ children: N, appId: n, userId: s }) => {
7
+ const [k, x] = h([]), [c, a] = h([]), [m, $] = h(!1), J = g(-1), r = g(), d = g([]), { post: p } = S(), {
8
+ data: f = null,
9
+ get: v,
10
+ isProcessing: R
11
+ } = z(), T = (n === "" || f && !R) && c.length > 0, _ = y(
12
+ (e, o) => {
13
+ if (console.log(`setJourney: ${e}`), m) {
10
14
  console.error(
11
15
  `setJourney: Other Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}`
12
16
  );
13
17
  return;
14
18
  }
15
- x(!0), r.current = e, a.current = -1, s([...t]);
19
+ $(!0), r.current = e, J.current = -1, a([...o]);
16
20
  },
17
- [c.length]
18
- ), m = l(() => {
19
- d.current.forEach((e) => {
21
+ [m]
22
+ ), u = y(() => {
23
+ console.log(`clearJourney: ${r.current}`), d.current.forEach((e) => {
20
24
  clearTimeout(e);
21
- }), d.current = [], r.current = void 0, a.current = -1, s([]), x(!1);
22
- }, []), $ = l(
25
+ }), d.current = [], r.current = void 0, J.current = -1, a([]), $(!1);
26
+ }, []), O = y(
23
27
  (e) => {
24
- k((t) => [...t, e]), _({
25
- app_id: u,
26
- user_id: o,
28
+ console.log(`endJOurney: ${r.current}`), x((o) => [...o, e]), p({
29
+ app_id: n,
30
+ user_id: s,
27
31
  journey_id: e,
28
32
  journey_status: "COMPLETED"
29
- }), m();
33
+ }), u();
30
34
  },
31
- [u, m, _, o]
32
- ), E = l((e, t) => {
33
- if (!r.current || e !== r.current) {
35
+ [n, u, p, s]
36
+ ), w = y((e, o) => {
37
+ if (console.log(JSON.stringify({ addCoachmark: { id: e, coachmark: o } })), !r.current || e !== r.current) {
34
38
  console.error(
35
39
  r.current ? `A Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}` : "addCoachmark was called before setJourney and Journey ID is undefined"
36
40
  );
37
41
  return;
38
42
  }
39
- s((y) => [...y, t]);
40
- }, []), P = l(
41
- (e, t = !1, y = 0) => {
42
- if (!r.current || e !== r.current) {
43
+ a((i) => [...i, o]);
44
+ }, []), A = y(
45
+ (e, o = !1, i = 0) => {
46
+ if (console.log(JSON.stringify({ addCoachmark: { id: e, keepPrevActive: o, delayInMs: i } })), !r.current || e !== r.current) {
43
47
  console.error(
44
48
  r.current ? "nextCoachmark was called before setJourney" : `A Journey is already active, Current Journey: ${r.current}, New Journey Request: ${e}`
45
49
  );
46
50
  return;
47
51
  }
48
- y !== 0 && s((n) => n.map((i) => ({ ...i, isActive: !1 })));
49
- const j = setTimeout(() => {
50
- clearTimeout(j);
51
- const n = a.current + 1;
52
- s((i) => {
53
- if (n >= i.length || i.length === 0)
54
- return r.current = void 0, a.current = -1, [];
55
- a.current = n;
56
- const C = [...i];
57
- return C[n].isActive = !0, n > 0 && (C[n - 1].isActive = t), C;
52
+ i !== 0 && a((t) => t.map((l) => ({ ...l, isActive: !1 })));
53
+ const E = setTimeout(() => {
54
+ clearTimeout(E);
55
+ const t = J.current + 1;
56
+ a((l) => {
57
+ if (t >= l.length || l.length === 0)
58
+ return u(), [];
59
+ J.current = t;
60
+ const C = [...l];
61
+ return C[t].isActive = !0, t > 0 && (C[t - 1].isActive = o), C;
58
62
  });
59
- }, y);
60
- d.current.push(j);
63
+ }, i);
64
+ d.current.push(E);
61
65
  },
62
- []
63
- ), O = q(
66
+ [u]
67
+ ), U = D(
64
68
  () => ({
65
- nextCoachmark: P,
66
- setJourney: A,
67
- addCoachmark: E,
68
- clearJourney: m,
69
- endJourney: $,
69
+ nextCoachmark: A,
70
+ setJourney: _,
71
+ addCoachmark: w,
72
+ clearJourney: u,
73
+ endJourney: O,
70
74
  coachmarks: c,
71
- userCompletedJourneyIds: v,
72
- isJourneyActive: J
75
+ userCompletedJourneyIds: k,
76
+ isJourneyActive: m
73
77
  }),
74
78
  [
75
- P,
76
79
  A,
77
- E,
78
- m,
79
- $,
80
+ _,
81
+ w,
82
+ u,
83
+ O,
80
84
  c,
81
- v,
82
- J
85
+ k,
86
+ m
83
87
  ]
84
88
  );
85
- return R(() => {
86
- u && o && g(o, {
87
- app_id: u,
88
- user_id: o,
89
+ return j(() => {
90
+ n && s && v(s, {
91
+ app_id: n,
92
+ user_id: s,
89
93
  journey_status: "COMPLETED"
90
94
  });
91
- }, [u, g, o]), R(() => {
95
+ }, [n, v, s]), j(() => {
92
96
  if (f) {
93
- const e = f.map((t) => t.journey_id);
94
- k(e);
97
+ const e = f.map((o) => o.journey_id);
98
+ x(e);
95
99
  }
96
- }, [f]), /* @__PURE__ */ U(z.Provider, { value: O, children: [
97
- J && /* @__PURE__ */ w(M, { children: c.map((e, t) => /* @__PURE__ */ w(D, { coachmark: e }, `coachmark-${t}`)) }),
98
- T
100
+ }, [f]), /* @__PURE__ */ b(M.Provider, { value: U, children: [
101
+ T && /* @__PURE__ */ P(G, { children: c.map((e, o) => /* @__PURE__ */ P(L, { coachmark: e }, `coachmark-${o}`)) }),
102
+ N
99
103
  ] });
100
104
  };
101
105
  export {
102
- z as JourneyContext,
103
- H as JourneyProvider
106
+ M as JourneyContext,
107
+ Q as JourneyProvider
104
108
  };
105
109
  //# sourceMappingURL=journey-context-provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"journey-context-provider.js","sources":["../../../../src/features/journey/use-journey/journey-context-provider.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { TJourneyId } from '../journey-id/journey-id-types';\nimport type {\n ICoachmarkProps,\n IJourneyContext,\n IJourneyProviderProps,\n} from './journey-context-types';\nimport type { FC } from 'react';\n\nimport { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { Coachmark } from '../comps/coachmark/coachmark';\nimport { useGetUserJourney, usePostUserJourney } from '../user-journey-api/user-journey-api';\nimport * as S from './journey-styled';\n\nexport const JourneyContext = createContext<IJourneyContext | null>(null);\n\nexport const JourneyProvider: FC<IJourneyProviderProps> = ({ children, appId, userId }) => {\n const [userCompletedJourneyIds, setUserCompletedJourneyIds] = useState<TJourneyId[]>([]);\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 setUserCompletedJourneyIds(prev => [...prev, journeyId]);\n postJourneyCompletion({\n app_id: appId,\n user_id: userId,\n journey_id: journeyId,\n journey_status: 'COMPLETED',\n });\n clearJourney();\n },\n [appId, clearJourney, postJourneyCompletion, userId],\n );\n\n const addCoachmark = useCallback((id: TJourneyId, coachmark: ICoachmarkProps) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`\n : `addCoachmark was called before setJourney and Journey ID is undefined`,\n );\n\n return;\n }\n\n setCoachmarkList(prev => [...prev, coachmark]);\n }, []);\n\n const nextCoachmark = useCallback(\n (id: TJourneyId, keepPrevActive: boolean = false, delayInMs: number = 0) => {\n if (!currentJourneyId.current || id !== currentJourneyId.current) {\n console.error(\n currentJourneyId.current\n ? `nextCoachmark was called before setJourney`\n : `A Journey is already active, Current Journey: ${currentJourneyId.current}, New Journey Request: ${id}`,\n );\n\n return;\n }\n\n if (delayInMs !== 0) {\n // If delay is not 0, we will hide all them coachmarks and reveal only after the delay\n setCoachmarkList(prevList => {\n return prevList.map((item: ICoachmarkProps) => {\n return { ...item, isActive: false };\n });\n });\n }\n\n const timer = setTimeout(() => {\n clearTimeout(timer);\n const currIndex = currentIndex.current + 1;\n\n setCoachmarkList(prevList => {\n // Finish onboarding\n if (currIndex >= prevList.length || prevList.length === 0) {\n currentJourneyId.current = undefined;\n currentIndex.current = -1;\n\n return [];\n }\n\n currentIndex.current = currIndex;\n const updatedCoachmarkList = [...prevList];\n\n (updatedCoachmarkList[currIndex] as ICoachmarkProps).isActive = true;\n\n if (currIndex > 0) {\n (updatedCoachmarkList[currIndex - 1] as ICoachmarkProps).isActive = keepPrevActive;\n }\n\n return updatedCoachmarkList;\n });\n }, delayInMs);\n\n timerRefs.current.push(timer);\n },\n [],\n );\n\n const memoizedContextValue: IJourneyContext = useMemo(\n () => ({\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarks: coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n }),\n [\n nextCoachmark,\n setJourney,\n addCoachmark,\n clearJourney,\n endJourney,\n coachmarkList,\n userCompletedJourneyIds,\n isJourneyActive,\n ],\n );\n\n // Get the initial state of incompleteJourneys\n useEffect(() => {\n if (appId && userId) {\n getJourneyProgress(userId, {\n app_id: appId,\n user_id: userId,\n journey_status: 'COMPLETED',\n });\n }\n }, [appId, getJourneyProgress, userId]);\n\n // Set the data to context state initially\n useEffect(() => {\n if (userCompletedJourneys) {\n const completedUserJourneysIds = userCompletedJourneys.map(journey => journey.journey_id);\n\n setUserCompletedJourneyIds(completedUserJourneysIds);\n }\n }, [userCompletedJourneys]);\n\n return (\n <JourneyContext.Provider value={memoizedContextValue}>\n {isJourneyActive && (\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","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","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,EAAwC,CAAA,CAAE,GAEtD,EAAE,MAAMG,EAAsB,IAAIC,EAAmB,GACrD,EAAE,MAAMC,IAAwB,M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,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,IAAA7B,uBACEmC,GAAA,EACE,UAAArC,EAAc,IAAI,CAACuB,GAAWe,MAC7B,gBAAAC,EAACC,KAAqC,WAAAjB,KAAtB,aAAae,CAAK,EAA0B,CAC7D,GACH;AAAA,IAED5C;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(JSON.stringify({ 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(JSON.stringify({ 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,EAAwC,CAAA,CAAE,GAEtD,EAAE,MAAMG,EAAsB,IAAIC,EAAmB,GACrD;AAAA,IACJ,MAAMC,IAAwB;AAAA,IAC9B,KAAKC;AAAA,IACL,cAAAC;AAAA,MACEC,EAAkB,GAEhBC,KACJnB,MAAU,MAENe,KAAyB,CAACE,MAAgBZ,EAAc,SAAS,GAEjEe,IAAaC;AAAA,IACjB,CAACC,GAAgBC,MAAkC;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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;"}
package/dist/index.d.ts CHANGED
@@ -1327,7 +1327,7 @@ export declare interface IJourneyContext {
1327
1327
  * This data is set only the component is mounted.
1328
1328
  * And thereafter it is updated when the user completes a journey, through the `endJourney` method.
1329
1329
  */
1330
- userCompletedJourneyIds: TJourneyId[] | null;
1330
+ userCompletedJourneyIds: TJourneyId[];
1331
1331
  }
1332
1332
 
1333
1333
  declare interface IJourneyProviderProps {
@@ -5023,12 +5023,6 @@ export declare const useGetCircleHomeDetailsDal: (userId: string, grade: string,
5023
5023
  invalidateCircleHomeDetails: () => void;
5024
5024
  };
5025
5025
 
5026
- /**
5027
- * Unless the useGetUserJourney API is resolved, this hook will return an empty array.
5028
- * This is because the userCompletedJourneyIds are set from the API response.
5029
- * And Unless the API is resolved, we cannot determine the eligible journeys.
5030
- * So, we return an empty array.
5031
- */
5032
5026
  export declare const useGetEligibleJourneysViaRoute: (routeJourneyIds: TJourneyId[]) => JOURNEY_ID_STUDENT[];
5033
5027
 
5034
5028
  declare const useGetLeaderboard: (initialId?: string, initialQuery?: IGetLeaderboardPayloadModel | undefined) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuemath/leap",
3
- "version": "2.8.61-rj-0",
3
+ "version": "2.8.61-rj-2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"