@magmamath/students-features 0.6.5 → 0.6.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/dist/commonjs/features/feedback/model/comments.js +3 -5
  2. package/dist/commonjs/features/feedback/model/comments.js.map +1 -1
  3. package/dist/commonjs/features/feedback/model/model.js +9 -7
  4. package/dist/commonjs/features/feedback/model/model.js.map +1 -1
  5. package/dist/commonjs/features/gifCelebrations/GifCelebrations.js +65 -0
  6. package/dist/commonjs/features/gifCelebrations/GifCelebrations.js.map +1 -0
  7. package/dist/commonjs/features/gifCelebrations/assets/confetti.webp +0 -0
  8. package/dist/commonjs/features/gifCelebrations/components/Backdrop.js +44 -0
  9. package/dist/commonjs/features/gifCelebrations/components/Backdrop.js.map +1 -0
  10. package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js +46 -0
  11. package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js.map +1 -0
  12. package/dist/commonjs/features/gifCelebrations/components/Gif.js +80 -0
  13. package/dist/commonjs/features/gifCelebrations/components/Gif.js.map +1 -0
  14. package/dist/commonjs/features/gifCelebrations/components/Progress.js +106 -0
  15. package/dist/commonjs/features/gifCelebrations/components/Progress.js.map +1 -0
  16. package/dist/commonjs/features/gifCelebrations/constants.js +30 -0
  17. package/dist/commonjs/features/gifCelebrations/constants.js.map +1 -0
  18. package/dist/commonjs/features/gifCelebrations/helpers.js +71 -0
  19. package/dist/commonjs/features/gifCelebrations/helpers.js.map +1 -0
  20. package/dist/commonjs/features/gifCelebrations/index.js +20 -0
  21. package/dist/commonjs/features/gifCelebrations/index.js.map +1 -0
  22. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js +32 -0
  23. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -0
  24. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js +125 -0
  25. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -0
  26. package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js +14 -0
  27. package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js.map +1 -0
  28. package/dist/commonjs/features/gifCelebrations/types/model.types.js +6 -0
  29. package/dist/commonjs/features/gifCelebrations/types/model.types.js.map +1 -0
  30. package/dist/commonjs/index.js +12 -0
  31. package/dist/commonjs/index.js.map +1 -1
  32. package/dist/commonjs/lib/helpers/helpers.js.map +1 -1
  33. package/dist/commonjs/react-app-env.d.js +2 -0
  34. package/dist/commonjs/react-app-env.d.js.map +1 -0
  35. package/dist/commonjs/shared/translation/localization/en.json +5 -0
  36. package/dist/commonjs/shared/translation/localization/gb.json +5 -0
  37. package/dist/commonjs/shared/translation/localization/sw.json +5 -0
  38. package/dist/module/features/feedback/model/comments.js +3 -5
  39. package/dist/module/features/feedback/model/comments.js.map +1 -1
  40. package/dist/module/features/feedback/model/model.js +9 -7
  41. package/dist/module/features/feedback/model/model.js.map +1 -1
  42. package/dist/module/features/gifCelebrations/GifCelebrations.js +58 -0
  43. package/dist/module/features/gifCelebrations/GifCelebrations.js.map +1 -0
  44. package/dist/module/features/gifCelebrations/assets/confetti.webp +0 -0
  45. package/dist/module/features/gifCelebrations/components/Backdrop.js +36 -0
  46. package/dist/module/features/gifCelebrations/components/Backdrop.js.map +1 -0
  47. package/dist/module/features/gifCelebrations/components/ContentContainer.js +38 -0
  48. package/dist/module/features/gifCelebrations/components/ContentContainer.js.map +1 -0
  49. package/dist/module/features/gifCelebrations/components/Gif.js +73 -0
  50. package/dist/module/features/gifCelebrations/components/Gif.js.map +1 -0
  51. package/dist/module/features/gifCelebrations/components/Progress.js +98 -0
  52. package/dist/module/features/gifCelebrations/components/Progress.js.map +1 -0
  53. package/dist/module/features/gifCelebrations/constants.js +26 -0
  54. package/dist/module/features/gifCelebrations/constants.js.map +1 -0
  55. package/dist/module/features/gifCelebrations/helpers.js +64 -0
  56. package/dist/module/features/gifCelebrations/helpers.js.map +1 -0
  57. package/dist/module/features/gifCelebrations/index.js +5 -0
  58. package/dist/module/features/gifCelebrations/index.js.map +1 -0
  59. package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js +27 -0
  60. package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -0
  61. package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js +120 -0
  62. package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -0
  63. package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js +9 -0
  64. package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js.map +1 -0
  65. package/dist/module/features/gifCelebrations/types/model.types.js +4 -0
  66. package/dist/module/features/gifCelebrations/types/model.types.js.map +1 -0
  67. package/dist/module/index.js +1 -0
  68. package/dist/module/index.js.map +1 -1
  69. package/dist/module/react-app-env.d.js +2 -0
  70. package/dist/module/react-app-env.d.js.map +1 -0
  71. package/dist/module/shared/translation/localization/en.json +5 -0
  72. package/dist/module/shared/translation/localization/gb.json +5 -0
  73. package/dist/module/shared/translation/localization/sw.json +5 -0
  74. package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts +10 -0
  75. package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts.map +1 -0
  76. package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts +10 -0
  77. package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts.map +1 -0
  78. package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts +10 -0
  79. package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -0
  80. package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts +10 -0
  81. package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts.map +1 -0
  82. package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts +10 -0
  83. package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts.map +1 -0
  84. package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts +22 -0
  85. package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts.map +1 -0
  86. package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts +85 -0
  87. package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts.map +1 -0
  88. package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts +3 -0
  89. package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts.map +1 -0
  90. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts +18 -0
  91. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -0
  92. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts +26 -0
  93. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -0
  94. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts +6 -0
  95. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +1 -0
  96. package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts +42 -0
  97. package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts.map +1 -0
  98. package/dist/typescript/commonjs/index.d.ts +1 -0
  99. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  100. package/dist/typescript/commonjs/lib/helpers/helpers.d.ts.map +1 -1
  101. package/dist/typescript/commonjs/shared/translation/constants.d.ts +15 -0
  102. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  103. package/dist/typescript/commonjs/shared/translation/model.d.ts +10 -0
  104. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
  105. package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts +10 -0
  106. package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts.map +1 -0
  107. package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts +10 -0
  108. package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts.map +1 -0
  109. package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts +10 -0
  110. package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -0
  111. package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts +10 -0
  112. package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts.map +1 -0
  113. package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts +10 -0
  114. package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts.map +1 -0
  115. package/dist/typescript/module/features/gifCelebrations/constants.d.ts +22 -0
  116. package/dist/typescript/module/features/gifCelebrations/constants.d.ts.map +1 -0
  117. package/dist/typescript/module/features/gifCelebrations/helpers.d.ts +85 -0
  118. package/dist/typescript/module/features/gifCelebrations/helpers.d.ts.map +1 -0
  119. package/dist/typescript/module/features/gifCelebrations/index.d.ts +3 -0
  120. package/dist/typescript/module/features/gifCelebrations/index.d.ts.map +1 -0
  121. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts +18 -0
  122. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -0
  123. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts +26 -0
  124. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -0
  125. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts +6 -0
  126. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +1 -0
  127. package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts +42 -0
  128. package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts.map +1 -0
  129. package/dist/typescript/module/index.d.ts +1 -0
  130. package/dist/typescript/module/index.d.ts.map +1 -1
  131. package/dist/typescript/module/lib/helpers/helpers.d.ts.map +1 -1
  132. package/dist/typescript/module/shared/translation/constants.d.ts +15 -0
  133. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  134. package/dist/typescript/module/shared/translation/model.d.ts +10 -0
  135. package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
  136. package/package.json +1 -1
  137. package/src/features/feedback/model/comments.ts +7 -7
  138. package/src/features/feedback/model/model.ts +6 -6
  139. package/src/features/gifCelebrations/GifCelebrations.tsx +77 -0
  140. package/src/features/gifCelebrations/assets/confetti.webp +0 -0
  141. package/src/features/gifCelebrations/components/Backdrop.tsx +41 -0
  142. package/src/features/gifCelebrations/components/ContentContainer.tsx +44 -0
  143. package/src/features/gifCelebrations/components/Gif.tsx +86 -0
  144. package/src/features/gifCelebrations/components/Progress.tsx +116 -0
  145. package/src/features/gifCelebrations/constants.ts +25 -0
  146. package/src/features/gifCelebrations/helpers.ts +75 -0
  147. package/src/features/gifCelebrations/index.ts +2 -0
  148. package/src/features/gifCelebrations/model/GifCelebrations.cache.ts +43 -0
  149. package/src/features/gifCelebrations/model/GifCelebrations.model.ts +174 -0
  150. package/src/features/gifCelebrations/model/GifCelebrationsApi.ts +10 -0
  151. package/src/features/gifCelebrations/types/model.types.ts +50 -0
  152. package/src/index.ts +1 -0
  153. package/src/lib/helpers/helpers.ts +1 -1
  154. package/src/react-app-env.d.ts +5 -0
  155. package/src/shared/translation/localization/en.json +5 -0
  156. package/src/shared/translation/localization/gb.json +5 -0
  157. package/src/shared/translation/localization/sw.json +5 -0
