@magmamath/students-features 0.6.12 → 0.6.14-rc.0

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 (226) hide show
  1. package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js +17 -5
  2. package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js.map +1 -1
  3. package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js +148 -41
  4. package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js.map +1 -1
  5. package/dist/commonjs/features/chatbot/components/Alternatives/InputButton.js +110 -0
  6. package/dist/commonjs/features/chatbot/components/Alternatives/InputButton.js.map +1 -0
  7. package/dist/commonjs/features/chatbot/components/Alternatives/InputWithHintRow.js +159 -0
  8. package/dist/commonjs/features/chatbot/components/Alternatives/InputWithHintRow.js.map +1 -0
  9. package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
  10. package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
  11. package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js +1 -1
  12. package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
  13. package/dist/commonjs/features/exampleSolution/ExampleSolutionModal.js +31 -0
  14. package/dist/commonjs/features/exampleSolution/ExampleSolutionModal.js.map +1 -0
  15. package/dist/commonjs/features/exampleSolution/assets/grid.png +0 -0
  16. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js +97 -0
  17. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -0
  18. package/dist/commonjs/features/exampleSolution/components/LavaIcon.js +44 -0
  19. package/dist/commonjs/features/exampleSolution/components/LavaIcon.js.map +1 -0
  20. package/dist/commonjs/features/exampleSolution/components/MessageBlock.js +61 -0
  21. package/dist/commonjs/features/exampleSolution/components/MessageBlock.js.map +1 -0
  22. package/dist/commonjs/features/exampleSolution/components/QuestionSection.js +68 -0
  23. package/dist/commonjs/features/exampleSolution/components/QuestionSection.js.map +1 -0
  24. package/dist/commonjs/features/exampleSolution/components/SolutionSection.js +75 -0
  25. package/dist/commonjs/features/exampleSolution/components/SolutionSection.js.map +1 -0
  26. package/dist/commonjs/features/exampleSolution/constants.js +13 -0
  27. package/dist/commonjs/features/exampleSolution/constants.js.map +1 -0
  28. package/dist/commonjs/features/exampleSolution/hooks/useExampleSolution.js +61 -0
  29. package/dist/commonjs/features/exampleSolution/hooks/useExampleSolution.js.map +1 -0
  30. package/dist/commonjs/features/exampleSolution/index.js +39 -0
  31. package/dist/commonjs/features/exampleSolution/index.js.map +1 -0
  32. package/dist/commonjs/features/exampleSolution/model/ExampleSolution.model.js +22 -0
  33. package/dist/commonjs/features/exampleSolution/model/ExampleSolution.model.js.map +1 -0
  34. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionApi.js +32 -0
  35. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionApi.js.map +1 -0
  36. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionCache.js +18 -0
  37. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionCache.js.map +1 -0
  38. package/dist/commonjs/features/exampleSolution/types.js +6 -0
  39. package/dist/commonjs/features/exampleSolution/types.js.map +1 -0
  40. package/dist/commonjs/index.js +24 -0
  41. package/dist/commonjs/index.js.map +1 -1
  42. package/dist/commonjs/shared/icons/ExcitedLavaIcon.js +681 -0
  43. package/dist/commonjs/shared/icons/ExcitedLavaIcon.js.map +1 -0
  44. package/dist/commonjs/shared/icons/LavaIconInGlasses.js +616 -0
  45. package/dist/commonjs/shared/icons/LavaIconInGlasses.js.map +1 -0
  46. package/dist/commonjs/shared/icons/index.js +204 -0
  47. package/dist/commonjs/shared/icons/index.js.map +1 -0
  48. package/dist/commonjs/shared/translation/localization/ca.json +7 -1
  49. package/dist/commonjs/shared/translation/localization/en.json +8 -2
  50. package/dist/commonjs/shared/translation/localization/gb.json +7 -1
  51. package/dist/commonjs/shared/translation/localization/sct.json +7 -1
  52. package/dist/commonjs/shared/translation/localization/sw.json +7 -1
  53. package/dist/module/features/chatbot/components/Alternatives/Alternatives.js +17 -5
  54. package/dist/module/features/chatbot/components/Alternatives/Alternatives.js.map +1 -1
  55. package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js +147 -41
  56. package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js.map +1 -1
  57. package/dist/module/features/chatbot/components/Alternatives/InputButton.js +102 -0
  58. package/dist/module/features/chatbot/components/Alternatives/InputButton.js.map +1 -0
  59. package/dist/module/features/chatbot/components/Alternatives/InputWithHintRow.js +152 -0
  60. package/dist/module/features/chatbot/components/Alternatives/InputWithHintRow.js.map +1 -0
  61. package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
  62. package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
  63. package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js +1 -1
  64. package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +1 -1
  65. package/dist/module/features/exampleSolution/ExampleSolutionModal.js +25 -0
  66. package/dist/module/features/exampleSolution/ExampleSolutionModal.js.map +1 -0
  67. package/dist/module/features/exampleSolution/assets/grid.png +0 -0
  68. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js +91 -0
  69. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -0
  70. package/dist/module/features/exampleSolution/components/LavaIcon.js +36 -0
  71. package/dist/module/features/exampleSolution/components/LavaIcon.js.map +1 -0
  72. package/dist/module/features/exampleSolution/components/MessageBlock.js +53 -0
  73. package/dist/module/features/exampleSolution/components/MessageBlock.js.map +1 -0
  74. package/dist/module/features/exampleSolution/components/QuestionSection.js +60 -0
  75. package/dist/module/features/exampleSolution/components/QuestionSection.js.map +1 -0
  76. package/dist/module/features/exampleSolution/components/SolutionSection.js +67 -0
  77. package/dist/module/features/exampleSolution/components/SolutionSection.js.map +1 -0
  78. package/dist/module/features/exampleSolution/constants.js +9 -0
  79. package/dist/module/features/exampleSolution/constants.js.map +1 -0
  80. package/dist/module/features/exampleSolution/hooks/useExampleSolution.js +56 -0
  81. package/dist/module/features/exampleSolution/hooks/useExampleSolution.js.map +1 -0
  82. package/dist/module/features/exampleSolution/index.js +6 -0
  83. package/dist/module/features/exampleSolution/index.js.map +1 -0
  84. package/dist/module/features/exampleSolution/model/ExampleSolution.model.js +17 -0
  85. package/dist/module/features/exampleSolution/model/ExampleSolution.model.js.map +1 -0
  86. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js +27 -0
  87. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js.map +1 -0
  88. package/dist/module/features/exampleSolution/model/ExampleSolutionCache.js +13 -0
  89. package/dist/module/features/exampleSolution/model/ExampleSolutionCache.js.map +1 -0
  90. package/dist/module/features/exampleSolution/types.js +4 -0
  91. package/dist/module/features/exampleSolution/types.js.map +1 -0
  92. package/dist/module/index.js +2 -0
  93. package/dist/module/index.js.map +1 -1
  94. package/dist/module/shared/icons/ExcitedLavaIcon.js +673 -0
  95. package/dist/module/shared/icons/ExcitedLavaIcon.js.map +1 -0
  96. package/dist/module/shared/icons/LavaIconInGlasses.js +608 -0
  97. package/dist/module/shared/icons/LavaIconInGlasses.js.map +1 -0
  98. package/dist/module/shared/icons/index.js +21 -0
  99. package/dist/module/shared/icons/index.js.map +1 -0
  100. package/dist/module/shared/translation/localization/ca.json +7 -1
  101. package/dist/module/shared/translation/localization/en.json +8 -2
  102. package/dist/module/shared/translation/localization/gb.json +7 -1
  103. package/dist/module/shared/translation/localization/sct.json +7 -1
  104. package/dist/module/shared/translation/localization/sw.json +7 -1
  105. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/Alternatives.d.ts.map +1 -1
  106. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +3 -1
  107. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +1 -1
  108. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/InputButton.d.ts +9 -0
  109. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/InputButton.d.ts.map +1 -0
  110. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/InputWithHintRow.d.ts +10 -0
  111. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/InputWithHintRow.d.ts.map +1 -0
  112. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
  113. package/dist/typescript/commonjs/features/exampleSolution/ExampleSolutionModal.d.ts +11 -0
  114. package/dist/typescript/commonjs/features/exampleSolution/ExampleSolutionModal.d.ts.map +1 -0
  115. package/dist/typescript/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.d.ts +4 -0
  116. package/dist/typescript/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -0
  117. package/dist/typescript/commonjs/features/exampleSolution/components/LavaIcon.d.ts +10 -0
  118. package/dist/typescript/commonjs/features/exampleSolution/components/LavaIcon.d.ts.map +1 -0
  119. package/dist/typescript/commonjs/features/exampleSolution/components/MessageBlock.d.ts +10 -0
  120. package/dist/typescript/commonjs/features/exampleSolution/components/MessageBlock.d.ts.map +1 -0
  121. package/dist/typescript/commonjs/features/exampleSolution/components/QuestionSection.d.ts +9 -0
  122. package/dist/typescript/commonjs/features/exampleSolution/components/QuestionSection.d.ts.map +1 -0
  123. package/dist/typescript/commonjs/features/exampleSolution/components/SolutionSection.d.ts +9 -0
  124. package/dist/typescript/commonjs/features/exampleSolution/components/SolutionSection.d.ts.map +1 -0
  125. package/dist/typescript/commonjs/features/exampleSolution/constants.d.ts +6 -0
  126. package/dist/typescript/commonjs/features/exampleSolution/constants.d.ts.map +1 -0
  127. package/dist/typescript/commonjs/features/exampleSolution/hooks/useExampleSolution.d.ts +9 -0
  128. package/dist/typescript/commonjs/features/exampleSolution/hooks/useExampleSolution.d.ts.map +1 -0
  129. package/dist/typescript/commonjs/features/exampleSolution/index.d.ts +4 -0
  130. package/dist/typescript/commonjs/features/exampleSolution/index.d.ts.map +1 -0
  131. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolution.model.d.ts +9 -0
  132. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolution.model.d.ts.map +1 -0
  133. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionApi.d.ts +13 -0
  134. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -0
  135. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionCache.d.ts +11 -0
  136. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionCache.d.ts.map +1 -0
  137. package/dist/typescript/commonjs/features/exampleSolution/types.d.ts +26 -0
  138. package/dist/typescript/commonjs/features/exampleSolution/types.d.ts.map +1 -0
  139. package/dist/typescript/commonjs/index.d.ts +2 -0
  140. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  141. package/dist/typescript/commonjs/shared/icons/ExcitedLavaIcon.d.ts +4 -0
  142. package/dist/typescript/commonjs/shared/icons/ExcitedLavaIcon.d.ts.map +1 -0
  143. package/dist/typescript/commonjs/shared/icons/LavaIconInGlasses.d.ts +4 -0
  144. package/dist/typescript/commonjs/shared/icons/LavaIconInGlasses.d.ts.map +1 -0
  145. package/dist/typescript/commonjs/shared/icons/index.d.ts +19 -0
  146. package/dist/typescript/commonjs/shared/icons/index.d.ts.map +1 -0
  147. package/dist/typescript/commonjs/shared/translation/constants.d.ts +30 -0
  148. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  149. package/dist/typescript/commonjs/shared/translation/model.d.ts +12 -0
  150. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
  151. package/dist/typescript/module/features/chatbot/components/Alternatives/Alternatives.d.ts.map +1 -1
  152. package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +3 -1
  153. package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +1 -1
  154. package/dist/typescript/module/features/chatbot/components/Alternatives/InputButton.d.ts +9 -0
  155. package/dist/typescript/module/features/chatbot/components/Alternatives/InputButton.d.ts.map +1 -0
  156. package/dist/typescript/module/features/chatbot/components/Alternatives/InputWithHintRow.d.ts +10 -0
  157. package/dist/typescript/module/features/chatbot/components/Alternatives/InputWithHintRow.d.ts.map +1 -0
  158. package/dist/typescript/module/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
  159. package/dist/typescript/module/features/exampleSolution/ExampleSolutionModal.d.ts +11 -0
  160. package/dist/typescript/module/features/exampleSolution/ExampleSolutionModal.d.ts.map +1 -0
  161. package/dist/typescript/module/features/exampleSolution/components/ExampleSolutionModalContent.d.ts +4 -0
  162. package/dist/typescript/module/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -0
  163. package/dist/typescript/module/features/exampleSolution/components/LavaIcon.d.ts +10 -0
  164. package/dist/typescript/module/features/exampleSolution/components/LavaIcon.d.ts.map +1 -0
  165. package/dist/typescript/module/features/exampleSolution/components/MessageBlock.d.ts +10 -0
  166. package/dist/typescript/module/features/exampleSolution/components/MessageBlock.d.ts.map +1 -0
  167. package/dist/typescript/module/features/exampleSolution/components/QuestionSection.d.ts +9 -0
  168. package/dist/typescript/module/features/exampleSolution/components/QuestionSection.d.ts.map +1 -0
  169. package/dist/typescript/module/features/exampleSolution/components/SolutionSection.d.ts +9 -0
  170. package/dist/typescript/module/features/exampleSolution/components/SolutionSection.d.ts.map +1 -0
  171. package/dist/typescript/module/features/exampleSolution/constants.d.ts +6 -0
  172. package/dist/typescript/module/features/exampleSolution/constants.d.ts.map +1 -0
  173. package/dist/typescript/module/features/exampleSolution/hooks/useExampleSolution.d.ts +9 -0
  174. package/dist/typescript/module/features/exampleSolution/hooks/useExampleSolution.d.ts.map +1 -0
  175. package/dist/typescript/module/features/exampleSolution/index.d.ts +4 -0
  176. package/dist/typescript/module/features/exampleSolution/index.d.ts.map +1 -0
  177. package/dist/typescript/module/features/exampleSolution/model/ExampleSolution.model.d.ts +9 -0
  178. package/dist/typescript/module/features/exampleSolution/model/ExampleSolution.model.d.ts.map +1 -0
  179. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionApi.d.ts +13 -0
  180. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -0
  181. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionCache.d.ts +11 -0
  182. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionCache.d.ts.map +1 -0
  183. package/dist/typescript/module/features/exampleSolution/types.d.ts +26 -0
  184. package/dist/typescript/module/features/exampleSolution/types.d.ts.map +1 -0
  185. package/dist/typescript/module/index.d.ts +2 -0
  186. package/dist/typescript/module/index.d.ts.map +1 -1
  187. package/dist/typescript/module/shared/icons/ExcitedLavaIcon.d.ts +4 -0
  188. package/dist/typescript/module/shared/icons/ExcitedLavaIcon.d.ts.map +1 -0
  189. package/dist/typescript/module/shared/icons/LavaIconInGlasses.d.ts +4 -0
  190. package/dist/typescript/module/shared/icons/LavaIconInGlasses.d.ts.map +1 -0
  191. package/dist/typescript/module/shared/icons/index.d.ts +19 -0
  192. package/dist/typescript/module/shared/icons/index.d.ts.map +1 -0
  193. package/dist/typescript/module/shared/translation/constants.d.ts +30 -0
  194. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  195. package/dist/typescript/module/shared/translation/model.d.ts +12 -0
  196. package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
  197. package/package.json +6 -2
  198. package/src/features/chatbot/components/Alternatives/Alternatives.tsx +18 -8
  199. package/src/features/chatbot/components/Alternatives/HelpRequestOption.tsx +146 -35
  200. package/src/features/chatbot/components/Alternatives/InputButton.tsx +101 -0
  201. package/src/features/chatbot/components/Alternatives/InputWithHintRow.tsx +157 -0
  202. package/src/features/chatbot/components/ChatMessage/MessageLoader.tsx +6 -2
  203. package/src/features/chatbot/components/ChatMessages/ChatbotMessages.tsx +1 -1
  204. package/src/features/exampleSolution/ExampleSolutionModal.tsx +29 -0
  205. package/src/features/exampleSolution/assets/grid.png +0 -0
  206. package/src/features/exampleSolution/components/ExampleSolutionModalContent.tsx +71 -0
  207. package/src/features/exampleSolution/components/LavaIcon.tsx +35 -0
  208. package/src/features/exampleSolution/components/MessageBlock.tsx +67 -0
  209. package/src/features/exampleSolution/components/QuestionSection.tsx +56 -0
  210. package/src/features/exampleSolution/components/SolutionSection.tsx +69 -0
  211. package/src/features/exampleSolution/constants.ts +5 -0
  212. package/src/features/exampleSolution/hooks/useExampleSolution.ts +66 -0
  213. package/src/features/exampleSolution/index.ts +3 -0
  214. package/src/features/exampleSolution/model/ExampleSolution.model.ts +12 -0
  215. package/src/features/exampleSolution/model/ExampleSolutionApi.ts +33 -0
  216. package/src/features/exampleSolution/model/ExampleSolutionCache.ts +20 -0
  217. package/src/features/exampleSolution/types.ts +26 -0
  218. package/src/index.ts +2 -0
  219. package/src/shared/icons/ExcitedLavaIcon.tsx +541 -0
  220. package/src/shared/icons/LavaIconInGlasses.tsx +489 -0
  221. package/src/shared/icons/index.ts +18 -0
  222. package/src/shared/translation/localization/ca.json +7 -1
  223. package/src/shared/translation/localization/en.json +8 -2
  224. package/src/shared/translation/localization/gb.json +7 -1
  225. package/src/shared/translation/localization/sct.json +7 -1
  226. package/src/shared/translation/localization/sw.json +7 -1
