@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
@@ -1,3 +1,5 @@
1
+ import _toString from 'lodash/fp/toString';
2
+
1
3
  export const TOTAL_SLIDES_STACK = 5;
2
4
  export const HIGHEST_INDEX = TOTAL_SLIDES_STACK - 1;
3
5
 
@@ -11,4 +13,8 @@ export const VIEWS: {
11
13
  slides: 'slides'
12
14
  };
13
15
 
14
- export const slideNumbers: number[] = [0, 1, 2, 3, 4];
16
+ export const slideIndexes = ['0', '1', '2', '3', '4'] as const;
17
+
18
+ export type SlideIndexes = typeof slideIndexes[number];
19
+
20
+ export const indexToString = (index: number): SlideIndexes => _toString(index) as SlideIndexes;
@@ -1,7 +1,7 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {UISlide} from '../types/slides';
2
+ import {UISlide} from '../types/common';
3
3
 
4
- export const slide: UISlide = {
4
+ export const slide: Pick<UISlide, 'questionText' | 'answerUI'> = {
5
5
  questionText: 'QCM',
6
6
  answerUI: {
7
7
  help: '__help',
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-console */
2
- import {SlidesViewProps} from '../types/views/slides';
2
+ import {SlidesViewProps, CorrectionPopinProps} from '../views/slides';
3
3
 
4
- export const correctionPopinProps: SlidesViewProps['correctionPopinProps'] = {
4
+ export const correctionPopinProps: CorrectionPopinProps = {
5
5
  klf: {
6
6
  label: 'Key learning factor',
7
7
  tooltip: 'Some tooltip info.',
package/src/index.tsx CHANGED
@@ -1,121 +1,42 @@
1
1
  import React, {useEffect, useState} from 'react';
2
2
  import type {} from 'redux-thunk/extend-redux'; // https://github.com/reduxjs/redux-thunk/issues/333
3
3
  import {AnyAction, Store} from 'redux';
4
- import {connect, Provider} from 'react-redux';
4
+ import {useSelector, useDispatch, Provider} from 'react-redux';
5
5
  import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
6
6
  import {TemplateContext} from '@coorpacademy/components/es/template/app-review/template-context';
7
7
 
8
8
  import isEmpty from 'lodash/fp/isEmpty';
9
9
  import get from 'lodash/fp/get';
10
10
  import configureStore from './configure-store';
11
- import {congratsProps, correctionPopinProps} from './fixtures/temp-fixture';
12
11
 
13
12
  import type {AppOptions} from './types/common';
14
13
  import type {StoreState} from './reducers';
15
- import {SkillsProps} from './types/views/skills';
16
- import type {SlidesViewStaticProps} from './types/views/slides';
17
14
 
18
- import {Dispatchers} from './actions';
19
- import {updateSlidesOnNext, updateSlidesOnValidation, validateSlide} from './actions/data/slides';
20
- import {navigateTo, navigateBack, ViewPath} from './actions/ui/navigation';
15
+ import {navigateTo, ViewPath} from './actions/ui/navigation';
21
16
  import {storeToken} from './actions/data/token';
22
- import {updateFinishedSlides} from './actions/ui/finished-slides';
23
- import {updateReviewStatus} from './actions/ui/review-status';
24
- import {updateStepItemsOnValidation, updateStepItemsOnNext} from './actions/ui/step-items';
25
17
  import {fetchSkills} from './actions/api/fetch-skills';
26
18
  import {postProgression} from './actions/api/post-progression';
27
19
  import {VIEWS} from './common';
28
-
29
- type StaticProps = {
30
- viewName: 'skills' | 'onboarding' | 'slides' | 'loader';
31
- slides: SlidesViewStaticProps | null;
32
- skills: SkillsProps | null;
33
- };
34
-
35
- const mapDispatchToProps: Dispatchers = {
36
- navigateTo,
37
- navigateBack,
38
- validateSlide,
39
- updateSlidesOnValidation,
40
- updateSlidesOnNext,
41
- updateReviewStatus,
42
- updateStepItemsOnValidation,
43
- updateStepItemsOnNext,
44
- updateFinishedSlides
45
- };
46
-
47
- const getCurrentViewName = (storeState: StoreState): ViewPath =>
48
- storeState.ui.navigation[storeState.ui.navigation.length - 1];
49
-
50
- const mapStateToSkillsProps = (state: StoreState): SkillsProps | null => {
51
- if (!state.data.skills) {
52
- return null;
53
- }
54
-
55
- return {
56
- title: '@todo title',
57
- titleNoSkills: '@todo titleNoSkills',
58
- textNoSkills: '@todo textNoSkills',
59
- iconSkillAriaLabel: '@todo iconSkillAriaLabel',
60
- isLoading: false,
61
- isLoadingAriaLabel: '@todo loading',
62
- listSkills: state.data.skills.map(skill => ({
63
- 'aria-label': '',
64
- isCustom: skill.custom,
65
- skillTitle: skill.name,
66
- skillAriaLabel: '@todo skill aria label',
67
- buttonLabel: '@todo button',
68
- buttonAriaLabel: '@todo button aria label',
69
- reviseLabel: '@todo revise',
70
- reviseAriaLabel: '@todo revise aria label',
71
- // eslint-disable-next-line no-console
72
- onClick: () => console.log('@todo plug dispatcher select skill')
73
- }))
20
+ import {mapStateToSlidesProps} from './views/slides';
21
+ import {mapStateToSkillsProps} from './views/skills';
22
+
23
+ const ConnectedApp = (): JSX.Element => {
24
+ const dispatch = useDispatch();
25
+
26
+ const props = {
27
+ viewName: useSelector(
28
+ (state: StoreState) => state.ui.navigation[state.ui.navigation.length - 1]
29
+ ),
30
+ slides: useSelector((state: StoreState) => mapStateToSlidesProps(state, dispatch)),
31
+ skills: useSelector((state: StoreState) => mapStateToSkillsProps(state))
74
32
  };
75
- };
76
33
 
77
- const mapStateToSlidesProps = (state: StoreState): SlidesViewStaticProps | null => {
78
- if (!state.data.slides) {
79
- return null;
80
- }
81
-
82
- return {
83
- headerProps: {
84
- mode: '__revision_mode',
85
- skillName: '__agility',
86
- onQuitClick: (): void => {
87
- // eslint-disable-next-line no-console
88
- console.log('onQuitClick');
89
- },
90
- 'aria-label': 'aria-header-wrapper',
91
- closeButtonAriaLabel: 'aria-close-button'
92
- },
93
- slides: state.data.slides,
94
- validate: {
95
- label: '__validate'
96
- },
97
- finishedSlides: state.ui.finishedSlides,
98
- stepItems: state.ui.stepItems,
99
- reviewStatus: state.ui.reviewStatus,
100
- correctionPopinProps,
101
- congratsProps,
102
- progression: state.data.progression
103
- };
104
- };
105
-
106
- const mapStateToProps = (state: StoreState): StaticProps => {
107
- return {
108
- viewName: getCurrentViewName(state),
109
- slides: mapStateToSlidesProps(state),
110
- skills: mapStateToSkillsProps(state)
111
- };
34
+ return <AppReviewTemplate {...props} />;
112
35
  };
113
36
 
114
- const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
115
-
116
37
  const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
117
38
  const [store, setStore] = useState<Store<StoreState, AnyAction> | null>(null);
118
- const [isSlideFetched, setIsSlideFetched] = useState(false);
39
+ const [isProgressionCreated, setIsProgressionCreated] = useState(false);
119
40
 
120
41
  useEffect(() => {
121
42
  if (store) return;
@@ -125,14 +46,13 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
125
46
  }, [options, store]);
126
47
 
127
48
  useEffect(() => {
128
- if (!store || isSlideFetched) return;
49
+ if (!store || isProgressionCreated) return;
129
50
 
130
51
  return store.subscribe(() => {
131
- const isSlidePresent = !isEmpty(store.getState().data.slides[0].questionText);
132
- return isSlidePresent && setIsSlideFetched(isSlidePresent);
133
- }); // using the first slide questionText for now, should only check for a slide's presence
134
- // when the refactor is done (slides will be feed one by one on api's side)
135
- }, [isSlideFetched, options, store]);
52
+ const isProgressionPresent = !isEmpty(store.getState().data.progression);
53
+ return isProgressionPresent && setIsProgressionCreated(isProgressionPresent);
54
+ });
55
+ }, [isProgressionCreated, options, store]);
136
56
 
137
57
  useEffect(() => {
138
58
  const token = get('token', options);
@@ -146,8 +66,8 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
146
66
 
147
67
  const skillRef = get('skillRef', options);
148
68
 
149
- // ThunkAction is not assignable to parameter of type 'AnyAction'
150
- // ts problem describre here = https://github.com/reduxjs/redux-thunk/issues/333
69
+ /* ThunkAction is not assignable to parameter of type 'AnyAction'
70
+ ts problem is described here = https://github.com/reduxjs/redux-thunk/issues/333 */
151
71
  skillRef
152
72
  ? store.dispatch(postProgression(skillRef, token))
153
73
  : store.dispatch(fetchSkills(token));
@@ -158,18 +78,14 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
158
78
 
159
79
  const {skillRef} = options;
160
80
 
161
- if (skillRef && !isSlideFetched) {
81
+ if (skillRef && !isProgressionCreated) {
162
82
  store.dispatch(navigateTo('loader')); // use loader while posting progression
163
83
  return;
164
84
  }
165
85
 
166
- // TODO: when slides state is refactored (data + mapping),
167
- // use loader in case a skillRef is found && no slides from the API
168
- // are found
169
-
170
86
  const initialView: ViewPath = skillRef ? VIEWS.slides : VIEWS.skills;
171
87
  store.dispatch(navigateTo(initialView));
172
- }, [isSlideFetched, options, store]);
88
+ }, [isProgressionCreated, options, store]);
173
89
 
174
90
  if (!store) return null;
175
91
 
@@ -178,7 +94,7 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
178
94
  return (
179
95
  <Provider store={store}>
180
96
  <TemplateContext values={values}>
181
- <App />
97
+ <ConnectedApp />
182
98
  </TemplateContext>
183
99
  </Provider>
184
100
  );
@@ -7,7 +7,7 @@ import token, {TokenState} from './token';
7
7
 
8
8
  export type DataState = {
9
9
  isFetching?: boolean;
10
- progression?: ProgressionState;
10
+ progression: ProgressionState;
11
11
  skills: SkillsState;
12
12
  slides: SlidesState;
13
13
  token?: TokenState;
@@ -1,24 +1,8 @@
1
- import {getOr} from 'lodash/fp';
2
- import {ValidateSlide, VALIDATE_SLIDE} from '../../actions/data/slides';
1
+ import {ValidateSlide, VALIDATE_SLIDE} from '../../actions/ui/slides';
3
2
  import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../actions/api/post-progression';
3
+ import {ProgressionFromAPI} from '../../types/common';
4
4
 
5
- export type ProgressionState = {
6
- _id?: string;
7
- state: {
8
- isCorrect: boolean;
9
- nextContent: {
10
- ref: 'successExitNode' | string;
11
- type: 'success' | 'slide';
12
- };
13
- pendingSlides: string[];
14
- step: {
15
- current: number;
16
- };
17
- };
18
- // TO refactor: (slideNumber)
19
- // virtual field
20
- slideNumber?: number;
21
- } | null; // TODO: ça ressemble beaucoup à ProgressionFromAPI et ça devrait l'être
5
+ export type ProgressionState = ProgressionFromAPI | null;
22
6
 
23
7
  const reducer = (
24
8
  // eslint-disable-next-line default-param-last
@@ -27,25 +11,8 @@ const reducer = (
27
11
  ): ProgressionState => {
28
12
  switch (action.type) {
29
13
  case VALIDATE_SLIDE: {
30
- const previousSlideNumber: number = getOr(-1, 'slideNumber', state);
31
- // hard coded for now
32
- // TODO: fix on VALIDATE ticket
33
- return {
34
- _id: '1234',
35
- // virtual field
36
- slideNumber: previousSlideNumber + 1,
37
- state: {
38
- pendingSlides: [],
39
- step: {
40
- current: Number.NaN
41
- },
42
- isCorrect: true,
43
- nextContent: {
44
- ref: 'sli_V1gKpYYZ2',
45
- type: 'slide'
46
- }
47
- }
48
- };
14
+ // TODO: fix on VALIDATE ticket -> launch a POST PROGRESSION
15
+ return state;
49
16
  }
50
17
  case POST_PROGRESSION_SUCCESS: {
51
18
  const progression = action.payload;
@@ -56,6 +23,4 @@ const reducer = (
56
23
  }
57
24
  };
58
25
 
59
- // -----------------------------------------------------------------------------
60
-
61
26
  export default reducer;
@@ -1,140 +1,32 @@
1
- import map from 'lodash/fp/map';
1
+ import set from 'lodash/fp/set';
2
+ import {ValidateSlide} from '../../actions/ui/slides';
2
3
  import {
3
- OnNextPayload,
4
- SlidesAction,
5
- UPDATE_SLIDES_ON_NEXT,
6
- UPDATE_SLIDES_ON_VALIDATION,
7
- ValidationPayload
8
- } from '../../actions/data/slides';
9
- import {UISlide} from '../../types/slides';
10
- import {HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK} from '../../common';
11
- import {slide as qcmSlide} from '../../fixtures/qcm-slide';
12
- import {SLIDE_FETCH_SUCCESS} from '../../actions/api/fetch-slide';
13
- import {Slide} from '../../types/common';
4
+ ReceivedSlide,
5
+ FetchSlide,
6
+ SLIDE_FETCH_REQUEST,
7
+ SLIDE_FETCH_SUCCESS
8
+ } from '../../actions/api/fetch-slide';
9
+ import {SlideFromAPI} from '../../types/common';
14
10
 
15
- export type SlidesState = {
16
- slideNumbers: number[];
17
- [key: number]: Slide;
18
- };
19
-
20
- const getInitialState = (): SlidesState => {
21
- const state: SlidesState = {
22
- slideNumbers
23
- };
24
- // eslint-disable-next-line fp/no-loops
25
- for (let index = 0; index < TOTAL_SLIDES_STACK; index++) {
26
- state[index] = {hidden: false, position: index};
27
- }
28
- return state;
29
- };
30
-
31
- export const initialState: SlidesState = getInitialState();
32
-
33
- // -----------------------------------------------------------------------------
11
+ export type SlidesAction = FetchSlide | ReceivedSlide | ValidateSlide;
34
12
 
35
- const setFirstSlide = (state: SlidesState, slide: UISlide): SlidesState => {
36
- const _state: SlidesState = {
37
- slideNumbers
38
- };
39
- // eslint-disable-next-line lodash-fp/no-unused-result
40
- map(index => {
41
- const previousValue = state[index];
42
- // Only update the 1st one
43
- const content = index === 0 ? {...previousValue, ...slide} : {...previousValue};
44
- _state[index] = {...content};
45
- }, state.slideNumbers);
46
-
47
- return _state;
48
- };
49
-
50
- // ||-------> Handles the updates of a given slide on validation,
51
- // & then updates de remaining slides if this given change should impact their content
52
- const stateUpdateOnValidation = (state: SlidesState, payload: ValidationPayload): SlidesState => {
53
- const {slideNumber, newSlideContent, numberOfFinishedSlides, nextContent} = payload;
54
- const _state: SlidesState = {
55
- slideNumbers
56
- };
57
-
58
- // eslint-disable-next-line lodash-fp/no-unused-result
59
- map(index => {
60
- const previousValue = state[index];
61
- // the current slide
62
- if (index === slideNumber) {
63
- // only one slide remaining, presets the next value
64
- if (numberOfFinishedSlides === HIGHEST_INDEX) {
65
- _state[index] = {
66
- ...previousValue,
67
- nextContent,
68
- position: newSlideContent.position,
69
- isCorrect: newSlideContent.isCorrect
70
- };
71
- } else _state[slideNumber] = {...previousValue, ...newSlideContent};
72
- } else {
73
- // updates the rest of the slides here
74
- const {hidden, position} = previousValue;
75
- _state[index] = {...nextContent, endReview: newSlideContent.endReview, hidden, position};
76
- }
77
- }, state.slideNumbers);
78
-
79
- return _state;
80
- };
81
-
82
- // ||-------> Handles the updates of a given slide on correction popin's next click,
83
- // & then updates de remaining slides (updates position to trigger animations)
84
- const stateUpdateOnNext = (state: SlidesState, payload: OnNextPayload): SlidesState => {
85
- const {slideNumber, newSlideContent, numberOfFinishedSlides} = payload;
86
- const _state: SlidesState = {
87
- slideNumbers
88
- };
89
-
90
- // eslint-disable-next-line lodash-fp/no-unused-result
91
- map(index => {
92
- const previousValue = state[index];
93
- // the current slide
94
- if (index === slideNumber) {
95
- // when there is only one slide remaining, updates the slide value
96
- if (numberOfFinishedSlides === HIGHEST_INDEX && previousValue.nextContent) {
97
- _state[index] = {...previousValue.nextContent, position: previousValue.position};
98
- } else _state[slideNumber] = newSlideContent;
99
- } else {
100
- // updates the rest of the slides here
101
- const {hidden, position, answerUI, questionText} = previousValue;
102
- _state[index] = {
103
- hidden,
104
- position: position - 1, // position shift
105
- answerUI,
106
- questionText,
107
- endReview: newSlideContent.endReview
108
- };
109
- }
110
- }, state.slideNumbers);
111
-
112
- return _state;
113
- };
114
-
115
- // -----------------------------------------------------------------------------
13
+ export type SlidesState = Record<string, SlideFromAPI>;
14
+ export const initialState: SlidesState = {};
116
15
 
117
16
  // eslint-disable-next-line default-param-last
118
17
  const reducer = (state: SlidesState = initialState, action: SlidesAction): SlidesState => {
119
18
  switch (action.type) {
120
- case SLIDE_FETCH_SUCCESS: {
121
- // TODO: An intermediate slide transform is needed here (or in fetchSlide)
122
- // const apiSlide = action.payload;
123
- // apiSlide adapt to uiSlide
124
- const uiSlide = qcmSlide;
125
- return setFirstSlide(state, uiSlide);
126
- }
127
- case UPDATE_SLIDES_ON_VALIDATION: {
128
- return stateUpdateOnValidation(state, action.payload);
19
+ case SLIDE_FETCH_REQUEST: {
20
+ const {meta} = action;
21
+ return set(meta.slideRef, null, state);
129
22
  }
130
- case UPDATE_SLIDES_ON_NEXT: {
131
- return stateUpdateOnNext(state, action.payload);
23
+ case SLIDE_FETCH_SUCCESS: {
24
+ const slide = action.payload;
25
+ return set(slide.id, slide, state);
132
26
  }
133
27
  default:
134
28
  return state;
135
29
  }
136
30
  };
137
31
 
138
- // -----------------------------------------------------------------------------
139
-
140
32
  export default reducer;
@@ -0,0 +1,42 @@
1
+ import test from 'ava';
2
+ import reducer from '../progression';
3
+ import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../../actions/api/post-progression';
4
+ import {ProgressionFromAPI} from '../../../types/common';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as ReceiveProgression);
8
+ t.is(state, null);
9
+ });
10
+
11
+ test('should set the value of POST_PROGRESSION_SUCCESS action', t => {
12
+ const progression: ProgressionFromAPI = {
13
+ _id: '62b1d1087aa12f00253f40ee',
14
+ content: {
15
+ ref: '_skill-ref',
16
+ type: 'skill'
17
+ },
18
+ engine: {
19
+ ref: 'review'
20
+ },
21
+ state: {
22
+ allAnswers: [],
23
+ isCorrect: true,
24
+ nextContent: {
25
+ ref: 'sli_N1XACJobn',
26
+ type: 'slide'
27
+ },
28
+ pendingSlides: [],
29
+ slides: [],
30
+ step: {
31
+ current: 1
32
+ },
33
+ stars: 0
34
+ }
35
+ };
36
+
37
+ const state = reducer(null, {
38
+ type: POST_PROGRESSION_SUCCESS,
39
+ payload: progression
40
+ });
41
+ t.deepEqual(state, progression);
42
+ });
@@ -0,0 +1,14 @@
1
+ import test from 'ava';
2
+ import reducer from '../skills';
3
+ import {ReceivedSkills, SKILLS_FETCH_SUCCESS} from '../../../actions/api/fetch-skills';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as ReceivedSkills);
7
+ t.deepEqual(state, []);
8
+ });
9
+
10
+ test('should set the value of SKILLS_FETCH_SUCCESS action', t => {
11
+ const skills = [{skillRef: 'skill', name: 'skill name', slidesToReview: 5, custom: false}];
12
+ const state = reducer([], {type: SKILLS_FETCH_SUCCESS, payload: skills});
13
+ t.deepEqual(state, skills);
14
+ });
@@ -0,0 +1,26 @@
1
+ import test from 'ava';
2
+ import reducer, {type SlidesAction} from '../slides';
3
+ import {SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS} from '../../../actions/api/fetch-slide';
4
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as SlidesAction);
8
+ t.deepEqual(state, {});
9
+ });
10
+
11
+ test('should set the value of SLIDE_FETCH_REQUEST action', t => {
12
+ const state = reducer({}, {type: SLIDE_FETCH_REQUEST, meta: {slideRef: 'slideRef'}});
13
+ t.deepEqual(state, {
14
+ slideRef: null
15
+ });
16
+ });
17
+
18
+ test('should set the value of SLIDE_FETCH_SUCCESS action', t => {
19
+ const state = reducer(
20
+ {},
21
+ {type: SLIDE_FETCH_SUCCESS, payload: freeTextSlide, meta: {slideRef: 'sli_VJYjJnJhg'}}
22
+ );
23
+ t.deepEqual(state, {
24
+ sli_VJYjJnJhg: freeTextSlide
25
+ });
26
+ });
@@ -0,0 +1,13 @@
1
+ import test from 'ava';
2
+ import reducer from '../token';
3
+ import {StoreToken, STORE_TOKEN} from '../../../actions/data/token';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as StoreToken);
7
+ t.is(state, null);
8
+ });
9
+
10
+ test('should set the value of STORE_TOKEN action', t => {
11
+ const state = reducer(null, {type: STORE_TOKEN, payload: 'token'});
12
+ t.is(state, 'token');
13
+ });
@@ -0,0 +1,19 @@
1
+ import {EditBasicAction, EDIT_BASIC} from '../../actions/ui/answers';
2
+
3
+ export type AnswerState = string[];
4
+
5
+ const reducer = (
6
+ // eslint-disable-next-line default-param-last
7
+ state: AnswerState = [],
8
+ action: EditBasicAction
9
+ ): AnswerState => {
10
+ switch (action.type) {
11
+ case EDIT_BASIC: {
12
+ return action.payload;
13
+ }
14
+ default:
15
+ return state;
16
+ }
17
+ };
18
+
19
+ export default reducer;
@@ -0,0 +1,19 @@
1
+ import {SET_CURRENT_SLIDE, UISlidesAction} from '../../actions/ui/slides';
2
+
3
+ export type CurrentSlideRefState = string;
4
+
5
+ const reducer = (
6
+ // eslint-disable-next-line default-param-last
7
+ state: CurrentSlideRefState = '',
8
+ action: UISlidesAction
9
+ ): CurrentSlideRefState => {
10
+ switch (action.type) {
11
+ case SET_CURRENT_SLIDE: {
12
+ return action.payload.id;
13
+ }
14
+ default:
15
+ return state;
16
+ }
17
+ };
18
+
19
+ export default reducer;
@@ -1,20 +1,17 @@
1
1
  import {combineReducers} from 'redux';
