@magmamath/students-features 0.6.5-rc.13 → 0.6.5-rc.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.
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js +3 -3
- package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js +1 -3
- package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +2 -4
- package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/constants.js.map +1 -1
- package/dist/commonjs/features/chatbot/model/translation.js +0 -7
- package/dist/commonjs/features/chatbot/model/translation.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/GifCelebrations.js +2 -5
- package/dist/commonjs/features/gifCelebrations/GifCelebrations.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/components/Backdrop.js +1 -1
- package/dist/commonjs/features/gifCelebrations/components/Backdrop.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/components/Gif.js +16 -33
- package/dist/commonjs/features/gifCelebrations/components/Gif.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/components/Progress.js +8 -12
- package/dist/commonjs/features/gifCelebrations/components/Progress.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/constants.js +1 -13
- package/dist/commonjs/features/gifCelebrations/constants.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/helpers.js +27 -31
- package/dist/commonjs/features/gifCelebrations/helpers.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js +5 -18
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -1
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js +42 -18
- package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -1
- package/dist/commonjs/lib/helpers/helpers.js.map +1 -1
- package/dist/commonjs/shared/translation/localization/en.json +1 -7
- package/dist/commonjs/shared/translation/localization/gb.json +1 -7
- package/dist/commonjs/shared/translation/localization/sw.json +1 -7
- package/dist/module/features/chatbot/model/ChatBotModel.js +3 -3
- package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
- package/dist/module/features/chatbot/model/ChatBoxTextManager.js +1 -3
- package/dist/module/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js +2 -4
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
- package/dist/module/features/chatbot/model/constants.js.map +1 -1
- package/dist/module/features/chatbot/model/translation.js +0 -7
- package/dist/module/features/chatbot/model/translation.js.map +1 -1
- package/dist/module/features/gifCelebrations/GifCelebrations.js +2 -5
- package/dist/module/features/gifCelebrations/GifCelebrations.js.map +1 -1
- package/dist/module/features/gifCelebrations/components/Backdrop.js +1 -1
- package/dist/module/features/gifCelebrations/components/Backdrop.js.map +1 -1
- package/dist/module/features/gifCelebrations/components/ContentContainer.js.map +1 -1
- package/dist/module/features/gifCelebrations/components/Gif.js +17 -34
- package/dist/module/features/gifCelebrations/components/Gif.js.map +1 -1
- package/dist/module/features/gifCelebrations/components/Progress.js +10 -14
- package/dist/module/features/gifCelebrations/components/Progress.js.map +1 -1
- package/dist/module/features/gifCelebrations/constants.js +0 -12
- package/dist/module/features/gifCelebrations/constants.js.map +1 -1
- package/dist/module/features/gifCelebrations/helpers.js +25 -28
- package/dist/module/features/gifCelebrations/helpers.js.map +1 -1
- package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js +6 -19
- package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -1
- package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js +42 -18
- package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -1
- package/dist/module/shared/translation/localization/en.json +1 -7
- package/dist/module/shared/translation/localization/gb.json +1 -7
- package/dist/module/shared/translation/localization/sw.json +1 -7
- package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts +1 -3
- package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts +1 -2
- package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts +1 -2
- package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts +2 -5
- package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts +1 -2
- package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts +0 -10
- package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts +8 -18
- package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts +1 -11
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts +1 -4
- package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -1
- package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts +3 -13
- package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts.map +1 -1
- package/dist/typescript/commonjs/lib/helpers/helpers.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/constants.d.ts +0 -18
- package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/commonjs/shared/translation/model.d.ts +0 -12
- package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/constants.d.ts.map +1 -1
- package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts +1 -3
- package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts +1 -2
- package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts +1 -2
- package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts +2 -5
- package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts +1 -2
- package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/constants.d.ts +0 -10
- package/dist/typescript/module/features/gifCelebrations/constants.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/helpers.d.ts +8 -18
- package/dist/typescript/module/features/gifCelebrations/helpers.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts +1 -11
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts +1 -4
- package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -1
- package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts +3 -13
- package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts.map +1 -1
- package/dist/typescript/module/lib/helpers/helpers.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/constants.d.ts +0 -18
- package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
- package/dist/typescript/module/shared/translation/model.d.ts +0 -12
- package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/chatbot/model/ChatBotModel.ts +1 -1
- package/src/features/chatbot/model/ChatBoxTextManager.ts +1 -3
- package/src/features/chatbot/model/DefaultMessageCreator.ts +2 -4
- package/src/features/chatbot/model/constants.ts +2 -0
- package/src/features/chatbot/model/translation.ts +0 -9
- package/src/features/gifCelebrations/GifCelebrations.tsx +3 -9
- package/src/features/gifCelebrations/components/Backdrop.tsx +2 -3
- package/src/features/gifCelebrations/components/ContentContainer.tsx +1 -2
- package/src/features/gifCelebrations/components/Gif.tsx +14 -39
- package/src/features/gifCelebrations/components/Progress.tsx +9 -17
- package/src/features/gifCelebrations/constants.ts +0 -12
- package/src/features/gifCelebrations/helpers.ts +32 -39
- package/src/features/gifCelebrations/model/GifCelebrations.cache.ts +14 -33
- package/src/features/gifCelebrations/model/GifCelebrations.model.ts +41 -39
- package/src/features/gifCelebrations/types/model.types.ts +3 -17
- package/src/lib/helpers/helpers.ts +1 -1
- package/src/shared/translation/localization/en.json +1 -7
- package/src/shared/translation/localization/gb.json +1 -7
- package/src/shared/translation/localization/sw.json +1 -7
- package/dist/commonjs/react-app-env.d.js +0 -2
- package/dist/commonjs/react-app-env.d.js.map +0 -1
- package/dist/module/react-app-env.d.js +0 -2
- package/dist/module/react-app-env.d.js.map +0 -1
- package/src/react-app-env.d.ts +0 -5
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { GifsGroups } from './types/model.types'
|
|
2
|
+
|
|
3
|
+
type GifSelectProps = {
|
|
4
|
+
gifsGroups: GifsGroups
|
|
5
|
+
resolvedProblem: number
|
|
6
|
+
totalProblems: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Number of problems When we show gif
|
|
10
|
+
// <6 Never
|
|
11
|
+
// 7-12 50% completion
|
|
12
|
+
// 13-18 33%, 66% completion
|
|
13
|
+
// 19-24 25%, 50%, 75 completion
|
|
14
|
+
// 25-30 20%, 40%, 60%, 80% completion
|
|
15
|
+
// .>30 15%, 30%, 45%, 60%, 75% completion
|
|
16
|
+
|
|
17
|
+
// We are also going to have different buckets with different gifs. The logic is as follows:
|
|
18
|
+
// Group 1: 15%, 20%, 25%, 30% - Early celebrations
|
|
19
|
+
// Group 2: 33%, 40%, 45%, 50% - Mid celebrations
|
|
20
|
+
// Group 3: 60%, 66%, 75%, 80% - Party
|
|
21
|
+
|
|
22
|
+
export const gifSelect = ({ gifsGroups, resolvedProblem, totalProblems }: GifSelectProps) => {
|
|
23
|
+
if (totalProblems < 7) return null
|
|
24
|
+
|
|
25
|
+
const group = Math.ceil((resolvedProblem / totalProblems) * 100)
|
|
26
|
+
|
|
27
|
+
if (group <= 20) return gifsGroups.group1[Math.floor(Math.random() * gifsGroups.group1.length)]
|
|
28
|
+
if (group <= 40) return gifsGroups.group2[Math.floor(Math.random() * gifsGroups.group2.length)]
|
|
29
|
+
if (group <= 60) return gifsGroups.group3[Math.floor(Math.random() * gifsGroups.group3.length)]
|
|
30
|
+
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
3
33
|
|
|
4
|
-
/**
|
|
5
|
-
* Number of problems When we show gif
|
|
6
|
-
* <6 Never
|
|
7
|
-
* 7-12 50% completion
|
|
8
|
-
* 13-18 33%, 66% completion
|
|
9
|
-
* 19-24 25%, 50%, 75 completion
|
|
10
|
-
* 25-30 20%, 40%, 60%, 80% completion
|
|
11
|
-
* .>30 15%, 30%, 45%, 60%, 75% completion
|
|
12
|
-
*
|
|
13
|
-
* We are also going to have different buckets with different gifs. The logic is as follows:
|
|
14
|
-
* Group 1: 15%, 20%, 25%, 30% - Early celebrations
|
|
15
|
-
* Group 2: 33%, 40%, 45%, 50% - Mid celebrations
|
|
16
|
-
* Group 3: 60%, 66%, 75%, 80% - Party
|
|
17
|
-
*/
|
|
18
34
|
export const calculatePercentageTable = (totalProblems: number) => {
|
|
19
35
|
if (totalProblems <= 12) return { 50: Math.ceil(totalProblems * 0.5) }
|
|
20
36
|
|
|
@@ -50,26 +66,3 @@ export const calculatePercentageTable = (totalProblems: number) => {
|
|
|
50
66
|
75: Math.ceil(totalProblems * 0.75),
|
|
51
67
|
}
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
export const generateGifsStructure = (gifs: GifsGroups): GifsStructure =>
|
|
55
|
-
Object.fromEntries(
|
|
56
|
-
Object.entries(gifs).map(([key, value]) => [
|
|
57
|
-
key,
|
|
58
|
-
value.map((url) => ({
|
|
59
|
-
url,
|
|
60
|
-
isShown: false,
|
|
61
|
-
group: key as `group${GroupNumber}`,
|
|
62
|
-
})),
|
|
63
|
-
]),
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
export const getGifLabel = (relatedGroup: GroupNumber): TranslationKeys => {
|
|
67
|
-
if (relatedGroup === 2) {
|
|
68
|
-
return 'gifCelebrations.onTheWay'
|
|
69
|
-
}
|
|
70
|
-
if (relatedGroup === 3) {
|
|
71
|
-
return 'gifCelebrations.almostThere'
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return 'gifCelebrations.greatStart'
|
|
75
|
-
}
|
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
GifsGroups,
|
|
4
|
-
GifsStructure,
|
|
5
|
-
CustomPrefetchMethod,
|
|
6
|
-
CustomGetCachePathMethod,
|
|
7
|
-
} from '../types/model.types'
|
|
8
|
-
import { generateGifsStructure } from '../helpers'
|
|
9
|
-
import { Image } from 'react-native'
|
|
10
|
-
|
|
11
|
-
type GifCelebrationsCacheProps = {
|
|
12
|
-
customPrefetchMethod?: CustomPrefetchMethod
|
|
13
|
-
customGetCachePathMethod?: CustomGetCachePathMethod
|
|
14
|
-
}
|
|
1
|
+
import { createEvent, createStore } from 'effector'
|
|
2
|
+
import { GifsGroups, GifsStructure } from '../types/model.types'
|
|
15
3
|
|
|
16
4
|
export class GifCelebrationsCache {
|
|
17
5
|
public readonly initialSet = createEvent<GifsGroups>()
|
|
18
6
|
public readonly set = createEvent<GifsStructure>()
|
|
19
7
|
public readonly reset = createEvent()
|
|
20
8
|
|
|
21
|
-
public readonly prefetchMethod: CustomPrefetchMethod | typeof Image.prefetch
|
|
22
|
-
public readonly getCachePathMethod?: CustomGetCachePathMethod
|
|
23
|
-
|
|
24
|
-
public readonly prefetchGifs = createEffect<GifsGroups, void>((data) => {
|
|
25
|
-
Object.values(data).forEach((group) => {
|
|
26
|
-
group.forEach((gifUrl) => {
|
|
27
|
-
Image.prefetch(gifUrl)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
this.initialSet(data)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
9
|
public readonly $gifs = createStore<GifsStructure | null>(null)
|
|
35
10
|
.reset(this.reset)
|
|
36
|
-
.on(this.initialSet, (_, gifs) =>
|
|
11
|
+
.on(this.initialSet, (_, gifs) =>
|
|
12
|
+
Object.fromEntries(
|
|
13
|
+
Object.entries(gifs).map(([key, value]) => [
|
|
14
|
+
key,
|
|
15
|
+
value.map((url) => ({
|
|
16
|
+
url,
|
|
17
|
+
isShown: false,
|
|
18
|
+
group: key as `group${number}`,
|
|
19
|
+
})),
|
|
20
|
+
]),
|
|
21
|
+
),
|
|
22
|
+
)
|
|
37
23
|
.on(this.set, (_, gifs) => gifs)
|
|
38
|
-
|
|
39
|
-
constructor({ customPrefetchMethod, customGetCachePathMethod }: GifCelebrationsCacheProps) {
|
|
40
|
-
this.prefetchMethod = customPrefetchMethod || Image.prefetch
|
|
41
|
-
this.getCachePathMethod = customGetCachePathMethod
|
|
42
|
-
}
|
|
43
24
|
}
|
|
@@ -3,13 +3,20 @@ import { GifCelebrationsApi } from './GifCelebrationsApi'
|
|
|
3
3
|
import {
|
|
4
4
|
GifCelebrationsModelProps,
|
|
5
5
|
GifObject,
|
|
6
|
+
GifsGroups,
|
|
6
7
|
GifsStructure,
|
|
7
|
-
GroupNumber,
|
|
8
8
|
ProblemsPercentageTable,
|
|
9
9
|
} from '../types/model.types'
|
|
10
10
|
import { GifCelebrationsCache } from './GifCelebrations.cache'
|
|
11
11
|
import { calculatePercentageTable } from '../helpers'
|
|
12
|
-
import {
|
|
12
|
+
import { Image } from 'react-native'
|
|
13
|
+
import { MIN_PROBLEMS_TO_SHOW_GIF } from '../constants'
|
|
14
|
+
|
|
15
|
+
const GROUPS_PERCENTAGES = {
|
|
16
|
+
group1: [15, 20, 25, 30], // Early celebrations
|
|
17
|
+
group2: [33, 40, 45, 50], // Mid celebrations
|
|
18
|
+
group3: [60, 66, 75, 80], // Party
|
|
19
|
+
}
|
|
13
20
|
|
|
14
21
|
type HandleGifSelectionProps = {
|
|
15
22
|
gifsGroups: GifsStructure
|
|
@@ -27,16 +34,6 @@ export class GifCelebrationsModel {
|
|
|
27
34
|
public readonly triggerPlay = createEvent()
|
|
28
35
|
public readonly stop = createEvent()
|
|
29
36
|
|
|
30
|
-
public readonly resetIsGifCelebrationMayBeTriggered = createEvent()
|
|
31
|
-
public readonly setIsGifCelebrationMayBeTriggered = createEvent<boolean>()
|
|
32
|
-
public readonly $isGifCelebrationMayBeTriggered = createStore<boolean>(false)
|
|
33
|
-
.reset(this.resetIsGifCelebrationMayBeTriggered)
|
|
34
|
-
.reset(this.stop)
|
|
35
|
-
.on(
|
|
36
|
-
this.setIsGifCelebrationMayBeTriggered,
|
|
37
|
-
(_, isGifCelebrationMayBeTriggered) => isGifCelebrationMayBeTriggered,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
37
|
public readonly resetPercentageTable = createEvent()
|
|
41
38
|
public readonly $problemsPercentageTable = createStore<ProblemsPercentageTable | null>(
|
|
42
39
|
null,
|
|
@@ -50,15 +47,9 @@ export class GifCelebrationsModel {
|
|
|
50
47
|
public readonly initialize = createEvent()
|
|
51
48
|
public readonly resetGroupGifs = createEvent<string>()
|
|
52
49
|
|
|
53
|
-
constructor({
|
|
54
|
-
api,
|
|
55
|
-
totalProblems,
|
|
56
|
-
resolvedProblems,
|
|
57
|
-
customPrefetchMethod,
|
|
58
|
-
customGetCachePathMethod,
|
|
59
|
-
}: GifCelebrationsModelProps) {
|
|
50
|
+
constructor({ api, totalProblems, resolvedProblems }: GifCelebrationsModelProps) {
|
|
60
51
|
this.api = new GifCelebrationsApi(api)
|
|
61
|
-
this.cache = new GifCelebrationsCache(
|
|
52
|
+
this.cache = new GifCelebrationsCache()
|
|
62
53
|
|
|
63
54
|
this.$totalProblems = totalProblems
|
|
64
55
|
this.$resolvedProblems = resolvedProblems
|
|
@@ -69,9 +60,21 @@ export class GifCelebrationsModel {
|
|
|
69
60
|
private setupEventHandlers() {
|
|
70
61
|
sample({
|
|
71
62
|
source: this.api.getGifsFx.doneData,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
fn: (response) =>
|
|
64
|
+
response.ok
|
|
65
|
+
? response.data
|
|
66
|
+
: (() => {
|
|
67
|
+
throw new Error('Failed to fetch GIFs')
|
|
68
|
+
})(),
|
|
69
|
+
target: createEffect((data: GifsGroups) => {
|
|
70
|
+
Object.values(data).forEach((group) => {
|
|
71
|
+
group.forEach((gifUrl) => {
|
|
72
|
+
Image.prefetch(gifUrl)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
this.cache.initialSet(data)
|
|
77
|
+
}),
|
|
75
78
|
})
|
|
76
79
|
|
|
77
80
|
sample({
|
|
@@ -84,7 +87,7 @@ export class GifCelebrationsModel {
|
|
|
84
87
|
sample({
|
|
85
88
|
//todo: fix types
|
|
86
89
|
//@ts-ignore
|
|
87
|
-
clock:
|
|
90
|
+
clock: this.initialize,
|
|
88
91
|
source: this.$totalProblems,
|
|
89
92
|
filter: (totalProblems) => totalProblems && totalProblems >= MIN_PROBLEMS_TO_SHOW_GIF,
|
|
90
93
|
fn: (totalProblems) => calculatePercentageTable(totalProblems),
|
|
@@ -94,23 +97,12 @@ export class GifCelebrationsModel {
|
|
|
94
97
|
sample({
|
|
95
98
|
clock: this.triggerPlay,
|
|
96
99
|
source: {
|
|
97
|
-
isGifCelebrationMayBeTriggered: this.$isGifCelebrationMayBeTriggered,
|
|
98
100
|
gifsGroups: this.cache.$gifs,
|
|
99
101
|
resolvedProblem: this.$resolvedProblems,
|
|
100
102
|
problemsPercentageTable: this.$problemsPercentageTable,
|
|
101
103
|
},
|
|
102
|
-
filter: ({
|
|
103
|
-
|
|
104
|
-
gifsGroups,
|
|
105
|
-
resolvedProblem,
|
|
106
|
-
problemsPercentageTable,
|
|
107
|
-
}) =>
|
|
108
|
-
!!(
|
|
109
|
-
isGifCelebrationMayBeTriggered &&
|
|
110
|
-
gifsGroups &&
|
|
111
|
-
resolvedProblem !== undefined &&
|
|
112
|
-
problemsPercentageTable
|
|
113
|
-
),
|
|
104
|
+
filter: ({ gifsGroups, resolvedProblem, problemsPercentageTable }) =>
|
|
105
|
+
!!(gifsGroups && resolvedProblem !== undefined && problemsPercentageTable),
|
|
114
106
|
fn: (sources) => sources as HandleGifSelectionProps,
|
|
115
107
|
target: this.handleGifSelection,
|
|
116
108
|
})
|
|
@@ -118,28 +110,34 @@ export class GifCelebrationsModel {
|
|
|
118
110
|
|
|
119
111
|
private readonly handleGifSelection = createEffect(
|
|
120
112
|
({ gifsGroups, resolvedProblem, problemsPercentageTable }: HandleGifSelectionProps) => {
|
|
113
|
+
// Find which percentage milestone this resolved problem represents
|
|
121
114
|
const percentageMilestone = Object.keys(problemsPercentageTable).find(
|
|
122
115
|
(key) => problemsPercentageTable[Number(key)] === resolvedProblem,
|
|
123
116
|
)
|
|
124
|
-
|
|
125
117
|
if (!percentageMilestone) return null
|
|
126
118
|
|
|
119
|
+
// Find which group this percentage belongs to
|
|
127
120
|
const groupName = this.findGroupForPercentage(Number(percentageMilestone)) as
|
|
128
|
-
| `group${
|
|
121
|
+
| `group${number}`
|
|
129
122
|
| undefined
|
|
130
123
|
if (!groupName) return null
|
|
131
124
|
|
|
125
|
+
// Get available gifs for this group
|
|
132
126
|
const gifsForGroup = gifsGroups[groupName]
|
|
133
127
|
if (!gifsForGroup || gifsForGroup.length === 0) return null
|
|
134
128
|
|
|
129
|
+
// Find the first gif that hasn't been shown yet
|
|
135
130
|
const unusedGifIndex = gifsForGroup.findIndex((gif) => !gif.isShown)
|
|
136
131
|
|
|
132
|
+
// If all gifs have been shown, reset the group and start from the beginning
|
|
137
133
|
if (unusedGifIndex === -1) {
|
|
134
|
+
// Reset the group by setting all gifs to isShown: false
|
|
138
135
|
const updatedGifsGroups = { ...gifsGroups }
|
|
139
136
|
updatedGifsGroups[groupName] = gifsGroups[groupName].map((gif) => ({
|
|
140
137
|
...gif,
|
|
141
138
|
isShown: false,
|
|
142
139
|
}))
|
|
140
|
+
// Select the first gif from the group
|
|
143
141
|
const gifObject: GifObject = {
|
|
144
142
|
...updatedGifsGroups[groupName][0],
|
|
145
143
|
isShown: true,
|
|
@@ -147,16 +145,20 @@ export class GifCelebrationsModel {
|
|
|
147
145
|
updatedGifsGroups[groupName][0].isShown = true
|
|
148
146
|
|
|
149
147
|
this.setActiveGif(gifObject)
|
|
148
|
+
// Update the cache with the shown gif
|
|
150
149
|
this.cache.set(updatedGifsGroups)
|
|
151
150
|
}
|
|
152
151
|
|
|
152
|
+
// Otherwise, use the first unused gif
|
|
153
153
|
const selectedGif = gifsForGroup[unusedGifIndex]
|
|
154
154
|
|
|
155
|
+
// Create a new gif object with isShown set to true
|
|
155
156
|
const gifObject: GifObject = {
|
|
156
157
|
...selectedGif,
|
|
157
158
|
isShown: true,
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
// Update the cache with the shown gif
|
|
160
162
|
const updatedGifsGroups = { ...gifsGroups }
|
|
161
163
|
updatedGifsGroups[groupName][unusedGifIndex].isShown = true
|
|
162
164
|
this.cache.set(updatedGifsGroups)
|
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
import { Store } from 'effector'
|
|
2
2
|
|
|
3
|
-
export type CustomPrefetchMethod = (gifs: string[] | string) => Promise<unknown>
|
|
4
|
-
export type CustomGetCachePathMethod = (uri: string) => Promise<string | null>
|
|
5
|
-
|
|
6
|
-
export type GroupNumber = number
|
|
7
|
-
|
|
8
3
|
export type GifCelebrationApiRequests = {
|
|
9
4
|
getGifs: () => Promise<GifResponse>
|
|
10
5
|
}
|
|
11
|
-
export type GifCelebrationCache = {
|
|
12
|
-
prefetchMethod?: CustomPrefetchMethod
|
|
13
|
-
}
|
|
14
6
|
|
|
15
7
|
export type GifCelebrationsModelProps = {
|
|
16
8
|
api: GifCelebrationApiRequests
|
|
17
9
|
totalProblems: Store<number>
|
|
18
10
|
resolvedProblems: Store<number>
|
|
19
|
-
customPrefetchMethod?: CustomPrefetchMethod
|
|
20
|
-
customGetCachePathMethod?: CustomGetCachePathMethod
|
|
21
11
|
}
|
|
22
12
|
|
|
23
13
|
export type GifsGroup = string[]
|
|
24
|
-
export type GifsGroups = Record<`group${
|
|
14
|
+
export type GifsGroups = Record<`group${number}`, GifsGroup>
|
|
25
15
|
|
|
26
16
|
export type GifObject = {
|
|
27
17
|
url: string
|
|
28
18
|
isShown: boolean
|
|
29
|
-
group: `group${
|
|
19
|
+
group: `group${number}`
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
export type GifsStructure = Record<`group${
|
|
22
|
+
export type GifsStructure = Record<`group${number}`, GifObject[]>
|
|
33
23
|
/**
|
|
34
24
|
* Usually, the response contains 3 groups of gifs:
|
|
35
25
|
* - group1: early celebrations
|
|
@@ -43,8 +33,4 @@ export type GifResponse = {
|
|
|
43
33
|
export type GifsPayload = {
|
|
44
34
|
group: number
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
export type ProblemsPercentageTable = Record<number, number>
|
|
48
|
-
export type ProgressValue = 0 | 1 | 2
|
|
49
|
-
|
|
50
|
-
export type TextComponentType = (text: string) => React.ReactNode
|
|
@@ -13,15 +13,9 @@
|
|
|
13
13
|
"time.yearsAgo": "years ago",
|
|
14
14
|
"chat": {
|
|
15
15
|
"anotherHint": "Give me another hint",
|
|
16
|
-
"giveHint": "Give me a hint",
|
|
17
16
|
"answerAgain": "Answer again to get another hint!",
|
|
18
|
-
"errorMessage": "
|
|
17
|
+
"errorMessage": "Sorry, I can't help with this issue at the moment 😔.",
|
|
19
18
|
"howCanIHelp": "Hi! Do you want help?",
|
|
20
19
|
"showError": "Show error"
|
|
21
|
-
},
|
|
22
|
-
"gifCelebrations": {
|
|
23
|
-
"greatStart": "Great start!",
|
|
24
|
-
"onTheWay": "On the way!",
|
|
25
|
-
"almostThere": "Almost there"
|
|
26
20
|
}
|
|
27
21
|
}
|
|
@@ -13,15 +13,9 @@
|
|
|
13
13
|
"time.yearsAgo": "years ago",
|
|
14
14
|
"chat": {
|
|
15
15
|
"anotherHint": "Give me another hint",
|
|
16
|
-
"giveHint": "Give me a hint",
|
|
17
16
|
"answerAgain": "Answer again to get another hint!",
|
|
18
|
-
"errorMessage": "
|
|
17
|
+
"errorMessage": "Sorry, I can't help with this issue at the moment 😔.",
|
|
19
18
|
"howCanIHelp": "Hi! Do you want help?",
|
|
20
19
|
"showError": "Show error"
|
|
21
|
-
},
|
|
22
|
-
"gifCelebrations": {
|
|
23
|
-
"greatStart": "Great start!",
|
|
24
|
-
"onTheWay": "On the way!",
|
|
25
|
-
"almostThere": "Almost there"
|
|
26
20
|
}
|
|
27
21
|
}
|
|
@@ -13,15 +13,9 @@
|
|
|
13
13
|
"time.yearsAgo": "år sedan",
|
|
14
14
|
"chat": {
|
|
15
15
|
"anotherHint": "Ge mig en ledtråd",
|
|
16
|
-
"giveHint": "Ge mig en ledtråd",
|
|
17
16
|
"answerAgain": "Svara igen för att få en till ledtråd!",
|
|
18
|
-
"errorMessage": "
|
|
17
|
+
"errorMessage": "Tyvärr kan jag inte hjälpa dig just nu 😔.",
|
|
19
18
|
"howCanIHelp": "Hej! Hur kan jag hjälpa dig?",
|
|
20
19
|
"showError": "Visa fel"
|
|
21
|
-
},
|
|
22
|
-
"gifCelebrations": {
|
|
23
|
-
"greatStart": "Bra start!",
|
|
24
|
-
"onTheWay": "På god väg!",
|
|
25
|
-
"almostThere": "Nästan där"
|
|
26
20
|
}
|
|
27
21
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["react-app-env.d.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["react-app-env.d.ts"],"mappings":"","ignoreList":[]}
|