@coorpacademy/app-review 0.1.13 → 0.1.15

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 (174) hide show
  1. package/es/actions/api/fetch-slide.d.ts +3 -3
  2. package/es/actions/api/fetch-slide.js +22 -2
  3. package/es/actions/api/post-progression.js +1 -2
  4. package/es/actions/index.d.ts +1 -10
  5. package/es/actions/ui/is-fetching.js +0 -2
  6. package/es/actions/ui/slides.d.ts +26 -0
  7. package/es/actions/ui/slides.js +9 -0
  8. package/es/common/index.d.ts +3 -1
  9. package/es/common/index.js +3 -1
  10. package/es/fixtures/qcm-slide.d.ts +2 -2
  11. package/es/fixtures/temp-fixture.d.ts +2 -2
  12. package/es/helpers/map-api-slide-to-ui.d.ts +4 -1
  13. package/es/helpers/map-api-slide-to-ui.js +33 -15
  14. package/es/helpers/test/fixtures/free-text.d.ts +2 -3
  15. package/es/helpers/test/fixtures/free-text.js +10 -4
  16. package/es/helpers/test/fixtures/qcm-drag.d.ts +2 -3
  17. package/es/helpers/test/fixtures/qcm-drag.js +38 -32
  18. package/es/helpers/test/fixtures/qcm-graphic.d.ts +2 -3
  19. package/es/helpers/test/fixtures/qcm-graphic.js +20 -14
  20. package/es/helpers/test/fixtures/qcm.d.ts +2 -3
  21. package/es/helpers/test/fixtures/qcm.js +32 -26
  22. package/es/helpers/test/fixtures/select-template.d.ts +2 -3
  23. package/es/helpers/test/fixtures/select-template.js +38 -32
  24. package/es/helpers/test/fixtures/slider.d.ts +2 -3
  25. package/es/helpers/test/fixtures/slider.js +13 -7
  26. package/es/helpers/test/fixtures/text-template.d.ts +2 -3
  27. package/es/helpers/test/fixtures/text-template.js +16 -10
  28. package/es/index.js +14 -78
  29. package/es/reducers/data/index.d.ts +1 -1
  30. package/es/reducers/data/progression.d.ts +3 -16
  31. package/es/reducers/data/progression.js +3 -22
  32. package/es/reducers/data/slides.d.ts +5 -6
  33. package/es/reducers/data/slides.js +4 -107
  34. package/es/reducers/index.d.ts +3 -4
  35. package/es/reducers/ui/current-slide-ref.d.ts +4 -0
  36. package/es/reducers/ui/{review-status.js → current-slide-ref.js} +4 -4
  37. package/es/reducers/ui/index.d.ts +7 -10
  38. package/es/reducers/ui/index.js +4 -6
  39. package/es/reducers/ui/slides.d.ts +9 -0
  40. package/es/reducers/ui/slides.js +42 -0
  41. package/es/services/test/post-progression.test.js +6 -4
  42. package/es/test/util/services.mock.js +17 -5
  43. package/es/types/common.d.ts +40 -23
  44. package/es/types/common.js +0 -5
  45. package/es/types/slides.d.ts +0 -4
  46. package/es/types/views/slides.d.ts +41 -27
  47. package/es/types/views/slides.js +5 -0
  48. package/{lib/types/views/skills.d.ts → es/views/skills/index.d.ts} +2 -0
  49. package/es/views/skills/index.js +25 -0
  50. package/es/views/slides/index.d.ts +3 -0
  51. package/es/views/slides/index.js +85 -0
  52. package/lib/actions/api/fetch-slide.d.ts +3 -3
  53. package/lib/actions/api/fetch-slide.js +20 -2
  54. package/lib/actions/api/post-progression.js +1 -2
  55. package/lib/actions/index.d.ts +1 -10
  56. package/lib/actions/ui/is-fetching.js +0 -2
  57. package/lib/actions/ui/slides.d.ts +26 -0
  58. package/lib/actions/ui/slides.js +9 -0
  59. package/lib/common/index.d.ts +3 -1
  60. package/lib/common/index.js +3 -1
  61. package/lib/fixtures/qcm-slide.d.ts +2 -2
  62. package/lib/fixtures/temp-fixture.d.ts +2 -2
  63. package/lib/helpers/map-api-slide-to-ui.d.ts +4 -1
  64. package/lib/helpers/map-api-slide-to-ui.js +34 -14
  65. package/lib/helpers/test/fixtures/free-text.d.ts +2 -3
  66. package/lib/helpers/test/fixtures/free-text.js +10 -4
  67. package/lib/helpers/test/fixtures/qcm-drag.d.ts +2 -3
  68. package/lib/helpers/test/fixtures/qcm-drag.js +38 -32
  69. package/lib/helpers/test/fixtures/qcm-graphic.d.ts +2 -3
  70. package/lib/helpers/test/fixtures/qcm-graphic.js +20 -14
  71. package/lib/helpers/test/fixtures/qcm.d.ts +2 -3
  72. package/lib/helpers/test/fixtures/qcm.js +32 -26
  73. package/lib/helpers/test/fixtures/select-template.d.ts +2 -3
  74. package/lib/helpers/test/fixtures/select-template.js +38 -32
  75. package/lib/helpers/test/fixtures/slider.d.ts +2 -3
  76. package/lib/helpers/test/fixtures/slider.js +13 -7
  77. package/lib/helpers/test/fixtures/text-template.d.ts +2 -3
  78. package/lib/helpers/test/fixtures/text-template.js +16 -10
  79. package/lib/index.js +14 -78
  80. package/lib/reducers/data/index.d.ts +1 -1
  81. package/lib/reducers/data/progression.d.ts +3 -16
  82. package/lib/reducers/data/progression.js +3 -22
  83. package/lib/reducers/data/slides.d.ts +5 -6
  84. package/lib/reducers/data/slides.js +4 -113
  85. package/lib/reducers/index.d.ts +3 -4
  86. package/lib/reducers/ui/current-slide-ref.d.ts +4 -0
  87. package/lib/reducers/ui/{review-status.js → current-slide-ref.js} +4 -4
  88. package/lib/reducers/ui/index.d.ts +7 -10
  89. package/lib/reducers/ui/index.js +4 -6
  90. package/lib/reducers/ui/slides.d.ts +9 -0
  91. package/lib/reducers/ui/slides.js +43 -0
  92. package/lib/services/test/post-progression.test.js +6 -4
  93. package/lib/test/util/services.mock.js +17 -5
  94. package/lib/types/common.d.ts +40 -23
  95. package/lib/types/common.js +0 -5
  96. package/lib/types/slides.d.ts +0 -4
  97. package/lib/types/views/slides.d.ts +41 -27
  98. package/lib/types/views/slides.js +5 -0
  99. package/{es/types/views/skills.d.ts → lib/views/skills/index.d.ts} +2 -0
  100. package/lib/views/skills/index.js +25 -0
  101. package/lib/views/slides/index.d.ts +3 -0
  102. package/lib/views/slides/index.js +89 -0
  103. package/package.json +3 -3
  104. package/src/actions/api/fetch-slide.ts +26 -5
  105. package/src/actions/api/post-progression.ts +1 -2
  106. package/src/actions/index.ts +1 -10
  107. package/src/actions/ui/is-fetching.ts +0 -6
  108. package/src/actions/ui/slides.ts +35 -0
  109. package/src/common/index.ts +7 -1
  110. package/src/fixtures/qcm-slide.ts +2 -2
  111. package/src/fixtures/temp-fixture.ts +2 -2
  112. package/src/helpers/map-api-slide-to-ui.ts +43 -17
  113. package/src/helpers/test/fixtures/free-text.ts +12 -7
  114. package/src/helpers/test/fixtures/qcm-drag.ts +40 -35
  115. package/src/helpers/test/fixtures/qcm-graphic.ts +22 -17
  116. package/src/helpers/test/fixtures/qcm.ts +38 -32
  117. package/src/helpers/test/fixtures/select-template.ts +40 -35
  118. package/src/helpers/test/fixtures/slider.ts +15 -10
  119. package/src/helpers/test/fixtures/text-template.ts +18 -13
  120. package/src/helpers/test/map-api-slide-to-ui.test.ts +2 -11
  121. package/src/index.tsx +15 -84
  122. package/src/reducers/data/progression.ts +5 -40
  123. package/src/reducers/data/slides.ts +9 -126
  124. package/src/reducers/ui/current-slide-ref.ts +19 -0
  125. package/src/reducers/ui/index.ts +6 -9
  126. package/src/reducers/ui/slides.ts +58 -0
  127. package/src/services/test/post-progression.test.ts +6 -4
  128. package/src/test/util/services.mock.ts +17 -5
  129. package/src/types/common.ts +44 -27
  130. package/src/types/slides.ts +0 -5
  131. package/src/types/views/slides.ts +52 -27
  132. package/src/views/skills/index.ts +56 -0
  133. package/src/views/slides/index.ts +92 -0
  134. package/es/actions/data/slides.d.ts +0 -37
  135. package/es/actions/data/slides.js +0 -16
  136. package/es/actions/ui/finished-slides.d.ts +0 -10
  137. package/es/actions/ui/finished-slides.js +0 -8
  138. package/es/actions/ui/review-status.d.ts +0 -7
  139. package/es/actions/ui/review-status.js +0 -7
  140. package/es/actions/ui/step-items.d.ts +0 -24
  141. package/es/actions/ui/step-items.js +0 -11
  142. package/es/reducers/ui/finished-slides.d.ts +0 -7
  143. package/es/reducers/ui/finished-slides.js +0 -33
  144. package/es/reducers/ui/review-status.d.ts +0 -4
  145. package/es/reducers/ui/step-items.d.ts +0 -14
  146. package/es/reducers/ui/step-items.js +0 -74
  147. package/es/types/ui-progression.d.ts +0 -10
  148. package/es/types/ui-progression.js +0 -1
  149. package/es/types/views/skills.js +0 -1
  150. package/lib/actions/data/slides.d.ts +0 -37
  151. package/lib/actions/data/slides.js +0 -16
  152. package/lib/actions/ui/finished-slides.d.ts +0 -10
  153. package/lib/actions/ui/finished-slides.js +0 -8
  154. package/lib/actions/ui/review-status.d.ts +0 -7
  155. package/lib/actions/ui/review-status.js +0 -7
  156. package/lib/actions/ui/step-items.d.ts +0 -24
  157. package/lib/actions/ui/step-items.js +0 -11
  158. package/lib/reducers/ui/finished-slides.d.ts +0 -7
  159. package/lib/reducers/ui/finished-slides.js +0 -45
  160. package/lib/reducers/ui/review-status.d.ts +0 -4
  161. package/lib/reducers/ui/step-items.d.ts +0 -14
  162. package/lib/reducers/ui/step-items.js +0 -86
  163. package/lib/types/ui-progression.d.ts +0 -10
  164. package/lib/types/ui-progression.js +0 -1
  165. package/lib/types/views/skills.js +0 -1
  166. package/src/actions/data/slides.ts +0 -65
  167. package/src/actions/ui/finished-slides.ts +0 -21
  168. package/src/actions/ui/review-status.ts +0 -19
  169. package/src/actions/ui/step-items.ts +0 -45
  170. package/src/reducers/ui/finished-slides.ts +0 -52
  171. package/src/reducers/ui/review-status.ts +0 -19
  172. package/src/reducers/ui/step-items.ts +0 -116
  173. package/src/types/ui-progression.ts +0 -25
  174. package/src/types/views/skills.ts +0 -27
