@coorpacademy/app-review 0.1.14 → 0.1.16

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 (295) hide show
  1. package/es/actions/api/fetch-skills.d.ts +4 -6
  2. package/es/actions/api/fetch-skills.js +7 -4
  3. package/es/actions/api/fetch-slide.d.ts +14 -7
  4. package/es/actions/api/fetch-slide.js +27 -4
  5. package/es/actions/api/post-progression.d.ts +4 -6
  6. package/es/actions/api/post-progression.js +13 -9
  7. package/es/actions/api/test/create-test-store.d.ts +5 -0
  8. package/es/actions/api/test/create-test-store.js +16 -0
  9. package/es/actions/api/test/fetch-skills.test.js +54 -0
  10. package/es/actions/api/test/fetch-slide.test.js +61 -0
  11. package/es/actions/api/test/post-progression.test.js +102 -0
  12. package/es/actions/index.d.ts +1 -10
  13. package/es/actions/ui/answers.d.ts +7 -0
  14. package/es/actions/ui/answers.js +7 -0
  15. package/es/actions/ui/is-fetching.js +0 -2
  16. package/es/actions/ui/slides.d.ts +26 -0
  17. package/es/actions/ui/slides.js +9 -0
  18. package/es/common/index.d.ts +3 -1
  19. package/es/common/index.js +3 -1
  20. package/es/fixtures/qcm-slide.d.ts +2 -2
  21. package/es/fixtures/temp-fixture.d.ts +2 -2
  22. package/es/index.js +22 -92
  23. package/es/reducers/data/index.d.ts +2 -2
  24. package/es/reducers/data/progression.d.ts +3 -16
  25. package/es/reducers/data/progression.js +3 -22
  26. package/es/reducers/data/slides.d.ts +5 -6
  27. package/es/reducers/data/slides.js +9 -108
  28. package/es/reducers/data/test/progression.test.js +38 -0
  29. package/es/reducers/data/test/skills.test.js +12 -0
  30. package/es/reducers/data/test/slides.test.js +20 -0
  31. package/es/reducers/data/test/token.test.js +11 -0
  32. package/es/reducers/index.d.ts +3 -4
  33. package/es/reducers/ui/answers.d.ts +4 -0
  34. package/es/reducers/ui/{review-status.js → answers.js} +3 -3
  35. package/es/reducers/ui/current-slide-ref.d.ts +4 -0
  36. package/es/reducers/ui/current-slide-ref.js +13 -0
  37. package/es/reducers/ui/index.d.ts +7 -10
  38. package/es/reducers/ui/index.js +4 -6
  39. package/es/reducers/ui/test/answers.test.js +11 -0
  40. package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  41. package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
  42. package/es/reducers/ui/test/navigation.test.d.ts +1 -0
  43. package/es/reducers/ui/test/navigation.test.js +15 -0
  44. package/es/services/fetch-slide.js +1 -1
  45. package/es/services/index.js +3 -1
  46. package/es/services/post-answer.d.ts +2 -0
  47. package/es/services/post-answer.js +18 -0
  48. package/es/services/test/fetch-slide.test.d.ts +1 -0
  49. package/es/services/test/fetch-slide.test.js +22 -0
  50. package/es/services/test/post-answer.test.d.ts +1 -0
  51. package/es/services/test/post-answer.test.js +57 -0
  52. package/es/services/test/post-progression.test.js +14 -4
  53. package/es/test/util/services.mock.js +46 -4
  54. package/es/types/common.d.ts +61 -30
  55. package/es/types/common.js +0 -5
  56. package/es/types/slides.d.ts +0 -4
  57. package/{lib/types/views/skills.d.ts → es/views/skills/index.d.ts} +2 -0
  58. package/es/views/skills/index.js +25 -0
  59. package/es/views/slides/index.d.ts +79 -0
  60. package/es/views/slides/index.js +151 -0
  61. package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
  62. package/es/views/slides/map-api-slide-to-ui.js +172 -0
  63. package/es/views/slides/test/fixtures/free-text.d.ts +3 -0
  64. package/es/views/slides/test/fixtures/free-text.js +38 -0
  65. package/es/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
  66. package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
  67. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
  68. package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
  69. package/es/views/slides/test/fixtures/qcm.d.ts +3 -0
  70. package/es/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
  71. package/es/views/slides/test/fixtures/select-template.d.ts +3 -0
  72. package/es/views/slides/test/fixtures/select-template.js +92 -0
  73. package/es/views/slides/test/fixtures/slider.d.ts +3 -0
  74. package/es/views/slides/test/fixtures/slider.js +36 -0
  75. package/es/views/slides/test/fixtures/text-template.d.ts +3 -0
  76. package/es/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
  77. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  78. package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  79. package/lib/actions/api/fetch-skills.d.ts +4 -6
  80. package/lib/actions/api/fetch-skills.js +55 -7
  81. package/lib/actions/api/fetch-slide.d.ts +14 -7
  82. package/lib/actions/api/fetch-slide.js +75 -7
  83. package/lib/actions/api/post-progression.d.ts +4 -6
  84. package/lib/actions/api/post-progression.js +63 -10
  85. package/lib/actions/api/test/create-test-store.d.ts +5 -0
  86. package/lib/actions/api/test/create-test-store.js +18 -0
  87. package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
  88. package/lib/actions/api/test/fetch-skills.test.js +113 -0
  89. package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
  90. package/lib/actions/api/test/fetch-slide.test.js +120 -0
  91. package/lib/actions/api/test/post-progression.test.d.ts +1 -0
  92. package/lib/actions/api/test/post-progression.test.js +160 -0
  93. package/lib/actions/index.d.ts +1 -10
  94. package/lib/actions/ui/answers.d.ts +7 -0
  95. package/lib/actions/ui/answers.js +9 -0
  96. package/lib/actions/ui/is-fetching.js +0 -2
  97. package/lib/actions/ui/slides.d.ts +26 -0
  98. package/lib/actions/ui/slides.js +9 -0
  99. package/lib/common/index.d.ts +3 -1
  100. package/lib/common/index.js +3 -1
  101. package/lib/fixtures/qcm-slide.d.ts +2 -2
  102. package/lib/fixtures/temp-fixture.d.ts +2 -2
  103. package/lib/index.js +33 -94
  104. package/lib/reducers/data/index.d.ts +2 -2
  105. package/lib/reducers/data/progression.d.ts +3 -16
  106. package/lib/reducers/data/progression.js +3 -22
  107. package/lib/reducers/data/slides.d.ts +5 -6
  108. package/lib/reducers/data/slides.js +9 -114
  109. package/lib/reducers/data/test/progression.test.d.ts +1 -0
  110. package/lib/reducers/data/test/progression.test.js +38 -0
  111. package/lib/reducers/data/test/skills.test.d.ts +1 -0
  112. package/lib/reducers/data/test/skills.test.js +12 -0
  113. package/lib/reducers/data/test/slides.test.d.ts +1 -0
  114. package/lib/reducers/data/test/slides.test.js +20 -0
  115. package/lib/reducers/data/test/token.test.d.ts +1 -0
  116. package/lib/reducers/data/test/token.test.js +11 -0
  117. package/lib/reducers/index.d.ts +3 -4
  118. package/lib/reducers/ui/answers.d.ts +4 -0
  119. package/lib/reducers/ui/{review-status.js → answers.js} +3 -3
  120. package/lib/reducers/ui/current-slide-ref.d.ts +4 -0
  121. package/lib/reducers/ui/current-slide-ref.js +14 -0
  122. package/lib/reducers/ui/index.d.ts +7 -10
  123. package/lib/reducers/ui/index.js +4 -6
  124. package/lib/reducers/ui/test/answers.test.d.ts +1 -0
  125. package/lib/reducers/ui/test/answers.test.js +11 -0
  126. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  127. package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
  128. package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
  129. package/lib/reducers/ui/test/navigation.test.js +15 -0
  130. package/lib/services/fetch-slide.js +1 -1
  131. package/lib/services/index.js +3 -1
  132. package/lib/services/post-answer.d.ts +2 -0
  133. package/lib/services/post-answer.js +62 -0
  134. package/lib/services/test/fetch-slide.test.d.ts +1 -0
  135. package/lib/services/test/fetch-slide.test.js +76 -0
  136. package/lib/services/test/post-answer.test.d.ts +1 -0
  137. package/lib/services/test/post-answer.test.js +111 -0
  138. package/lib/services/test/post-progression.test.js +14 -4
  139. package/lib/test/util/services.mock.js +46 -4
  140. package/lib/types/common.d.ts +61 -30
  141. package/lib/types/common.js +0 -5
  142. package/lib/types/slides.d.ts +0 -4
  143. package/{es/types/views/skills.d.ts → lib/views/skills/index.d.ts} +2 -0
  144. package/lib/views/skills/index.js +25 -0
  145. package/lib/views/slides/index.d.ts +79 -0
  146. package/lib/views/slides/index.js +155 -0
  147. package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
  148. package/lib/views/slides/map-api-slide-to-ui.js +178 -0
  149. package/lib/views/slides/test/fixtures/free-text.d.ts +3 -0
  150. package/lib/views/slides/test/fixtures/free-text.js +38 -0
  151. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
  152. package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
  153. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
  154. package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
  155. package/lib/views/slides/test/fixtures/qcm.d.ts +3 -0
  156. package/lib/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
  157. package/lib/views/slides/test/fixtures/select-template.d.ts +3 -0
  158. package/lib/views/slides/test/fixtures/select-template.js +92 -0
  159. package/lib/views/slides/test/fixtures/slider.d.ts +3 -0
  160. package/lib/views/slides/test/fixtures/slider.js +36 -0
  161. package/lib/views/slides/test/fixtures/text-template.d.ts +3 -0
  162. package/lib/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
  163. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  164. package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  165. package/package.json +4 -3
  166. package/src/actions/api/fetch-skills.ts +12 -12
  167. package/src/actions/api/fetch-slide.ts +38 -13
  168. package/src/actions/api/post-progression.ts +18 -22
  169. package/src/actions/api/test/create-test-store.ts +25 -0
  170. package/src/actions/api/test/fetch-skills.test.ts +70 -0
  171. package/src/actions/api/test/fetch-slide.test.ts +77 -0
  172. package/src/actions/api/test/post-progression.test.ts +119 -0
  173. package/src/actions/index.ts +1 -10
  174. package/src/actions/ui/answers.ts +16 -0
  175. package/src/actions/ui/is-fetching.ts +0 -6
  176. package/src/actions/ui/slides.ts +35 -0
  177. package/src/common/index.ts +7 -1
  178. package/src/fixtures/qcm-slide.ts +2 -2
  179. package/src/fixtures/temp-fixture.ts +2 -2
  180. package/src/index.tsx +26 -110
  181. package/src/reducers/data/index.ts +1 -1
  182. package/src/reducers/data/progression.ts +5 -40
  183. package/src/reducers/data/slides.ts +17 -125
  184. package/src/reducers/data/test/progression.test.ts +42 -0
  185. package/src/reducers/data/test/skills.test.ts +14 -0
  186. package/src/reducers/data/test/slides.test.ts +26 -0
  187. package/src/reducers/data/test/token.test.ts +13 -0
  188. package/src/reducers/ui/answers.ts +19 -0
  189. package/src/reducers/ui/current-slide-ref.ts +19 -0
  190. package/src/reducers/ui/index.ts +6 -9
  191. package/src/reducers/ui/test/answers.test.ts +13 -0
  192. package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
  193. package/src/reducers/ui/test/navigation.test.ts +19 -0
  194. package/src/services/fetch-slide.ts +1 -1
  195. package/src/services/index.ts +3 -1
  196. package/src/services/post-answer.ts +27 -0
  197. package/src/services/test/fetch-slide.test.ts +30 -0
  198. package/src/services/test/post-answer.test.ts +68 -0
  199. package/src/services/test/post-progression.test.ts +14 -4
  200. package/src/test/util/services.mock.ts +46 -4
  201. package/src/types/common.ts +77 -40
  202. package/src/types/slides.ts +0 -5
  203. package/src/views/skills/index.ts +56 -0
  204. package/src/views/slides/index.ts +251 -0
  205. package/src/views/slides/map-api-slide-to-ui.ts +251 -0
  206. package/src/views/slides/test/fixtures/free-text.ts +43 -0
  207. package/src/views/slides/test/fixtures/qcm-drag.ts +111 -0
  208. package/src/views/slides/test/fixtures/qcm-graphic.ts +94 -0
  209. package/src/{helpers → views/slides}/test/fixtures/qcm.ts +43 -33
  210. package/src/views/slides/test/fixtures/select-template.ts +98 -0
  211. package/src/views/slides/test/fixtures/slider.ts +41 -0
  212. package/src/{helpers → views/slides}/test/fixtures/text-template.ts +23 -14
  213. package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +22 -20
  214. package/es/actions/data/slides.d.ts +0 -37
  215. package/es/actions/data/slides.js +0 -16
  216. package/es/actions/ui/finished-slides.d.ts +0 -10
  217. package/es/actions/ui/finished-slides.js +0 -8
  218. package/es/actions/ui/review-status.d.ts +0 -7
  219. package/es/actions/ui/review-status.js +0 -7
  220. package/es/actions/ui/step-items.d.ts +0 -24
  221. package/es/actions/ui/step-items.js +0 -11
  222. package/es/helpers/map-api-slide-to-ui.d.ts +0 -8
  223. package/es/helpers/map-api-slide-to-ui.js +0 -175
  224. package/es/helpers/test/fixtures/free-text.d.ts +0 -4
  225. package/es/helpers/test/fixtures/free-text.js +0 -24
  226. package/es/helpers/test/fixtures/qcm-drag.d.ts +0 -4
  227. package/es/helpers/test/fixtures/qcm-drag.js +0 -106
  228. package/es/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
  229. package/es/helpers/test/fixtures/qcm-graphic.js +0 -70
  230. package/es/helpers/test/fixtures/qcm.d.ts +0 -4
  231. package/es/helpers/test/fixtures/select-template.d.ts +0 -4
  232. package/es/helpers/test/fixtures/select-template.js +0 -88
  233. package/es/helpers/test/fixtures/slider.d.ts +0 -4
  234. package/es/helpers/test/fixtures/slider.js +0 -27
  235. package/es/helpers/test/fixtures/text-template.d.ts +0 -4
  236. package/es/reducers/ui/finished-slides.d.ts +0 -7
  237. package/es/reducers/ui/finished-slides.js +0 -33
  238. package/es/reducers/ui/review-status.d.ts +0 -4
  239. package/es/reducers/ui/step-items.d.ts +0 -14
  240. package/es/reducers/ui/step-items.js +0 -74
  241. package/es/types/ui-progression.d.ts +0 -10
  242. package/es/types/views/slides.d.ts +0 -60
  243. package/lib/actions/data/slides.d.ts +0 -37
  244. package/lib/actions/data/slides.js +0 -16
  245. package/lib/actions/ui/finished-slides.d.ts +0 -10
  246. package/lib/actions/ui/finished-slides.js +0 -8
  247. package/lib/actions/ui/review-status.d.ts +0 -7
  248. package/lib/actions/ui/review-status.js +0 -7
  249. package/lib/actions/ui/step-items.d.ts +0 -24
  250. package/lib/actions/ui/step-items.js +0 -11
  251. package/lib/helpers/map-api-slide-to-ui.d.ts +0 -8
  252. package/lib/helpers/map-api-slide-to-ui.js +0 -181
  253. package/lib/helpers/test/fixtures/free-text.d.ts +0 -4
  254. package/lib/helpers/test/fixtures/free-text.js +0 -24
  255. package/lib/helpers/test/fixtures/qcm-drag.d.ts +0 -4
  256. package/lib/helpers/test/fixtures/qcm-drag.js +0 -106
  257. package/lib/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
  258. package/lib/helpers/test/fixtures/qcm-graphic.js +0 -70
  259. package/lib/helpers/test/fixtures/qcm.d.ts +0 -4
  260. package/lib/helpers/test/fixtures/select-template.d.ts +0 -4
  261. package/lib/helpers/test/fixtures/select-template.js +0 -88
  262. package/lib/helpers/test/fixtures/slider.d.ts +0 -4
  263. package/lib/helpers/test/fixtures/slider.js +0 -27
  264. package/lib/helpers/test/fixtures/text-template.d.ts +0 -4
  265. package/lib/reducers/ui/finished-slides.d.ts +0 -7
  266. package/lib/reducers/ui/finished-slides.js +0 -45
  267. package/lib/reducers/ui/review-status.d.ts +0 -4
  268. package/lib/reducers/ui/step-items.d.ts +0 -14
  269. package/lib/reducers/ui/step-items.js +0 -86
  270. package/lib/types/ui-progression.d.ts +0 -10
  271. package/lib/types/views/slides.d.ts +0 -60
  272. package/src/actions/data/slides.ts +0 -65
  273. package/src/actions/ui/finished-slides.ts +0 -21
  274. package/src/actions/ui/review-status.ts +0 -19
  275. package/src/actions/ui/step-items.ts +0 -45
  276. package/src/helpers/map-api-slide-to-ui.ts +0 -253
  277. package/src/helpers/test/fixtures/free-text.ts +0 -28
  278. package/src/helpers/test/fixtures/qcm-drag.ts +0 -110
  279. package/src/helpers/test/fixtures/qcm-graphic.ts +0 -74
  280. package/src/helpers/test/fixtures/select-template.ts +0 -92
  281. package/src/helpers/test/fixtures/slider.ts +0 -31
  282. package/src/reducers/ui/finished-slides.ts +0 -52
  283. package/src/reducers/ui/review-status.ts +0 -19
  284. package/src/reducers/ui/step-items.ts +0 -116
  285. package/src/types/ui-progression.ts +0 -25
  286. package/src/types/views/skills.ts +0 -27
  287. package/src/types/views/slides.ts +0 -65
  288. /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
  289. /package/es/{types/ui-progression.js → actions/api/test/fetch-slide.test.d.ts} +0 -0
  290. /package/es/{types/views/skills.js → actions/api/test/post-progression.test.d.ts} +0 -0
  291. /package/es/{types/views/slides.js → reducers/data/test/progression.test.d.ts} +0 -0
  292. /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/reducers/data/test/skills.test.d.ts} +0 -0
  293. /package/{lib/types/ui-progression.js → es/reducers/data/test/slides.test.d.ts} +0 -0
  294. /package/{lib/types/views/skills.js → es/reducers/data/test/token.test.d.ts} +0 -0
  295. /package/{lib/types/views/slides.js → es/reducers/ui/test/answers.test.d.ts} +0 -0
