@magmamath/students-features 0.6.5-rc-21 → 0.6.5-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 (201) hide show
  1. package/dist/commonjs/features/chatbot/model/ChatBotModel.js +3 -3
  2. package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
  3. package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js +1 -3
  4. package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
  5. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +2 -4
  6. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  7. package/dist/commonjs/features/chatbot/model/constants.js.map +1 -1
  8. package/dist/commonjs/features/chatbot/model/translation.js +0 -7
  9. package/dist/commonjs/features/chatbot/model/translation.js.map +1 -1
  10. package/dist/commonjs/features/endOfAssignment/components/Modal/ModalBackground.js +3 -17
  11. package/dist/commonjs/features/endOfAssignment/components/Modal/ModalBackground.js.map +1 -1
  12. package/dist/commonjs/features/feedback/model/comments.js +3 -5
  13. package/dist/commonjs/features/feedback/model/comments.js.map +1 -1
  14. package/dist/commonjs/features/feedback/model/model.js +9 -7
  15. package/dist/commonjs/features/feedback/model/model.js.map +1 -1
  16. package/dist/commonjs/features/gifCelebrations/GifCelebrations.js +65 -0
  17. package/dist/commonjs/features/gifCelebrations/GifCelebrations.js.map +1 -0
  18. package/dist/commonjs/features/gifCelebrations/assets/confetti.webp +0 -0
  19. package/dist/commonjs/features/gifCelebrations/components/Backdrop.js +44 -0
  20. package/dist/commonjs/features/gifCelebrations/components/Backdrop.js.map +1 -0
  21. package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js +46 -0
  22. package/dist/commonjs/features/gifCelebrations/components/ContentContainer.js.map +1 -0
  23. package/dist/commonjs/features/gifCelebrations/components/Gif.js +63 -0
  24. package/dist/commonjs/features/gifCelebrations/components/Gif.js.map +1 -0
  25. package/dist/commonjs/features/gifCelebrations/components/Progress.js +102 -0
  26. package/dist/commonjs/features/gifCelebrations/components/Progress.js.map +1 -0
  27. package/dist/commonjs/features/gifCelebrations/constants.js +18 -0
  28. package/dist/commonjs/features/gifCelebrations/constants.js.map +1 -0
  29. package/dist/commonjs/features/gifCelebrations/helpers.js +67 -0
  30. package/dist/commonjs/features/gifCelebrations/helpers.js.map +1 -0
  31. package/dist/commonjs/features/gifCelebrations/index.js +20 -0
  32. package/dist/commonjs/features/gifCelebrations/index.js.map +1 -0
  33. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js +19 -0
  34. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -0
  35. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js +151 -0
  36. package/dist/commonjs/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -0
  37. package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js +14 -0
  38. package/dist/commonjs/features/gifCelebrations/model/GifCelebrationsApi.js.map +1 -0
  39. package/dist/commonjs/features/gifCelebrations/types/model.types.js +6 -0
  40. package/dist/commonjs/features/gifCelebrations/types/model.types.js.map +1 -0
  41. package/dist/commonjs/index.js +12 -0
  42. package/dist/commonjs/index.js.map +1 -1
  43. package/dist/commonjs/shared/hooks/useImagePreloader.js +20 -0
  44. package/dist/commonjs/shared/hooks/useImagePreloader.js.map +1 -0
  45. package/dist/commonjs/shared/translation/localization/en.json +1 -2
  46. package/dist/commonjs/shared/translation/localization/gb.json +1 -2
  47. package/dist/commonjs/shared/translation/localization/sw.json +1 -2
  48. package/dist/module/features/chatbot/model/ChatBotModel.js +3 -3
  49. package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
  50. package/dist/module/features/chatbot/model/ChatBoxTextManager.js +1 -3
  51. package/dist/module/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
  52. package/dist/module/features/chatbot/model/DefaultMessageCreator.js +2 -4
  53. package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  54. package/dist/module/features/chatbot/model/constants.js.map +1 -1
  55. package/dist/module/features/chatbot/model/translation.js +0 -7
  56. package/dist/module/features/chatbot/model/translation.js.map +1 -1
  57. package/dist/module/features/endOfAssignment/components/Modal/ModalBackground.js +4 -19
  58. package/dist/module/features/endOfAssignment/components/Modal/ModalBackground.js.map +1 -1
  59. package/dist/module/features/feedback/model/comments.js +3 -5
  60. package/dist/module/features/feedback/model/comments.js.map +1 -1
  61. package/dist/module/features/feedback/model/model.js +9 -7
  62. package/dist/module/features/feedback/model/model.js.map +1 -1
  63. package/dist/module/features/gifCelebrations/GifCelebrations.js +58 -0
  64. package/dist/module/features/gifCelebrations/GifCelebrations.js.map +1 -0
  65. package/dist/module/features/gifCelebrations/assets/confetti.webp +0 -0
  66. package/dist/module/features/gifCelebrations/components/Backdrop.js +36 -0
  67. package/dist/module/features/gifCelebrations/components/Backdrop.js.map +1 -0
  68. package/dist/module/features/gifCelebrations/components/ContentContainer.js +38 -0
  69. package/dist/module/features/gifCelebrations/components/ContentContainer.js.map +1 -0
  70. package/dist/module/features/gifCelebrations/components/Gif.js +56 -0
  71. package/dist/module/features/gifCelebrations/components/Gif.js.map +1 -0
  72. package/dist/module/features/gifCelebrations/components/Progress.js +94 -0
  73. package/dist/module/features/gifCelebrations/components/Progress.js.map +1 -0
  74. package/dist/module/features/gifCelebrations/constants.js +14 -0
  75. package/dist/module/features/gifCelebrations/constants.js.map +1 -0
  76. package/dist/module/features/gifCelebrations/helpers.js +61 -0
  77. package/dist/module/features/gifCelebrations/helpers.js.map +1 -0
  78. package/dist/module/features/gifCelebrations/index.js +5 -0
  79. package/dist/module/features/gifCelebrations/index.js.map +1 -0
  80. package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js +14 -0
  81. package/dist/module/features/gifCelebrations/model/GifCelebrations.cache.js.map +1 -0
  82. package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js +146 -0
  83. package/dist/module/features/gifCelebrations/model/GifCelebrations.model.js.map +1 -0
  84. package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js +9 -0
  85. package/dist/module/features/gifCelebrations/model/GifCelebrationsApi.js.map +1 -0
  86. package/dist/module/features/gifCelebrations/types/model.types.js +4 -0
  87. package/dist/module/features/gifCelebrations/types/model.types.js.map +1 -0
  88. package/dist/module/index.js +1 -0
  89. package/dist/module/index.js.map +1 -1
  90. package/dist/module/shared/hooks/useImagePreloader.js +15 -0
  91. package/dist/module/shared/hooks/useImagePreloader.js.map +1 -0
  92. package/dist/module/shared/translation/localization/en.json +1 -2
  93. package/dist/module/shared/translation/localization/gb.json +1 -2
  94. package/dist/module/shared/translation/localization/sw.json +1 -2
  95. package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  96. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  97. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  98. package/dist/typescript/commonjs/features/chatbot/model/constants.d.ts.map +1 -1
  99. package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +1 -1
  100. package/dist/typescript/commonjs/features/endOfAssignment/components/Modal/ModalBackground.d.ts.map +1 -1
  101. package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts +8 -0
  102. package/dist/typescript/commonjs/features/gifCelebrations/GifCelebrations.d.ts.map +1 -0
  103. package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts +9 -0
  104. package/dist/typescript/commonjs/features/gifCelebrations/components/Backdrop.d.ts.map +1 -0
  105. package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts +9 -0
  106. package/dist/typescript/commonjs/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -0
  107. package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts +7 -0
  108. package/dist/typescript/commonjs/features/gifCelebrations/components/Gif.d.ts.map +1 -0
  109. package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts +9 -0
  110. package/dist/typescript/commonjs/features/gifCelebrations/components/Progress.d.ts.map +1 -0
  111. package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts +12 -0
  112. package/dist/typescript/commonjs/features/gifCelebrations/constants.d.ts.map +1 -0
  113. package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts +75 -0
  114. package/dist/typescript/commonjs/features/gifCelebrations/helpers.d.ts.map +1 -0
  115. package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts +3 -0
  116. package/dist/typescript/commonjs/features/gifCelebrations/index.d.ts.map +1 -0
  117. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts +8 -0
  118. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -0
  119. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts +23 -0
  120. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -0
  121. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts +6 -0
  122. package/dist/typescript/commonjs/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +1 -0
  123. package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts +32 -0
  124. package/dist/typescript/commonjs/features/gifCelebrations/types/model.types.d.ts.map +1 -0
  125. package/dist/typescript/commonjs/index.d.ts +1 -0
  126. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  127. package/dist/typescript/commonjs/shared/hooks/useImagePreloader.d.ts +4 -0
  128. package/dist/typescript/commonjs/shared/hooks/useImagePreloader.d.ts.map +1 -0
  129. package/dist/typescript/commonjs/shared/translation/constants.d.ts +0 -3
  130. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  131. package/dist/typescript/commonjs/shared/translation/model.d.ts +0 -2
  132. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
  133. package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  134. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  135. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  136. package/dist/typescript/module/features/chatbot/model/constants.d.ts.map +1 -1
  137. package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +1 -1
  138. package/dist/typescript/module/features/endOfAssignment/components/Modal/ModalBackground.d.ts.map +1 -1
  139. package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts +8 -0
  140. package/dist/typescript/module/features/gifCelebrations/GifCelebrations.d.ts.map +1 -0
  141. package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts +9 -0
  142. package/dist/typescript/module/features/gifCelebrations/components/Backdrop.d.ts.map +1 -0
  143. package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts +9 -0
  144. package/dist/typescript/module/features/gifCelebrations/components/ContentContainer.d.ts.map +1 -0
  145. package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts +7 -0
  146. package/dist/typescript/module/features/gifCelebrations/components/Gif.d.ts.map +1 -0
  147. package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts +9 -0
  148. package/dist/typescript/module/features/gifCelebrations/components/Progress.d.ts.map +1 -0
  149. package/dist/typescript/module/features/gifCelebrations/constants.d.ts +12 -0
  150. package/dist/typescript/module/features/gifCelebrations/constants.d.ts.map +1 -0
  151. package/dist/typescript/module/features/gifCelebrations/helpers.d.ts +75 -0
  152. package/dist/typescript/module/features/gifCelebrations/helpers.d.ts.map +1 -0
  153. package/dist/typescript/module/features/gifCelebrations/index.d.ts +3 -0
  154. package/dist/typescript/module/features/gifCelebrations/index.d.ts.map +1 -0
  155. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts +8 -0
  156. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.cache.d.ts.map +1 -0
  157. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts +23 -0
  158. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrations.model.d.ts.map +1 -0
  159. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts +6 -0
  160. package/dist/typescript/module/features/gifCelebrations/model/GifCelebrationsApi.d.ts.map +1 -0
  161. package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts +32 -0
  162. package/dist/typescript/module/features/gifCelebrations/types/model.types.d.ts.map +1 -0
  163. package/dist/typescript/module/index.d.ts +1 -0
  164. package/dist/typescript/module/index.d.ts.map +1 -1
  165. package/dist/typescript/module/shared/hooks/useImagePreloader.d.ts +4 -0
  166. package/dist/typescript/module/shared/hooks/useImagePreloader.d.ts.map +1 -0
  167. package/dist/typescript/module/shared/translation/constants.d.ts +0 -3
  168. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  169. package/dist/typescript/module/shared/translation/model.d.ts +0 -2
  170. package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
  171. package/package.json +1 -1
  172. package/src/features/chatbot/model/ChatBotModel.ts +1 -1
  173. package/src/features/chatbot/model/ChatBoxTextManager.ts +1 -3
  174. package/src/features/chatbot/model/DefaultMessageCreator.ts +2 -4
  175. package/src/features/chatbot/model/constants.ts +2 -0
  176. package/src/features/chatbot/model/translation.ts +0 -9
  177. package/src/features/endOfAssignment/components/Modal/ModalBackground.tsx +3 -14
  178. package/src/features/feedback/model/comments.ts +7 -7
  179. package/src/features/feedback/model/model.ts +6 -6
  180. package/src/features/gifCelebrations/GifCelebrations.tsx +75 -0
  181. package/src/features/gifCelebrations/assets/confetti.webp +0 -0
  182. package/src/features/gifCelebrations/components/Backdrop.tsx +40 -0
  183. package/src/features/gifCelebrations/components/ContentContainer.tsx +43 -0
  184. package/src/features/gifCelebrations/components/Gif.tsx +61 -0
  185. package/src/features/gifCelebrations/components/Progress.tsx +108 -0
  186. package/src/features/gifCelebrations/constants.ts +13 -0
  187. package/src/features/gifCelebrations/helpers.ts +68 -0
  188. package/src/features/gifCelebrations/index.ts +2 -0
  189. package/src/features/gifCelebrations/model/GifCelebrations.cache.ts +24 -0
  190. package/src/features/gifCelebrations/model/GifCelebrations.model.ts +177 -0
  191. package/src/features/gifCelebrations/model/GifCelebrationsApi.ts +10 -0
  192. package/src/features/gifCelebrations/types/model.types.ts +36 -0
  193. package/src/index.ts +1 -0
  194. package/src/shared/hooks/useImagePreloader.ts +15 -0
  195. package/src/shared/translation/localization/en.json +1 -2
  196. package/src/shared/translation/localization/gb.json +1 -2
  197. package/src/shared/translation/localization/sw.json +1 -2
  198. package/src/types/types.d.ts +0 -5
  199. package/dist/commonjs/features/endOfAssignment/components/Modal/assets/goblet-bg.webp +0 -0
  200. package/dist/module/features/endOfAssignment/components/Modal/assets/goblet-bg.webp +0 -0
  201. package/src/features/endOfAssignment/components/Modal/assets/goblet-bg.webp +0 -0