@@ -1,6 +1,5 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {Template} from '../../../types/slides';
3
- import {SlideFromAPI} from '../../../types/common';
2
+ import {SlideFromAPI, UISlide} from '../../../types/common';
4
3
 
5
4
  export const selectTemplateSlide: SlideFromAPI = {
6
5
  id: 'sli_410xZQxrZ',
@@ -52,41 +51,47 @@ export const selectTemplateSlide: SlideFromAPI = {
52
51
  tips: 'sli_410xZQxrZ.tips'
53
52
  };
54
53
 
55
- export const selectTemplateUISlide: Template = {
56
- type: 'template',
57
- template: 'sli_410xZQxrZ.template',
58
- answers: [
59
- {
60
- type: 'select',
61
- name: 'sel36665',
62
- onChange: noop,
63
- options: [
64
- {name: 'Select an answer', value: '', validOption: false, selected: true},
65
- {
66
- name: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
67
- value: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
68
- validOption: true,
69
- selected: false
70
- },
71
- {
72
- name: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
73
- value: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
74
- validOption: true,
75
- selected: false
76
- },
77
- {
78
- name: 'sli_410xZQxrZ.choice_VkaH~XgBb',
79
- value: 'sli_410xZQxrZ.choice_VkaH~XgBb',
80
- validOption: true,
81
- selected: false
82
- },
54
+ export const selectTemplateUISlide: Partial<UISlide> = {
55
+ questionText: 'sli_410xZQxrZ.header',
56
+ answerUI: {
57
+ help: 'sli_410xZQxrZ.explanation',
58
+ model: {
59
+ type: 'template',
60
+ template: 'sli_410xZQxrZ.template',
61
+ answers: [
83
62
  {
84
- name: 'sli_410xZQxrZ.choice_E1uUWXeBb',
85
- value: 'sli_410xZQxrZ.choice_E1uUWXeBb',
86
- validOption: true,
87
- selected: false
63
+ type: 'select',
64
+ name: 'sel36665',
65
+ onChange: noop,
66
+ options: [
67
+ {name: 'Select an answer', value: '', validOption: false, selected: true},
68
+ {
69
+ name: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
70
+ value: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
71
+ validOption: true,
72
+ selected: false
73
+ },
74
+ {
75
+ name: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
76
+ value: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
77
+ validOption: true,
78
+ selected: false
79
+ },
80
+ {
81
+ name: 'sli_410xZQxrZ.choice_VkaH~XgBb',
82
+ value: 'sli_410xZQxrZ.choice_VkaH~XgBb',
83
+ validOption: true,
84
+ selected: false
85
+ },
86
+ {
87
+ name: 'sli_410xZQxrZ.choice_E1uUWXeBb',
88
+ value: 'sli_410xZQxrZ.choice_E1uUWXeBb',
89
+ validOption: true,
90
+ selected: false
91
+ }
92
+ ]
88
93
  }
89
94
  ]
90
95
  }
91
- ]
96
+ }
92
97
  };
@@ -1,6 +1,5 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {QuestionRange} from '../../../types/slides';
3
- import {SlideFromAPI} from '../../../types/common';
2
+ import {SlideFromAPI, UISlide} from '../../../types/common';
4
3
 
5
4
  export const sliderSlide: SlideFromAPI = {
6
5
  id: 'sli_41D5AovN~',
@@ -20,12 +19,18 @@ export const sliderSlide: SlideFromAPI = {
20
19
  tips: 'sli_41D5AovN~.tips'
21
20
  };
22
21
 
23
- export const sliderUISlide: QuestionRange = {
24
- type: 'slider',
25
- placeholder: 'sli_41D5AovN~.explanation',
26
- minLabel: '1 undefined',
27
- maxLabel: '10 undefined',
28
- title: '0 sli_41D5AovN~.unitLabel',
29
- value: -0.1111111111111111,
30
- onChange: noop
22
+ export const sliderUISlide: Partial<UISlide> = {
23
+ questionText: 'sli_41D5AovN~.header',
24
+ answerUI: {
25
+ help: 'sli_41D5AovN~.explanation',
26
+ model: {
27
+ type: 'slider',
28
+ placeholder: 'sli_41D5AovN~.explanation',
29
+ minLabel: '1 undefined',
30
+ maxLabel: '10 undefined',
31
+ title: '0 sli_41D5AovN~.unitLabel',
32
+ value: -0.1111111111111111,
33
+ onChange: noop
34
+ }
35
+ }
31
36
  };
@@ -1,6 +1,5 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {Template} from '../../../types/slides';
3
- import {SlideFromAPI} from '../../../types/common';
2
+ import {SlideFromAPI, UISlide} from '../../../types/common';
4
3
 
5
4
  export const textTemplateSlide: SlideFromAPI = {
6
5
  question: {
@@ -37,16 +36,22 @@ export const textTemplateSlide: SlideFromAPI = {
37
36
  id: 'sli_VJKQonm2g'
38
37
  };
39
38
 
40
- export const textTemplateUISlide: Template = {
41
- type: 'template',
42
- template: 'Un {{inp58402}} model.',
43
- answers: [
44
- {
45
- type: 'text',
46
- name: 'inp58402',
47
- placeholder: 'Type here',
48
- value: undefined,
49
- onChange: noop
39
+ export const textTemplateUISlide: Partial<UISlide> = {
40
+ questionText: 'Comment le protégé doit-il percevoir son mentor ?',
41
+ answerUI: {
42
+ help: 'Saisissez votre réponse (en anglais).',
43
+ model: {
44
+ type: 'template',
45
+ template: 'Un {{inp58402}} model.',
46
+ answers: [
47
+ {
48
+ type: 'text',
49
+ name: 'inp58402',
50
+ placeholder: 'Type here',
51
+ value: undefined,
52
+ onChange: noop
53
+ }
54
+ ]
50
55
  }
51
- ]
56
+ }
52
57
  };
@@ -1,15 +1,6 @@
1
1
  import test from 'ava';
2
- import {SlideFromAPI} from '../../types/common';
2
+ import {SlideFromAPI, UISlide} from '../../types/common';
3
3
  import {mapApiSlideToUi} from '../map-api-slide-to-ui';
4
- import {
5
- QcmDrag,
6
- Qcm,
7
- QcmGraphic,
8
- FreeText,
9
- DropDown,
10
- QuestionRange,
11
- Template
12
- } from '../../types/slides';
13
4
  import {qcmUISlide, qcmSlide} from './fixtures/qcm';
14
5
  import {qcmDragUISlide, qcmDragSlide} from './fixtures/qcm-drag';
15
6
  import {freeTextSlide, freeTextUISlide} from './fixtures/free-text';
@@ -28,7 +19,7 @@ const macro = test.macro({
28
19
  t,
29
20
  arg: {
30
21
  slide: SlideFromAPI;
31
- expectedUiSlide: QcmDrag | Qcm | QcmGraphic | FreeText | DropDown | QuestionRange | Template;
22
+ expectedUiSlide: Partial<UISlide>;
32
23
  }
33
24
  ) {
34
25
  t.deepEqual(
package/src/index.tsx CHANGED
@@ -8,23 +8,21 @@ import {TemplateContext} from '@coorpacademy/components/es/template/app-review/t
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
14
  import type {SlidesViewStaticProps} from './types/views/slides';
17
15
 
18
16
  import {Dispatchers} from './actions';
19
- import {updateSlidesOnNext, updateSlidesOnValidation, validateSlide} from './actions/data/slides';
17
+ import {validateSlide} from './actions/ui/slides';
18
+
20
19
  import {navigateTo, navigateBack, ViewPath} from './actions/ui/navigation';
21
20
  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
21
  import {fetchSkills} from './actions/api/fetch-skills';
26
22
  import {postProgression} from './actions/api/post-progression';
27
23
  import {VIEWS} from './common';
24
+ import {mapStateToSlidesProps} from './views/slides';
25
+ import {mapStateToSkillsProps, SkillsProps} from './views/skills';
28
26
 
29
27
  type StaticProps = {
30
28
  viewName: 'skills' | 'onboarding' | 'slides' | 'loader';
@@ -35,74 +33,12 @@ type StaticProps = {
35
33
  const mapDispatchToProps: Dispatchers = {
36
34
  navigateTo,
37
35
  navigateBack,
38
- validateSlide,
39
- updateSlidesOnValidation,
40
- updateSlidesOnNext,
41
- updateReviewStatus,
42
- updateStepItemsOnValidation,
43
- updateStepItemsOnNext,
44
- updateFinishedSlides
36
+ validateSlide
45
37
  };
46
38
 
47
39
  const getCurrentViewName = (storeState: StoreState): ViewPath =>
48
40
  storeState.ui.navigation[storeState.ui.navigation.length - 1];
49
41
 
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
- }))
74
- };
75
- };
76
-
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
42
  const mapStateToProps = (state: StoreState): StaticProps => {
107
43
  return {
108
44
  viewName: getCurrentViewName(state),
@@ -115,7 +51,7 @@ const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
115
51
 
116
52
  const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
117
53
  const [store, setStore] = useState<Store<StoreState, AnyAction> | null>(null);
118
- const [isSlideFetched, setIsSlideFetched] = useState(false);
54
+ const [isProgressionCreated, setIsProgressionCreated] = useState(false);
119
55
 
120
56
  useEffect(() => {
121
57
  if (store) return;
@@ -125,14 +61,13 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
125
61
  }, [options, store]);
126
62
 
127
63
  useEffect(() => {
128
- if (!store || isSlideFetched) return;
64
+ if (!store || isProgressionCreated) return;
129
65
 
130
66
  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]);
67
+ const isProgressionPresent = !isEmpty(store.getState().data.progression);
68
+ return isProgressionPresent && setIsProgressionCreated(isProgressionPresent);
69
+ });
70
+ }, [isProgressionCreated, options, store]);
136
71
 
137
72
  useEffect(() => {
138
73
  const token = get('token', options);
@@ -146,8 +81,8 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
146
81
 
147
82
  const skillRef = get('skillRef', options);
148
83
 
149
- // ThunkAction is not assignable to parameter of type 'AnyAction'
150
- // ts problem describre here = https://github.com/reduxjs/redux-thunk/issues/333
84
+ /* ThunkAction is not assignable to parameter of type 'AnyAction'
85
+ ts problem is described here = https://github.com/reduxjs/redux-thunk/issues/333 */
151
86
  skillRef
152
87
  ? store.dispatch(postProgression(skillRef, token))
153
88
  : store.dispatch(fetchSkills(token));
@@ -158,18 +93,14 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
158
93
 
159
94
  const {skillRef} = options;
160
95
 
161
- if (skillRef && !isSlideFetched) {
96
+ if (skillRef && !isProgressionCreated) {
162
97
  store.dispatch(navigateTo('loader')); // use loader while posting progression
163
98
  return;
164
99
  }
165
100
 
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
101
  const initialView: ViewPath = skillRef ? VIEWS.slides : VIEWS.skills;
171
102
  store.dispatch(navigateTo(initialView));
172
- }, [isSlideFetched, options, store]);
103
+ }, [isProgressionCreated, options, store]);
173
104
 
174
105
  if (!store) return null;
175
106
 
@@ -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,23 @@
1
- import map from 'lodash/fp/map';
2
- 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';
1
+ import set from 'lodash/fp/set';
2
+ import {ValidateSlide} from '../../actions/ui/slides';
3
+ import {ReceivedSlide, SLIDE_FETCH_SUCCESS} from '../../actions/api/fetch-slide';
4
+ import {SlideFromAPI} from '../../types/common';
14
5
 
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
- // -----------------------------------------------------------------------------
34
-
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
- };
6
+ export type SlidesAction = ReceivedSlide | ValidateSlide;
81
7
 
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
- // -----------------------------------------------------------------------------
8
+ export type SlidesState = Record<string, SlideFromAPI>;
9
+ export const initialState: SlidesState = {};
116
10
 
117
11
  // eslint-disable-next-line default-param-last
118
12
  const reducer = (state: SlidesState = initialState, action: SlidesAction): SlidesState => {
119
13
  switch (action.type) {
120
14
  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);
129
- }
130
- case UPDATE_SLIDES_ON_NEXT: {
131
- return stateUpdateOnNext(state, action.payload);
15
+ const slide = action.payload;
16
+ return set(slide.id, slide, state);
132
17
  }
133
18
  default:
134
19
  return state;
135
20
  }
136
21
  };
137
22
 
138
- // -----------------------------------------------------------------------------
139
-
140
23
  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 slides, {UISlidesState} from './slides';
7
6
 
8
7
  export type UIState = {
8
+ currentSlideRef: CurrentSlideRefState;
9
9
  navigation: NavigationState;
10
- stepItems: StepItemsState;
11
- finishedSlides: FinishedSlidesState;
12
- reviewStatus: ReviewStatusState;
10
+ slides: UISlidesState;
13
11
  };
14
12
 
15
13
  export default combineReducers({
16
- finishedSlides,
14
+ currentSlideRef,
17
15
  navigation,
18
- reviewStatus,
19
- stepItems
16
+ slides
20
17
  });
@@ -0,0 +1,58 @@
1
+ import pipe from 'lodash/fp/pipe';
2
+ import set from 'lodash/fp/set';
3
+ import type {SlideFromAPI, UISlide} from '../../types/common';
4
+ import {SlideIndexes} from '../../common';
5
+ import {mapApiSlideToUi} from '../../helpers/map-api-slide-to-ui';
6
+ import {SET_CURRENT_SLIDE, UISlidesAction} from '../../actions/ui/slides';
7
+
8
+ export type UISlidesState = {
9
+ [key in SlideIndexes]: UISlide;
10
+ };
11
+
12
+ export const initialState: UISlidesState = {
13
+ '0': {
14
+ hidden: false,
15
+ position: 0
16
+ },
17
+ '1': {
18
+ hidden: false,
19
+ position: 1
20
+ },
21
+ '2': {
22
+ hidden: false,
23
+ position: 2
24
+ },
25
+ '3': {
26
+ hidden: false,
27
+ position: 3
28
+ },
29
+ '4': {
30
+ hidden: false,
31
+ position: 4
32
+ }
33
+ };
34
+
35
+ const setFirstSlide = (state: UISlidesState, slideFromAPI: SlideFromAPI): UISlidesState => {
36
+ const {questionText, answerUI} = mapApiSlideToUi({translate: (text: string) => text})(
37
+ slideFromAPI
38
+ );
39
+
40
+ return pipe(
41
+ set(['0', 'questionText'], questionText),
42
+ set(['0', 'answerUI'], answerUI),
43
+ set(['0', 'parentContentTitle'], 'Parent Title') // TODO parentContentTitle + translate
44
+ )(state);
45
+ };
46
+
47
+ // eslint-disable-next-line default-param-last
48
+ const reducer = (state: UISlidesState = initialState, action: UISlidesAction): UISlidesState => {
49
+ switch (action.type) {
50
+ case SET_CURRENT_SLIDE: {
51
+ return setFirstSlide(state, action.payload);
52
+ }
53
+ default:
54
+ return state;
55
+ }
56
+ };
57
+
58
+ export default reducer;