@@ -0,0 +1,75 @@
1
+ import { TranslationKeys } from 'src/shared/translation/types'
2
+ import { GifsGroups, GifsStructure, GroupNumber } from './types/model.types'
3
+
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
+ export const calculatePercentageTable = (totalProblems: number) => {
19
+ if (totalProblems <= 12) return { 50: Math.ceil(totalProblems * 0.5) }
20
+
21
+ if (totalProblems <= 18) {
22
+ return {
23
+ 33: Math.ceil(totalProblems * 0.33),
24
+ 66: Math.ceil(totalProblems * 0.66),
25
+ }
26
+ }
27
+
28
+ if (totalProblems <= 24) {
29
+ return {
30
+ 25: Math.ceil(totalProblems * 0.25),
31
+ 50: Math.ceil(totalProblems * 0.5),
32
+ 75: Math.ceil(totalProblems * 0.75),
33
+ }
34
+ }
35
+
36
+ if (totalProblems <= 30) {
37
+ return {
38
+ 20: Math.ceil(totalProblems * 0.2),
39
+ 40: Math.ceil(totalProblems * 0.4),
40
+ 60: Math.ceil(totalProblems * 0.6),
41
+ 80: Math.ceil(totalProblems * 0.8),
42
+ }
43
+ }
44
+
45
+ return {
46
+ 15: Math.ceil(totalProblems * 0.15),
47
+ 30: Math.ceil(totalProblems * 0.3),
48
+ 45: Math.ceil(totalProblems * 0.45),
49
+ 60: Math.ceil(totalProblems * 0.6),
50
+ 75: Math.ceil(totalProblems * 0.75),
51
+ }
52
+ }
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
+ }
@@ -0,0 +1,2 @@
1
+ export { GifCelebrations } from './GifCelebrations'
2
+ export { GifCelebrationsModel } from './model/GifCelebrations.model'
@@ -0,0 +1,43 @@
1
+ import { createEffect, createEvent, createStore } from 'effector'
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
+ }
15
+
16
+ export class GifCelebrationsCache {
17
+ public readonly initialSet = createEvent<GifsGroups>()
18
+ public readonly set = createEvent<GifsStructure>()
19
+ public readonly reset = createEvent()
20
+
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
+ public readonly $gifs = createStore<GifsStructure | null>(null)
35
+ .reset(this.reset)
36
+ .on(this.initialSet, (_, gifs) => generateGifsStructure(gifs))
37
+ .on(this.set, (_, gifs) => gifs)
38
+
39
+ constructor({ customPrefetchMethod, customGetCachePathMethod }: GifCelebrationsCacheProps) {
40
+ this.prefetchMethod = customPrefetchMethod || Image.prefetch
41
+ this.getCachePathMethod = customGetCachePathMethod
42
+ }
43
+ }
@@ -0,0 +1,174 @@
1
+ import { createEffect, createEvent, createStore, sample, Store } from 'effector'
2
+ import { GifCelebrationsApi } from './GifCelebrationsApi'
3
+ import {
4
+ GifCelebrationsModelProps,
5
+ GifObject,
6
+ GifsStructure,
7
+ GroupNumber,
8
+ ProblemsPercentageTable,
9
+ } from '../types/model.types'
10
+ import { GifCelebrationsCache } from './GifCelebrations.cache'
11
+ import { calculatePercentageTable } from '../helpers'
12
+ import { GROUPS_PERCENTAGES, MIN_PROBLEMS_TO_SHOW_GIF } from '../constants'
13
+
14
+ type HandleGifSelectionProps = {
15
+ gifsGroups: GifsStructure
16
+ resolvedProblem: number
17
+ problemsPercentageTable: ProblemsPercentageTable
18
+ }
19
+
20
+ export class GifCelebrationsModel {
21
+ public readonly api: GifCelebrationsApi
22
+ public readonly cache: GifCelebrationsCache
23
+
24
+ public readonly $totalProblems: Store<number>
25
+ public readonly $resolvedProblems: Store<number>
26
+
27
+ public readonly triggerPlay = createEvent()
28
+ public readonly stop = createEvent()
29
+
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
+ public readonly resetPercentageTable = createEvent()
41
+ public readonly $problemsPercentageTable = createStore<ProblemsPercentageTable | null>(
42
+ null,
43
+ ).reset(this.resetPercentageTable)
44
+
45
+ public readonly setActiveGif = createEvent<GifObject>()
46
+ public readonly $activeGif = createStore<GifObject | null>(null)
47
+ .reset(this.stop)
48
+ .reset(this.resetIsGifCelebrationMayBeTriggered)
49
+ .on(this.setActiveGif, (_, gif) => gif)
50
+
51
+ public readonly initialize = createEvent()
52
+ public readonly resetGroupGifs = createEvent<string>()
53
+
54
+ constructor({
55
+ api,
56
+ totalProblems,
57
+ resolvedProblems,
58
+ customPrefetchMethod,
59
+ customGetCachePathMethod,
60
+ }: GifCelebrationsModelProps) {
61
+ this.api = new GifCelebrationsApi(api)
62
+ this.cache = new GifCelebrationsCache({ customPrefetchMethod, customGetCachePathMethod })
63
+
64
+ this.$totalProblems = totalProblems
65
+ this.$resolvedProblems = resolvedProblems
66
+
67
+ this.setupEventHandlers()
68
+ }
69
+
70
+ private setupEventHandlers() {
71
+ sample({
72
+ source: this.api.getGifsFx.doneData,
73
+ filter: (response) => response.ok,
74
+ fn: (response) => response.data,
75
+ target: this.cache.prefetchGifs,
76
+ })
77
+
78
+ sample({
79
+ clock: this.initialize,
80
+ source: this.cache.$gifs,
81
+ filter: (gifs) => !gifs,
82
+ target: this.api.getGifsFx,
83
+ })
84
+
85
+ sample({
86
+ //todo: fix types
87
+ //@ts-ignore
88
+ clock: [this.initialize, this.$totalProblems.updates],
89
+ source: this.$totalProblems,
90
+ filter: (totalProblems) => totalProblems && totalProblems >= MIN_PROBLEMS_TO_SHOW_GIF,
91
+ fn: (totalProblems) => calculatePercentageTable(totalProblems),
92
+ target: this.$problemsPercentageTable,
93
+ })
94
+
95
+ sample({
96
+ clock: this.triggerPlay,
97
+ source: {
98
+ isGifCelebrationMayBeTriggered: this.$isGifCelebrationMayBeTriggered,
99
+ gifsGroups: this.cache.$gifs,
100
+ resolvedProblem: this.$resolvedProblems,
101
+ problemsPercentageTable: this.$problemsPercentageTable,
102
+ },
103
+ filter: ({
104
+ isGifCelebrationMayBeTriggered,
105
+ gifsGroups,
106
+ resolvedProblem,
107
+ problemsPercentageTable,
108
+ }) =>
109
+ !!(
110
+ isGifCelebrationMayBeTriggered &&
111
+ gifsGroups &&
112
+ resolvedProblem !== undefined &&
113
+ problemsPercentageTable
114
+ ),
115
+ fn: (sources) => sources as HandleGifSelectionProps,
116
+ target: this.handleGifSelection,
117
+ })
118
+ }
119
+
120
+ private readonly handleGifSelection = createEffect(
121
+ ({ gifsGroups, resolvedProblem, problemsPercentageTable }: HandleGifSelectionProps) => {
122
+ const percentageMilestone = Object.keys(problemsPercentageTable).find(
123
+ (key) => problemsPercentageTable[Number(key)] === resolvedProblem,
124
+ )
125
+
126
+ if (!percentageMilestone) return null
127
+
128
+ const groupName = this.findGroupForPercentage(Number(percentageMilestone)) as
129
+ | `group${GroupNumber}`
130
+ | undefined
131
+ if (!groupName) return null
132
+
133
+ const gifsForGroup = gifsGroups[groupName]
134
+ if (!gifsForGroup || gifsForGroup.length === 0) return null
135
+
136
+ const unusedGifIndex = gifsForGroup.findIndex((gif) => !gif.isShown)
137
+
138
+ if (unusedGifIndex === -1) {
139
+ const updatedGifsGroups = { ...gifsGroups }
140
+ updatedGifsGroups[groupName] = gifsGroups[groupName].map((gif) => ({
141
+ ...gif,
142
+ isShown: false,
143
+ }))
144
+ const gifObject: GifObject = {
145
+ ...updatedGifsGroups[groupName][0],
146
+ isShown: true,
147
+ }
148
+ updatedGifsGroups[groupName][0].isShown = true
149
+
150
+ this.setActiveGif(gifObject)
151
+ this.cache.set(updatedGifsGroups)
152
+ }
153
+
154
+ const selectedGif = gifsForGroup[unusedGifIndex]
155
+
156
+ const gifObject: GifObject = {
157
+ ...selectedGif,
158
+ isShown: true,
159
+ }
160
+
161
+ const updatedGifsGroups = { ...gifsGroups }
162
+ updatedGifsGroups[groupName][unusedGifIndex].isShown = true
163
+ this.cache.set(updatedGifsGroups)
164
+
165
+ this.setActiveGif(gifObject)
166
+ },
167
+ )
168
+
169
+ private findGroupForPercentage(percentage: number): string | undefined {
170
+ return Object.keys(GROUPS_PERCENTAGES).find((key) =>
171
+ GROUPS_PERCENTAGES[key as keyof typeof GROUPS_PERCENTAGES].includes(percentage),
172
+ )
173
+ }
174
+ }
@@ -0,0 +1,10 @@
1
+ import { createControllerEffect } from './../../../lib/effector/createControllerEffect'
2
+ import { GifCelebrationApiRequests } from '../types/model.types'
3
+
4
+ export class GifCelebrationsApi {
5
+ public readonly getGifsFx
6
+
7
+ constructor(api: GifCelebrationApiRequests) {
8
+ this.getGifsFx = createControllerEffect(api.getGifs)
9
+ }
10
+ }
@@ -0,0 +1,50 @@
1
+ import { Store } from 'effector'
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
+ export type GifCelebrationApiRequests = {
9
+ getGifs: () => Promise<GifResponse>
10
+ }
11
+ export type GifCelebrationCache = {
12
+ prefetchMethod?: CustomPrefetchMethod
13
+ }
14
+
15
+ export type GifCelebrationsModelProps = {
16
+ api: GifCelebrationApiRequests
17
+ totalProblems: Store<number>
18
+ resolvedProblems: Store<number>
19
+ customPrefetchMethod?: CustomPrefetchMethod
20
+ customGetCachePathMethod?: CustomGetCachePathMethod
21
+ }
22
+
23
+ export type GifsGroup = string[]
24
+ export type GifsGroups = Record<`group${GroupNumber}`, GifsGroup>
25
+
26
+ export type GifObject = {
27
+ url: string
28
+ isShown: boolean
29
+ group: `group${GroupNumber}`
30
+ }
31
+
32
+ export type GifsStructure = Record<`group${GroupNumber}`, GifObject[]>
33
+ /**
34
+ * Usually, the response contains 3 groups of gifs:
35
+ * - group1: early celebrations
36
+ * - group2: mid celebrations
37
+ * - group3: party
38
+ */
39
+ export type GifResponse = {
40
+ data: GifsGroups
41
+ ok: boolean
42
+ }
43
+ export type GifsPayload = {
44
+ group: number
45
+ }
46
+
47
+ export type ProblemsPercentageTable = Record<number, number>
48
+ export type ProgressValue = 0 | 1 | 2
49
+
50
+ export type TextComponentType = (text: string) => React.ReactNode
package/src/index.ts CHANGED
@@ -6,3 +6,4 @@ export * from './features/celebrations'
6
6
  export * from './features/endOfAssignment'