@@ -0,0 +1,251 @@
1
+ import concat from 'lodash/fp/concat';
2
+
3
+ import get from 'lodash/fp/get';
4
+ import getOr from 'lodash/fp/getOr';
5
+ import isEmpty from 'lodash/fp/isEmpty';
6
+ import pipe from 'lodash/fp/pipe';
7
+ import reduce from 'lodash/fp/reduce';
8
+ import set from 'lodash/fp/set';
9
+ import slice from 'lodash/fp/slice';
10
+ import toInteger from 'lodash/fp/toInteger';
11
+ import {Dispatch} from 'redux';
12
+ import {ProgressionFromAPI, UISlide} from '../../types/common';
13
+ import {SlideIndexes} from '../../common';
14
+ import {StoreState} from '../../reducers';
15
+ import {mapApiSlideToUi} from './map-api-slide-to-ui';
16
+
17
+ const ICON_VALUES = {
18
+ right: 'right',
19
+ wrong: 'wrong',
20
+ 'no-answer': 'no-answer'
21
+ } as const;
22
+
23
+ type IconValue = keyof typeof ICON_VALUES;
24
+
25
+ type StepItem = {
26
+ current: boolean;
27
+ icon: IconValue;
28
+ value: string;
29
+ };
30
+
31
+ type SlidesStack = {
32
+ [key in SlideIndexes]: UISlide;
33
+ };
34
+
35
+ export type CorrectionPopinProps = {
36
+ klf: {
37
+ label: string;
38
+ onClick: Function;
39
+ tooltip: string;
40
+ };
41
+ information: {
42
+ label: string;
43
+ message: string;
44
+ };
45
+ next: {
46
+ label: string;
47
+ ariaLabel: string;
48
+ };
49
+ successLabel: string;
50
+ failureLabel: string;
51
+ };
52
+
53
+ export type SlidesViewProps = {
54
+ header: {
55
+ mode: string;
56
+ skillName: string;
57
+ onQuitClick: Function;
58
+ 'aria-label'?: string;
59
+ closeButtonAriaLabel: string;
60
+ steps: StepItem[];
61
+ };
62
+ stack: {
63
+ slides: SlidesStack;
64
+ validateButton: {
65
+ label: string;
66
+ disabled: boolean;
67
+ onClick: Function;
68
+ };
69
+ correctionPopinProps?: CorrectionPopinProps;
70
+ endReview: boolean;
71
+ };
72
+ reviewBackgroundAriaLabel?: string;
73
+ congratsProps?: {
74
+ 'aria-label'?: string;
75
+ 'data-name'?: string;
76
+ animationLottie: unknown;
77
+ title: string;
78
+ cardCongratsStar: unknown;
79
+ cardCongratsRank: unknown;
80
+ buttonRevising: {
81
+ 'aria-label'?: string;
82
+ label: string;
83
+ onClick: Function;
84
+ type: string;
85
+ };
86
+ buttonRevisingSkill: {
87
+ 'aria-label'?: string;
88
+ label: string;
89
+ onClick: Function;
90
+ type: string;
91
+ };
92
+ };
93
+ };
94
+
95
+ export const initialState: SlidesStack = {
96
+ '0': {
97
+ hidden: false,
98
+ position: 0
99
+ },
100
+ '1': {
101
+ hidden: false,
102
+ position: 1
103
+ },
104
+ '2': {
105
+ hidden: false,
106
+ position: 2
107
+ },
108
+ '3': {
109
+ hidden: false,
110
+ position: 3
111
+ },
112
+ '4': {
113
+ hidden: false,
114
+ position: 4
115
+ }
116
+ };
117
+
118
+ const getProgressionSlidesRef = (progression: ProgressionFromAPI): string[] => {
119
+ if (progression.state.step.current < 5) {
120
+ const slideRef = progression.state.nextContent.ref;
121
+ return concat([slideRef], progression.state.slides);
122
+ }
123
+ return slice(0, 5, progression.state.slides);
124
+ };
125
+
126
+ const buildStackSlides = (state: StoreState, dispatch: Dispatch): SlidesStack => {
127
+ const currentSlideRef = state.ui.currentSlideRef;
128
+ const progression = state.data.progression;
129
+
130
+ if (!currentSlideRef || !progression) return initialState;
131
+ const slideRefs = getProgressionSlidesRef(progression);
132
+
133
+ // @ts-expect-error typescript does not support capped versions of lodash functions
134
+ const stack = reduce.convert({cap: false})(
135
+ (acc: SlidesStack, uiSlide: UISlide, index: string) => {
136
+ const slideRef = slideRefs[toInteger(index)];
137
+ if (!slideRef) return set(index, uiSlide, acc);
138
+
139
+ const slideFromAPI = get(slideRef, state.data.slides);
140
+ const answers = state.ui.answers;
141
+ const {questionText, answerUI} = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
142
+ const parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
143
+ const parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
144
+
145
+ const updatedUiSlide = pipe(
146
+ set(['questionText'], questionText),
147
+ set(['answerUI'], answerUI),
148
+ set(['parentContentTitle'], `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
149
+ // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
150
+ )(uiSlide);
151
+
152
+ return set(index, updatedUiSlide, acc);
153
+ },
154
+ initialState,
155
+ initialState
156
+ );
157
+
158
+ return stack;
159
+ };
160
+
161
+ const buildStepItems = (state: StoreState): StepItem[] => {
162
+ const {progression} = state.data;
163
+ const {currentSlideRef} = state.ui;
164
+ if (!progression) return [];
165
+
166
+ const defaultProps: StepItem[] = [
167
+ {
168
+ icon: 'no-answer',
169
+ current: true,
170
+ value: '1'
171
+ },
172
+ {
173
+ icon: 'no-answer',
174
+ current: false,
175
+ value: '2'
176
+ },
177
+ {
178
+ icon: 'no-answer',
179
+ current: false,
180
+ value: '3'
181
+ },
182
+ {
183
+ icon: 'no-answer',
184
+ current: false,
185
+ value: '4'
186
+ },
187
+ {
188
+ icon: 'no-answer',
189
+ current: false,
190
+ value: '5'
191
+ }
192
+ ];
193
+
194
+ const allAnswers = progression.state.allAnswers;
195
+ const step = progression.state.step;
196
+ if (isEmpty(allAnswers)) return defaultProps;
197
+
198
+ const steps = defaultProps.map((stepItem, index): StepItem => {
199
+ const givenAnswer = allAnswers[index];
200
+ if (!givenAnswer) {
201
+ return {
202
+ ...stepItem,
203
+ current: step.current === index + 1
204
+ };
205
+ }
206
+
207
+ return {
208
+ ...stepItem,
209
+ icon: givenAnswer.isCorrect ? 'right' : 'wrong',
210
+ current: givenAnswer.slideRef === currentSlideRef
211
+ };
212
+ });
213
+ return steps;
214
+ };
215
+
216
+ export const mapStateToSlidesProps = (
217
+ state: StoreState,
218
+ dispatch: Dispatch
219
+ ): SlidesViewProps | null => {
220
+ if (!state.data.slides) {
221
+ return null;
222
+ }
223
+
224
+ return {
225
+ header: {
226
+ mode: '__revision_mode',
227
+ skillName: '__agility',
228
+ onQuitClick: (): void => {
229
+ // eslint-disable-next-line no-console
230
+ console.log('onQuitClick');
231
+ },
232
+ 'aria-label': 'aria-header-wrapper',
233
+ closeButtonAriaLabel: 'aria-close-button',
234
+ steps: buildStepItems(state)
235
+ },
236
+ stack: {
237
+ slides: buildStackSlides(state, dispatch),
238
+ validateButton: {
239
+ label: '__validate',
240
+ disabled: true,
241
+ onClick: (): void => {
242
+ // eslint-disable-next-line no-console
243
+ console.log('TODO: validate question');
244
+ }
245
+ },
246
+ correctionPopinProps: undefined,
247
+ endReview: false
248
+ },
249
+ congratsProps: undefined
250
+ };
251
+ };
@@ -0,0 +1,251 @@
1
+ import {
2
+ concat,
3
+ divide,
4
+ get,
5
+ getOr,
6
+ head,
7
+ includes,
8
+ indexOf,
9
+ isEmpty,
10
+ map,
11
+ rangeStep,
12
+ size,
13
+ toInteger
14
+ } from 'lodash/fp';
15
+ import {Dispatch} from 'redux';
16
+ import {
17
+ AnswerUI,
18
+ FreeText,
19
+ Qcm,
20
+ QcmDrag,
21
+ QcmGraphic,
22
+ QuestionRange,
23
+ SelectionTemplate,
24
+ Template,
25
+ TextTemplate
26
+ } from '../../types/slides';
27
+ import {
28
+ BasicQuestion,
29
+ ChoiceFromAPI,
30
+ QcmDragQuestion,
31
+ QcmGraphicQuestion,
32
+ QcmQuestion,
33
+ Question,
34
+ SlideFromAPI,
35
+ SliderQuestion,
36
+ TemplateQuestion
37
+ } from '../../types/common';
38
+ import {editAnswer} from '../../actions/ui/answers';
39
+
40
+ const qcmProps = (question: QcmQuestion): Qcm => {
41
+ // TODO: EDIT_CHOICES -> getAnswerValues
42
+ const answers: string[] = [];
43
+
44
+ return {
45
+ type: 'qcm',
46
+ answers: map(
47
+ choice => ({
48
+ title: choice.label,
49
+ selected: includes(choice.label, answers),
50
+ // TODO: EDIT_CHOICES
51
+ // eslint-disable-next-line no-console
52
+ onClick: () => console.log('TODO: on choice click'),
53
+ ariaLabel: choice.label
54
+ }),
55
+ // TODO: EDIT_CHOICES -> getChoices
56
+ question.content.choices
57
+ )
58
+ };
59
+ };
60
+
61
+ const qcmDragProps = (question: QcmDragQuestion): QcmDrag => {
62
+ // TODO: EDIT_CHOICES -> getAnswerValues
63
+ const answers: string[] = [];
64
+ return {
65
+ type: 'qcmDrag',
66
+ answers: map(choice => {
67
+ const indexInAnswer = indexOf(choice.label, answers);
68
+ return {
69
+ title: choice.label,
70
+ selected: includes(choice.label, answers),
71
+ order: indexInAnswer,
72
+ // TODO: EDIT_CHOICES
73
+ // eslint-disable-next-line no-console
74
+ onClick: () => console.log('TODO: on choice click')
75
+ };
76
+ // TODO: EDIT_CHOICES -> getChoices
77
+ }, question.content.choices)
78
+ };
79
+ };
80
+
81
+ const qcmGraphicProps = (question: QcmGraphicQuestion): QcmGraphic => {
82
+ // mock the answers
83
+ // TODO: EDIT_CHOICES -> getAnswerValues
84
+ const answers: string[] = [];
85
+ return {
86
+ type: 'qcmGraphic',
87
+ answers: map(
88
+ choice => ({
89
+ title: choice.label,
90
+ image: get('media.src.0.url', choice),
91
+ selected: includes(choice.label, answers),
92
+ // TODO: EDIT_CHOICES
93
+ // eslint-disable-next-line no-console
94
+ onClick: () => console.log('TODO: on choice click')
95
+ }),
96
+ // TODO: EDIT_CHOICES -> getChoices
97
+ question.content.choices
98
+ )
99
+ };
100
+ };
101
+
102
+ const templateTextProps = (choice: ChoiceFromAPI, index: number): TextTemplate => {
103
+ // TODO: EDIT_CHOICES -> getAnswerValues
104
+ const answers: string[] = [];
105
+ return {
106
+ type: 'text',
107
+ name: getOr('', 'name', choice), // TODO prendre valeur depuis les données de l'api
108
+ placeholder: 'Type here',
109
+ value: get(index, answers),
110
+ // TODO: EDIT_CHOICES
111
+ // eslint-disable-next-line no-console
112
+ onChange: () => console.log('TODO: on choice change')
113
+ };
114
+ };
115
+
116
+ const templateSelectProps = (choice: ChoiceFromAPI, index: number): SelectionTemplate => {
117
+ // TODO: EDIT_CHOICES -> getAnswerValues
118
+ const answers: string[] = [];
119
+ const answer = get(index, answers);
120
+ const temporaryOption = {
121
+ name: 'Select an answer', // TODO translate
122
+ value: '',
123
+ validOption: false,
124
+ selected: true
125
+ };
126
+ const selectOptions = choice.items.map(item => {
127
+ const itemText = getOr('', 'text', item);
128
+ return {
129
+ name: itemText,
130
+ value: itemText,
131
+ validOption: true,
132
+ selected: itemText === answer
133
+ };
134
+ });
135
+
136
+ return {
137
+ type: 'select',
138
+ name: getOr('', 'name', choice),
139
+ // TODO: EDIT_CHOICES
140
+ // eslint-disable-next-line no-console
141
+ onChange: () => console.log('TODO: on choice change'),
142
+ options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
143
+ };
144
+ };
145
+
146
+ const templateProps = (question: TemplateQuestion): Template => {
147
+ // TODO: EDIT_CHOICES -> getChoices
148
+ const choices = question.content.choices;
149
+ return {
150
+ type: 'template',
151
+ template: get('content.template', question),
152
+ answers: choices.map((choice, index) =>
153
+ choice.type === 'text' ? templateTextProps(choice, index) : templateSelectProps(choice, index)
154
+ )
155
+ };
156
+ };
157
+
158
+ const basicProps =
159
+ (dispatch: Dispatch) =>
160
+ (answers: string[], question: BasicQuestion): FreeText => {
161
+ return {
162
+ type: 'freeText',
163
+ placeholder: question.content.placeholder || '',
164
+ value: answers[0] || '',
165
+ onChange: (text: string): void => {
166
+ // eslint-disable-next-line no-console
167
+ console.log(text);
168
+ dispatch(editAnswer(text));
169
+ }
170
+ };
171
+ };
172
+
173
+ const sliderProps = (question: SliderQuestion): QuestionRange => {
174
+ const values: number[] = rangeStep(
175
+ getOr(1, 'content.step', question),
176
+ get('content.min', question),
177
+ get('content.max', question) + 1
178
+ // Lodash doesn't infer the type very well here
179
+ ) as unknown as number[];
180
+
181
+ // TODO: EDIT_CHOICES -> getAnswerValues
182
+ const answers: string[] = [];
183
+
184
+ const stateValue = head(answers) || question.content.min;
185
+ const currentValue = toInteger(stateValue);
186
+
187
+ const indexValue = indexOf(currentValue, values);
188
+ const sliderPosition = divide(indexValue, size(values) - 1);
189
+
190
+ const unitLabel = get('content.unitLabel', question);
191
+
192
+ return {
193
+ type: 'slider',
194
+ placeholder: question.explanation,
195
+ minLabel: `${question.content.min} ${unitLabel}`,
196
+ maxLabel: `${question.content.max} ${unitLabel}`,
197
+ title: `${currentValue} ${question.content.unitLabel}`,
198
+ value: sliderPosition,
199
+ // TODO: EDIT_CHOICES
200
+ // eslint-disable-next-line no-console
201
+ onChange: () => console.log('TODO: on choice change')
202
+ };
203
+ };
204
+
205
+ export const getQuestionType = (question: Question): Question['type'] => question.type;
206
+
207
+ const getHelp = (slide: SlideFromAPI): string => get('question.explanation', slide);
208
+
209
+ const getAnswerUIModel = (
210
+ question: Question,
211
+ answers: string[],
212
+ dispatch: Dispatch
213
+ ): AnswerUI['model'] => {
214
+ const type = getQuestionType(question);
215
+ switch (type) {
216
+ case 'qcm':
217
+ return qcmProps(question as QcmQuestion);
218
+
219
+ case 'qcmGraphic':
220
+ return qcmGraphicProps(question as QcmGraphicQuestion);
221
+
222
+ case 'qcmDrag':
223
+ return qcmDragProps(question as QcmDragQuestion);
224
+
225
+ case 'basic':
226
+ return basicProps(dispatch)(answers, question as BasicQuestion);
227
+
228
+ case 'template':
229
+ return templateProps(question as TemplateQuestion);
230
+
231
+ case 'slider':
232
+ return sliderProps(question as SliderQuestion);
233
+
234
+ default:
235
+ throw new Error(`${type} is not an handled question.type`);
236
+ }
237
+ };
238
+
239
+ export const mapApiSlideToUi =
240
+ (dispatch: Dispatch) =>
241
+ (slide: SlideFromAPI, answers: string[]): {questionText: string; answerUI: AnswerUI} => {
242
+ if (!slide) {
243
+ throw new Error('no slide was found');
244
+ }
245
+ const questionText = getOr('', 'question.header', slide);
246
+
247
+ return {
248
+ questionText,
249
+ answerUI: {model: getAnswerUIModel(slide.question, answers, dispatch), help: getHelp(slide)}
250
+ };
251
+ };
@@ -0,0 +1,43 @@
1
+ import noop from 'lodash/fp/noop';
2
+ import {SlideFromAPI, UISlide} from '../../../../types/common';
3
+
4
+ export const freeTextSlide: SlideFromAPI = {
5
+ question: {
6
+ content: {
7
+ media: {
8
+ src: [],
9
+ posters: [],
10
+ subtitles: []
11
+ },
12
+ label: '',
13
+ placeholder: 'Type here',
14
+ id: 'sli_VJYjJnJhg.choice_1'
15
+ },
16
+ type: 'basic',
17
+ header:
18
+ 'Which term is used to describe the act of asking what the usual salary is for the position you are applying for?',
19
+ explanation: 'Type your answer.'
20
+ },
21
+ klf: 'To negotiate your salary when being hired, you have to establish a benchmark beforehand. In other words, you should assess the salary to which you aspire by enquiring about the remuneration paid in the same industry, the same region and the same position.',
22
+ tips: 'According to Insee, Paris salaries are 20-25% higher compared with those of the provinces in 2015.',
23
+ universalRef: 'sli_VJYjJnJhg',
24
+ id: 'sli_VJYjJnJhg',
25
+ parentContentTitle: {
26
+ title: 'Developing the review app',
27
+ type: 'course'
28
+ }
29
+ };
30
+
31
+ export const freeTextUISlide: Partial<UISlide> = {
32
+ answerUI: {
33
+ help: 'Type your answer.',
34
+ model: {
35
+ type: 'freeText',
36
+ placeholder: 'Type here',
37
+ value: '',
38
+ onChange: noop
39
+ }
40
+ },
41
+ questionText:
42
+ 'Which term is used to describe the act of asking what the usual salary is for the position you are applying for?'
43
+ };
@@ -0,0 +1,111 @@
1
+ import noop from 'lodash/fp/noop';
2
+ import {SlideFromAPI, UISlide} from '../../../../types/common';
3
+
4
+ export const qcmDragSlide: SlideFromAPI = {
5
+ question: {
6
+ content: {
7
+ media: {
8
+ src: [],
9
+ posters: [],
10
+ subtitles: []
11
+ },
12
+ choices: [
13
+ {
14
+ media: {
15
+ src: [],
16
+ posters: [],
17
+ subtitles: []
18
+ },
19
+ items: [],
20
+ _id: '624f01970a234b0333bc7ce8',
21
+ label: 'La démoralisation',
22
+ value: 'sli_4yGBq-mCg.choice_4kRL5uQCg',
23
+ id: '624f01970a234b0333bc7ce8'
24
+ },
25
+ {
26
+ media: {
27
+ src: [],
28
+ posters: [],
29
+ subtitles: []
30
+ },
31
+ items: [],
32
+ _id: '624f01970a234b0333bc7ce9',
33
+ label: 'La stagnation',
34
+ value: 'sli_4yGBq-mCg.choice_E11v9OXAx',
35
+ id: '624f01970a234b0333bc7ce9'
36
+ },
37
+ {
38
+ media: {
39
+ src: [],
40
+ posters: [],
41
+ subtitles: []
42
+ },
43
+ items: [],
44
+ _id: '624f01970a234b0333bc7cea',
45
+ label: 'La frustration',
46
+ value: 'sli_4yGBq-mCg.choice_N1lP9dmRg',
47
+ id: '624f01970a234b0333bc7cea'
48
+ },
49
+ {
50
+ media: {
51
+ src: [],
52
+ posters: [],
53
+ subtitles: []
54
+ },
55
+ items: [],
56
+ _id: '624f01970a234b0333bc7ceb',
57
+ label: "L'implication",
58
+ value: 'sli_4yGBq-mCg.choice_Eybw5dQCx',
59
+ id: '624f01970a234b0333bc7ceb'
60
+ }
61
+ ]
62
+ },
63
+ type: 'qcmDrag',
64
+ header: "Remettez dans l'ordre les quatre étapes du burn out.",
65
+ explanation: 'Sélectionnez les réponses ci-dessous dans le bon ordre.'
66
+ },
67
+ klf: "Le burn out s'installe en quatre étapes : tout d'abord, l'implication (investissement émotionnel et/ou affectif, sacrifice de sa vie privée) ; en second, la stagnation (premières déceptions, signes de fatigue) ; ensuite, la frustration (efforts non reconnus) ; et enfin, la démoralisation (problèmes de concentration, sentiment d'inutilité, désespoir).",
68
+ tips: "Encadré par la loi, l'entretien professionnel a pour but d'aider le collaborateur à verbaliser ses difficultés et à construire son projet professionnel.",
69
+ universalRef: 'sli_4yGBq-mCg',
70
+ id: 'sli_4yGBq-mCg',
71
+ parentContentTitle: {
72
+ title: 'Using redux',
73
+ type: 'chapter'
74
+ }
75
+ };
76
+
77
+ export const qcmDragUISlide: Partial<UISlide> = {
78
+ questionText: "Remettez dans l'ordre les quatre étapes du burn out.",
79
+ answerUI: {
80
+ help: 'Sélectionnez les réponses ci-dessous dans le bon ordre.',
81
+ model: {
82
+ type: 'qcmDrag',
83
+ answers: [
84
+ {
85
+ title: 'La démoralisation',
86
+ selected: false,
87
+ order: -1,
88
+ onClick: noop
89
+ },
90
+ {
91
+ title: 'La stagnation',
92
+ selected: false,
93
+ order: -1,
94
+ onClick: noop
95
+ },
96
+ {
97
+ title: 'La frustration',
98
+ selected: false,
99
+ order: -1,
100
+ onClick: noop
101
+ },
102
+ {
103
+ title: "L'implication",
104
+ selected: false,
105
+ order: -1,
106
+ onClick: noop
107
+ }
108
+ ]
109
+ }
110
+ }
111
+ };