2
2
 
3
- import finishedSlides, {FinishedSlidesState} from './finished-slides';
3
+ import currentSlideRef, {CurrentSlideRefState} from './current-slide-ref';
4
4
  import navigation, {NavigationState} from './navigation';
5
- import reviewStatus, {ReviewStatusState} from './review-status';
6
- import stepItems, {StepItemsState} from './step-items';
5
+ import answers, {AnswerState} from './answers';
7
6
 
8
7
  export type UIState = {
8
+ currentSlideRef: CurrentSlideRefState;
9
9
  navigation: NavigationState;
10
- stepItems: StepItemsState;
11
- finishedSlides: FinishedSlidesState;
12
- reviewStatus: ReviewStatusState;
10
+ answers: AnswerState;
13
11
  };
14
12
 
15
13
  export default combineReducers({
16
- finishedSlides,
14
+ currentSlideRef,
17
15
  navigation,
18
- reviewStatus,
19
- stepItems
16
+ answers
20
17
  });
@@ -0,0 +1,13 @@
1
+ import test from 'ava';
2
+ import reducer from '../answers';
3
+ import {EditBasicAction, EDIT_BASIC} from '../../../actions/ui/answers';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as EditBasicAction);
7
+ t.deepEqual(state, []);
8
+ });
9
+
10
+ test('should set the value of EDIT_BASIC action', t => {
11
+ const state = reducer([], {type: EDIT_BASIC, payload: ['value']});
12
+ t.deepEqual(state, ['value']);
13
+ });
@@ -0,0 +1,14 @@
1
+ import test from 'ava';
2
+ import reducer from '../current-slide-ref';
3
+ import {SetCurrentSlide, SET_CURRENT_SLIDE} from '../../../actions/ui/slides';
4
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as SetCurrentSlide);
8
+ t.is(state, '');
9
+ });
10
+
11
+ test('should set the value of SET_CURRENT_SLIDE action', t => {
12
+ const state = reducer('', {type: SET_CURRENT_SLIDE, payload: freeTextSlide});
13
+ t.is(state, 'sli_VJYjJnJhg');
14
+ });