7
7
  export * from './features/formulaSheet'
8
8
  export * from './features/problemSelector'
9
+ export * from './features/gifCelebrations'
@@ -1,6 +1,6 @@
1
1
  import { getText } from '../../shared/translation/helpers'
2
2
 
3
- export const noop = () => {};
3
+ export const noop = () => {}
4
4
 
5
5
  export const generateRandomId = () =>
6
6
  Date.now().toString(36) + Math.random().toString(36).substring(2)
@@ -0,0 +1,5 @@
1
+ declare module '*.png'
2
+ declare module '*.svg'
3
+ declare module '*.jpeg'
4
+ declare module '*.jpg'
5
+ declare module '*.webp'
@@ -18,5 +18,10 @@
18
18
  "errorMessage": "Something went wrong! Try again",
19
19
  "howCanIHelp": "Hi! Do you want help?",
20
20
  "showError": "Show error"
21
+ },
22
+ "gifCelebrations": {
23
+ "greatStart": "Great start!",
24
+ "onTheWay": "On the way!",
25
+ "almostThere": "Almost there"
21
26
  }
22
27
  }
@@ -18,5 +18,10 @@
18
18
  "errorMessage": "Something went wrong! Try again",
19
19
  "howCanIHelp": "Hi! Do you want help?",
20
20
  "showError": "Show error"
21
+ },
22
+ "gifCelebrations": {
23
+ "greatStart": "Great start!",
24
+ "onTheWay": "On the way!",
25
+ "almostThere": "Almost there"
21
26
  }
22
27
  }
@@ -18,5 +18,10 @@
18
18
  "errorMessage": "Något gick snett! Försök igen",
19
19
  "howCanIHelp": "Hej! Hur kan jag hjälpa dig?",
20
20
  "showError": "Visa fel"
21
+ },
22
+ "gifCelebrations": {
23
+ "greatStart": "Bra start!",
24
+ "onTheWay": "På god väg!",
25
+ "almostThere": "Nästan där"
21
26
  }
22
27
  }