@@ -0,0 +1,67 @@
1
+ import { StyleProp, StyleSheet, ViewStyle } from 'react-native'
2
+ import React from 'react'
3
+ import { COLORS, SPACING, Typography } from '@magmamath/react-native-ui'
4
+ import { useUnit } from 'effector-react'
5
+ import { $localization } from '../../../shared/translation'
6
+ import Animated, {
7
+ LinearTransition,
8
+ useAnimatedStyle,
9
+ withDelay,
10
+ withTiming,
11
+ } from 'react-native-reanimated'
12
+ import { ExampleSolutionStatuses } from '../constants'
13
+
14
+ type MessageBlockProps = {
15
+ status: ExampleSolutionStatuses
16
+ style?: StyleProp<ViewStyle>
17
+ }
18
+
19
+ export const MessageBlock = ({ status, style }: MessageBlockProps) => {
20
+ const localization = useUnit($localization)
21
+
22
+ const opacityAnimation = useAnimatedStyle(() => {
23
+ return {
24
+ opacity: withDelay(
25
+ 2000,
26
+ withTiming(status === ExampleSolutionStatuses.LOADING ? 1 : 0, { duration: 350 }),
27
+ ),
28
+ }
29
+ }, [status])
30
+
31
+ if (status === ExampleSolutionStatuses.CACHE) return null
32
+
33
+ return (
34
+ <Animated.View
35
+ layout={LinearTransition.duration(250)}
36
+ style={[styles.container, opacityAnimation, style]}
37
+ >
38
+ <Typography variant={'small'} numberOfLines={1}>
39
+ {status === ExampleSolutionStatuses.LOADING
40
+ ? localization.exampleSolution.letMeThink
41
+ : localization.exampleSolution.aha}
42
+ </Typography>
43
+ </Animated.View>
44
+ )
45
+ }
46
+
47
+ const styles = StyleSheet.create({
48
+ container: {
49
+ padding: SPACING[200],
50
+ backgroundColor: COLORS.NEUTRAL_3,
51
+ height: 44,
52
+ borderRadius: 12,
53
+ borderBottomRightRadius: 2,
54
+ borderWidth: StyleSheet.hairlineWidth,
55
+ borderColor: COLORS.NEUTRAL_5,
56
+
57
+ shadowColor: COLORS.NEUTRAL_10,
58
+ shadowOffset: {
59
+ width: 0,
60
+ height: 1,
61
+ },
62
+ shadowOpacity: 0.2,
63
+ shadowRadius: 1,
64
+
65
+ elevation: 3,
66
+ },
67
+ })
@@ -0,0 +1,56 @@
1
+ import { StyleSheet, View, ScrollView } from 'react-native'
2
+ import React from 'react'
3
+ import { COLORS, Loader, LoaderColor, SPACING, Typography } from '@magmamath/react-native-ui'
4
+ import Animated, { FadeOut } from 'react-native-reanimated'
5
+ import { ExampleSolutionStatuses } from '../constants'
6
+
7
+ type QuestionSectionProps = {
8
+ question?: string
9
+ status: ExampleSolutionStatuses
10
+ }
11
+
12
+ export const QuestionSection = ({ question, status }: QuestionSectionProps) => {
13
+ return (
14
+ <View style={styles.container}>
15
+ <ScrollView style={styles.scrollView}>
16
+ <Typography>{question}</Typography>
17
+ </ScrollView>
18
+ {status === ExampleSolutionStatuses.LOADING && (
19
+ <Animated.View exiting={FadeOut} style={styles.loaderContainer}>
20
+ <Loader size="large" color={LoaderColor.BLUE} />
21
+ </Animated.View>
22
+ )}
23
+ </View>
24
+ )
25
+ }
26
+
27
+ const styles = StyleSheet.create({
28
+ container: {
29
+ flex: 1,
30
+ },
31
+ scrollView: {
32
+ flex: 1,
33
+ },
34
+ loaderContainer: {
35
+ paddingTop: 34,
36
+ position: 'absolute',
37
+ width: '100%',
38
+ height: '100%',
39
+ backgroundColor: COLORS.NEUTRAL_1,
40
+ justifyContent: 'flex-start',
41
+ alignItems: 'center',
42
+ },
43
+ errorContainer: {
44
+ position: 'absolute',
45
+ width: '100%',
46
+ height: '100%',
47
+ backgroundColor: COLORS.NEUTRAL_1,
48
+ justifyContent: 'center',
49
+ alignItems: 'center',
50
+ padding: SPACING[400],
51
+ },
52
+ errorText: {
53
+ color: COLORS.PRIMARY_RED,
54
+ textAlign: 'center',
55
+ },
56
+ })
@@ -0,0 +1,69 @@
1
+ import { StyleSheet, View, Image, Text } from 'react-native'
2
+ import React from 'react'
3
+ import { COLORS, IS_WEB, SPACING } from '@magmamath/react-native-ui'
4
+ import Animated, { FadeIn } from 'react-native-reanimated'
5
+ import { ExampleSolutionStatuses } from '../constants'
6
+ import gridImage from '../assets/grid.png'
7
+
8
+ type SolutionSectionProps = {
9
+ answer?: string
10
+ status: ExampleSolutionStatuses
11
+ }
12
+
13
+ const gridImagePath = !IS_WEB ? Image.resolveAssetSource(gridImage).uri : gridImage
14
+
15
+ export const SolutionSection = ({ answer, status }: SolutionSectionProps) => {
16
+ const shouldShowAnswer =
17
+ answer &&
18
+ (status === ExampleSolutionStatuses.DONE_DATA || status === ExampleSolutionStatuses.CACHE)
19
+
20
+ return (
21
+ <View style={styles.container}>
22
+ <Image
23
+ source={{ uri: gridImagePath }}
24
+ style={[styles.gridImage, IS_WEB && styles.gridImageWeb]}
25
+ />
26
+ {shouldShowAnswer && (
27
+ <Animated.ScrollView
28
+ style={styles.solutionScroll}
29
+ contentContainerStyle={styles.solutionScrollContent}
30
+ entering={status === 'cache' ? undefined : FadeIn.delay(1000).duration(500)}
31
+ >
32
+ <Text style={styles.solutionText}>{answer}</Text>
33
+ </Animated.ScrollView>
34
+ )}
35
+ </View>
36
+ )
37
+ }
38
+
39
+ const styles = StyleSheet.create({
40
+ container: {
41
+ width: 500,
42
+ overflow: 'hidden',
43
+ borderRadius: 8,
44
+ borderWidth: 1,
45
+ borderColor: COLORS.NEUTRAL_5,
46
+ },
47
+ gridImage: {
48
+ width: '100%',
49
+ height: '100%',
50
+ resizeMode: 'cover',
51
+ aspectRatio: 28 / 8,
52
+ },
53
+ gridImageWeb: {
54
+ transform: [{ scale: 3.5 }],
55
+ },
56
+ solutionScroll: {
57
+ position: 'absolute',
58
+ width: '100%',
59
+ height: '100%',
60
+ },
61
+ solutionScrollContent: {
62
+ paddingHorizontal: SPACING[800],
63
+ paddingVertical: SPACING[400],
64
+ },
65
+ solutionText: {
66
+ fontFamily: 'PlaypenSans-Light',
67
+ fontSize: 22,
68
+ },
69
+ })
@@ -0,0 +1,5 @@
1
+ export const enum ExampleSolutionStatuses {
2
+ LOADING = 'loading',
3
+ DONE_DATA = 'doneData',
4
+ CACHE = 'cache',
5
+ }
@@ -0,0 +1,66 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { useUnit } from 'effector-react'
3
+ import { ExampleSolutionModalParams, ExampleSolutionResponse } from '../types'
4
+ import { ExampleSolutionStatuses } from '../constants'
5
+
6
+ const ANIMATION_DELAY = 600
7
+
8
+ type UseExampleSolutionReturn = {
9
+ result: ExampleSolutionResponse | null
10
+ status: ExampleSolutionStatuses
11
+ }
12
+
13
+ export const useExampleSolution = ({
14
+ model,
15
+ payload,
16
+ cacheKey,
17
+ }: ExampleSolutionModalParams): UseExampleSolutionReturn => {
18
+ const exampleSolutionsCache = useUnit(model.cache.$state)
19
+ const [result, setResult] = useState<ExampleSolutionResponse | null>(null)
20
+ const [status, setStatus] = useState<ExampleSolutionStatuses>(ExampleSolutionStatuses.LOADING)
21
+
22
+ useEffect(() => {
23
+ let timer: NodeJS.Timeout | null = null
24
+
25
+ const fetchExampleSolution = async () => {
26
+ try {
27
+ if (exampleSolutionsCache[cacheKey]) {
28
+ setResult(exampleSolutionsCache[cacheKey])
29
+ setStatus(ExampleSolutionStatuses.CACHE)
30
+ return
31
+ }
32
+
33
+ const startTime = Date.now()
34
+ const response = await model.api.generateExampleSolutionFx(payload)
35
+
36
+ setResult(response)
37
+ model.cache.addExampleSolution({ cacheKey, response })
38
+
39
+ const elapsedTime = Date.now() - startTime
40
+ if (elapsedTime >= ANIMATION_DELAY) {
41
+ setStatus(ExampleSolutionStatuses.DONE_DATA)
42
+ } else {
43
+ timer = setTimeout(() => {
44
+ setStatus(ExampleSolutionStatuses.DONE_DATA)
45
+ }, ANIMATION_DELAY - elapsedTime)
46
+ }
47
+ } catch (error) {
48
+ console.error('Failed to fetch example solution:', error)
49
+ setStatus(ExampleSolutionStatuses.DONE_DATA)
50
+ }
51
+ }
52
+
53
+ fetchExampleSolution()
54
+
55
+ return () => {
56
+ if (timer) {
57
+ clearTimeout(timer)
58
+ }
59
+ }
60
+ }, [])
61
+
62
+ return {
63
+ result,
64
+ status,
65
+ }
66
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ExampleSolutionModal'
2
+ export * from './model/ExampleSolution.model'
3
+ export * from './types'
@@ -0,0 +1,12 @@
1
+ import { GifCelebrationsModelProps } from '../types'
2
+ import { ExampleSolutionsApi } from './ExampleSolutionApi'
3
+ import { ExampleSolutionCache } from './ExampleSolutionCache'
4
+
5
+ export class ExampleSolutionModel {
6
+ public readonly api
7
+ public readonly cache = new ExampleSolutionCache()
8
+
9
+ constructor({ api, errorHandler }: GifCelebrationsModelProps) {
10
+ this.api = new ExampleSolutionsApi({ api, errorHandler })
11
+ }
12
+ }
@@ -0,0 +1,33 @@
1
+ import { createControllerEffect } from './../../../lib/effector/createControllerEffect'
2
+ import { ExampleSolutionApiRequests, ExampleSolutionErrorHandler } from '../types'
3
+ import { $localization } from '../../../shared/translation'
4
+ import { createEffect, sample, attach, StoreValue } from 'effector'
5
+
6
+ type ExampleSolutionApiProps = {
7
+ api: ExampleSolutionApiRequests
8
+ errorHandler?: ExampleSolutionErrorHandler
9
+ }
10
+
11
+ export class ExampleSolutionsApi {
12
+ public readonly generateExampleSolutionFx
13
+ public readonly errorHandlerFx?: ExampleSolutionErrorHandler
14
+
15
+ public readonly errorHandlingFx = attach({
16
+ source: $localization,
17
+ effect: createEffect((localization: StoreValue<typeof $localization>) => {
18
+ if (!this.errorHandlerFx) return
19
+ const errorMessage = localization.exampleSolution.errorMessage
20
+ this.errorHandlerFx(errorMessage)
21
+ }),
22
+ })
23
+
24
+ constructor({ api, errorHandler }: ExampleSolutionApiProps) {
25
+ this.generateExampleSolutionFx = createControllerEffect(api.generateExampleSolution)
26
+ this.errorHandlerFx = errorHandler
27
+
28
+ sample({
29
+ clock: this.generateExampleSolutionFx.fail,
30
+ target: this.errorHandlingFx,
31
+ })
32
+ }
33
+ }
@@ -0,0 +1,20 @@
1
+ import { createEvent, createStore } from 'effector'
2
+ import { ExampleSolutionResponse } from '../types'
3
+
4
+ type AddExampleSolution = {
5
+ cacheKey: string
6
+ response: ExampleSolutionResponse
7
+ }
8
+
9
+ export class ExampleSolutionCache {
10
+ public readonly addExampleSolution = createEvent<AddExampleSolution>()
11
+ public readonly $state = createStore<Record<string, ExampleSolutionResponse>>({}).on(
12
+ this.addExampleSolution,
13
+ (state, exampleSolution) => {
14
+ return {
15
+ ...state,
16
+ [exampleSolution.cacheKey]: exampleSolution.response,
17
+ }
18
+ },
19
+ )
20
+ }
@@ -0,0 +1,26 @@
1
+ import { ExampleSolutionModel } from './model/ExampleSolution.model'
2
+
3
+ export type ExampleSolutionPayload = {
4
+ question: string
5
+ answer: string
6
+ language: string
7
+ altText?: string
8
+ imageCdnId?: string
9
+ }
10
+ export type ExampleSolutionResponse = {
11
+ question: string
12
+ answer: string
13
+ }
14
+ export type ExampleSolutionApiRequests = {
15
+ generateExampleSolution: (body: ExampleSolutionPayload) => Promise<ExampleSolutionResponse>
16
+ }
17
+ export type ExampleSolutionErrorHandler = (errorMessage: string) => void
18
+ export type GifCelebrationsModelProps = {
19
+ api: ExampleSolutionApiRequests
20
+ errorHandler?: ExampleSolutionErrorHandler
21
+ }
22
+ export type ExampleSolutionModalParams = {
23
+ cacheKey: string
24
+ payload: ExampleSolutionPayload
25
+ model: ExampleSolutionModel
26
+ }
package/src/index.ts CHANGED
@@ -7,3 +7,5 @@ export * from './features/endOfAssignment'
7
7
  export * from './features/formulaSheet'
8
8
  export * from './features/problemSelector'
9
9
  export * from './features/gifCelebrations'
10
+ export * from './features/exampleSolution'
11
+ export * from './shared/icons'