@@ -0,0 +1,24 @@
1
+ import { createEvent, createStore } from 'effector'
2
+ import { GifsGroups, GifsStructure } from '../types/model.types'
3
+
4
+ export class GifCelebrationsCache {
5
+ public readonly initialSet = createEvent<GifsGroups>()
6
+ public readonly set = createEvent<GifsStructure>()
7
+ public readonly reset = createEvent()
8
+
9
+ public readonly $gifs = createStore<GifsStructure | null>(null)
10
+ .reset(this.reset)
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
+ )
23
+ .on(this.set, (_, gifs) => gifs)
24
+ }
@@ -0,0 +1,177 @@
1
+ import { createEffect, createEvent, createStore, sample, Store } from 'effector'
2
+ import { GifCelebrationsApi } from './GifCelebrationsApi'
3
+ import {
4
+ GifCelebrationsModelProps,
5
+ GifObject,
6
+ GifsGroups,
7
+ GifsStructure,
8
+ ProblemsPercentageTable,
9
+ } from '../types/model.types'
10
+ import { GifCelebrationsCache } from './GifCelebrations.cache'
11
+ import { calculatePercentageTable } from '../helpers'
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
+ }
20
+
21
+ type HandleGifSelectionProps = {
22
+ gifsGroups: GifsStructure
23
+ resolvedProblem: number
24
+ problemsPercentageTable: ProblemsPercentageTable
25
+ }
26
+
27
+ export class GifCelebrationsModel {
28
+ public readonly api: GifCelebrationsApi
29
+ public readonly cache: GifCelebrationsCache
30
+
31
+ public readonly $totalProblems: Store<number>
32
+ public readonly $resolvedProblems: Store<number>
33
+
34
+ public readonly triggerPlay = createEvent()
35
+ public readonly stop = createEvent()
36
+
37
+ public readonly resetPercentageTable = createEvent()
38
+ public readonly $problemsPercentageTable = createStore<ProblemsPercentageTable | null>(
39
+ null,
40
+ ).reset(this.resetPercentageTable)
41
+
42
+ public readonly setActiveGif = createEvent<GifObject>()
43
+ public readonly $activeGif = createStore<GifObject | null>(null)
44
+ .reset(this.stop)
45
+ .on(this.setActiveGif, (_, gif) => gif)
46
+
47
+ public readonly initialize = createEvent()
48
+ public readonly resetGroupGifs = createEvent<string>()
49
+
50
+ constructor({ api, totalProblems, resolvedProblems }: GifCelebrationsModelProps) {
51
+ this.api = new GifCelebrationsApi(api)
52
+ this.cache = new GifCelebrationsCache()
53
+
54
+ this.$totalProblems = totalProblems
55
+ this.$resolvedProblems = resolvedProblems
56
+
57
+ this.setupEventHandlers()
58
+ }
59
+
60
+ private setupEventHandlers() {
61
+ sample({
62
+ source: this.api.getGifsFx.doneData,
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
+ console.log('data: ', data)
76
+
77
+ this.cache.initialSet(data)
78
+ }),
79
+ })
80
+
81
+ sample({
82
+ clock: this.initialize,
83
+ source: this.cache.$gifs,
84
+ filter: (gifs) => !gifs,
85
+ target: this.api.getGifsFx,
86
+ })
87
+
88
+ sample({
89
+ //todo: fix types
90
+ //@ts-ignore
91
+ clock: this.initialize,
92
+ source: this.$totalProblems,
93
+ filter: (totalProblems) => totalProblems && totalProblems >= MIN_PROBLEMS_TO_SHOW_GIF,
94
+ fn: (totalProblems) => calculatePercentageTable(totalProblems),
95
+ target: this.$problemsPercentageTable,
96
+ })
97
+
98
+ sample({
99
+ clock: this.triggerPlay,
100
+ source: {
101
+ gifsGroups: this.cache.$gifs,
102
+ resolvedProblem: this.$resolvedProblems,
103
+ problemsPercentageTable: this.$problemsPercentageTable,
104
+ },
105
+ filter: ({ gifsGroups, resolvedProblem, problemsPercentageTable }) =>
106
+ !!(gifsGroups && resolvedProblem !== undefined && problemsPercentageTable),
107
+ fn: (sources) => sources as HandleGifSelectionProps,
108
+ target: this.handleGifSelection,
109
+ })
110
+ }
111
+
112
+ private readonly handleGifSelection = createEffect(
113
+ ({ gifsGroups, resolvedProblem, problemsPercentageTable }: HandleGifSelectionProps) => {
114
+ // Find which percentage milestone this resolved problem represents
115
+ const percentageMilestone = Object.keys(problemsPercentageTable).find(
116
+ (key) => problemsPercentageTable[Number(key)] === resolvedProblem,
117
+ )
118
+ if (!percentageMilestone) return null
119
+
120
+ // Find which group this percentage belongs to
121
+ const groupName = this.findGroupForPercentage(Number(percentageMilestone)) as
122
+ | `group${number}`
123
+ | undefined
124
+ if (!groupName) return null
125
+
126
+ // Get available gifs for this group
127
+ const gifsForGroup = gifsGroups[groupName]
128
+ console.log('gifsForGroup: ', gifsForGroup)
129
+ if (!gifsForGroup || gifsForGroup.length === 0) return null
130
+
131
+ // Find the first gif that hasn't been shown yet
132
+ const unusedGifIndex = gifsForGroup.findIndex((gif) => !gif.isShown)
133
+
134
+ // If all gifs have been shown, reset the group and start from the beginning
135
+ if (unusedGifIndex === -1) {
136
+ // Reset the group by setting all gifs to isShown: false
137
+ const updatedGifsGroups = { ...gifsGroups }
138
+ updatedGifsGroups[groupName] = gifsGroups[groupName].map((gif) => ({
139
+ ...gif,
140
+ isShown: false,
141
+ }))
142
+ // Select the first gif from the group
143
+ const gifObject: GifObject = {
144
+ ...updatedGifsGroups[groupName][0],
145
+ isShown: true,
146
+ }
147
+ updatedGifsGroups[groupName][0].isShown = true
148
+
149
+ this.setActiveGif(gifObject)
150
+ // Update the cache with the shown gif
151
+ this.cache.set(updatedGifsGroups)
152
+ }
153
+
154
+ // Otherwise, use the first unused gif
155
+ const selectedGif = gifsForGroup[unusedGifIndex]
156
+
157
+ // Create a new gif object with isShown set to true
158
+ const gifObject: GifObject = {
159
+ ...selectedGif,
160
+ isShown: true,
161
+ }
162
+
163
+ // Update the cache with the shown gif
164
+ const updatedGifsGroups = { ...gifsGroups }
165
+ updatedGifsGroups[groupName][unusedGifIndex].isShown = true
166
+ this.cache.set(updatedGifsGroups)
167
+
168
+ this.setActiveGif(gifObject)
169
+ },
170
+ )
171
+
172
+ private findGroupForPercentage(percentage: number): string | undefined {
173
+ return Object.keys(GROUPS_PERCENTAGES).find((key) =>
174
+ GROUPS_PERCENTAGES[key as keyof typeof GROUPS_PERCENTAGES].includes(percentage),
175
+ )
176
+ }
177
+ }
@@ -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,36 @@
1
+ import { Store } from 'effector'
2
+
3
+ export type GifCelebrationApiRequests = {
4
+ getGifs: () => Promise<GifResponse>
5
+ }
6
+
7
+ export type GifCelebrationsModelProps = {
8
+ api: GifCelebrationApiRequests
9
+ totalProblems: Store<number>
10
+ resolvedProblems: Store<number>
11
+ }
12
+
13
+ export type GifsGroup = string[]
14
+ export type GifsGroups = Record<`group${number}`, GifsGroup>
15
+
16
+ export type GifObject = {
17
+ url: string
18
+ isShown: boolean
19
+ group: `group${number}`
20
+ }
21
+
22
+ export type GifsStructure = Record<`group${number}`, GifObject[]>
23
+ /**
24
+ * Usually, the response contains 3 groups of gifs:
25
+ * - group1: early celebrations
26
+ * - group2: mid celebrations
27
+ * - group3: party
28
+ */
29
+ export type GifResponse = {
30
+ data: GifsGroups
31
+ ok: boolean
32
+ }
33
+ export type GifsPayload = {
34
+ group: number
35
+ }
36
+ export type ProblemsPercentageTable = Record<number, number>
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'
@@ -0,0 +1,15 @@
1
+ import { useEffect } from 'react'
2
+
3
+ type ImagesUrls = string[]
4
+
5
+ export const useImagePreloader = (imageUrls: ImagesUrls) => {
6
+ useEffect(() => {
7
+ imageUrls.forEach((url) => {
8
+ const img = new Image()
9
+ img.src = url
10
+ img.onload = () => {
11
+ console.log(`Image loaded: ${url}`)
12
+ }
13
+ })
14
+ }, [imageUrls])
15
+ }
@@ -13,9 +13,8 @@
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": "Something went wrong! Try again",
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
20
  }
@@ -13,9 +13,8 @@
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": "Something went wrong! Try again",
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
20
  }
@@ -13,9 +13,8 @@
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": "Något gick snett! Försök igen",
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
20
  }
@@ -2,8 +2,3 @@ declare module '*.scss' {
2
2
  const content: Record<string, string>
3
3
  export default content
4
4
  }
5
-
6
- declare module '*.webp' {
7
- const value: string | number
8
- export default value
9
- }