@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
@@ -17,11 +17,17 @@ export const sliderSlide = {
17
17
  tips: 'sli_41D5AovN~.tips'
18
18
  };
19
19
  export const sliderUISlide = {
20
- type: 'slider',
21
- placeholder: 'sli_41D5AovN~.explanation',
22
- minLabel: '1 undefined',
23
- maxLabel: '10 undefined',
24
- title: '0 sli_41D5AovN~.unitLabel',
25
- value: -0.1111111111111111,
26
- onChange: noop
20
+ questionText: 'sli_41D5AovN~.header',
21
+ answerUI: {
22
+ help: 'sli_41D5AovN~.explanation',
23
+ model: {
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
31
+ }
32
+ }
27
33
  };
@@ -1,4 +1,3 @@
1
- import { Template } from '../../../types/slides';
2
- import { SlideFromAPI } from '../../../types/common';
1
+ import { SlideFromAPI, UISlide } from '../../../types/common';
3
2
  export declare const textTemplateSlide: SlideFromAPI;
4
- export declare const textTemplateUISlide: Template;
3
+ export declare const textTemplateUISlide: Partial<UISlide>;
@@ -34,15 +34,21 @@ export const textTemplateSlide = {
34
34
  id: 'sli_VJKQonm2g'
35
35
  };
36
36
  export const textTemplateUISlide = {
37
- type: 'template',
38
- template: 'Un {{inp58402}} model.',
39
- answers: [
40
- {
41
- type: 'text',
42
- name: 'inp58402',
43
- placeholder: 'Type here',
44
- value: undefined,
45
- onChange: noop
37
+ questionText: 'Comment le protégé doit-il percevoir son mentor ?',
38
+ answerUI: {
39
+ help: 'Saisissez votre réponse (en anglais).',
40
+ model: {
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
50
+ }
51
+ ]
46
52
  }
47
- ]
53
+ }
48
54
  };
package/es/index.js CHANGED
@@ -5,80 +5,20 @@ import { TemplateContext } from '@coorpacademy/components/es/template/app-review
5
5
  import isEmpty from 'lodash/fp/isEmpty';
6
6
  import get from 'lodash/fp/get';
7
7
  import configureStore from './configure-store';
8
- import { congratsProps, correctionPopinProps } from './fixtures/temp-fixture';
9
- import { updateSlidesOnNext, updateSlidesOnValidation, validateSlide } from './actions/data/slides';
8
+ import { validateSlide } from './actions/ui/slides';
10
9
  import { navigateTo, navigateBack } from './actions/ui/navigation';
11
10
  import { storeToken } from './actions/data/token';
12
- import { updateFinishedSlides } from './actions/ui/finished-slides';
13
- import { updateReviewStatus } from './actions/ui/review-status';
14
- import { updateStepItemsOnValidation, updateStepItemsOnNext } from './actions/ui/step-items';
15
11
  import { fetchSkills } from './actions/api/fetch-skills';
16
12
  import { postProgression } from './actions/api/post-progression';
17
13
  import { VIEWS } from './common';
14
+ import { mapStateToSlidesProps } from './views/slides';
15
+ import { mapStateToSkillsProps } from './views/skills';
18
16
  const mapDispatchToProps = {
19
17
  navigateTo,
20
18
  navigateBack,
21
- validateSlide,
22
- updateSlidesOnValidation,
23
- updateSlidesOnNext,
24
- updateReviewStatus,
25
- updateStepItemsOnValidation,
26
- updateStepItemsOnNext,
27
- updateFinishedSlides
19
+ validateSlide
28
20
  };
29
21
  const getCurrentViewName = (storeState) => storeState.ui.navigation[storeState.ui.navigation.length - 1];
30
- const mapStateToSkillsProps = (state) => {
31
- if (!state.data.skills) {
32
- return null;
33
- }
34
- return {
35
- title: '@todo title',
36
- titleNoSkills: '@todo titleNoSkills',
37
- textNoSkills: '@todo textNoSkills',
38
- iconSkillAriaLabel: '@todo iconSkillAriaLabel',
39
- isLoading: false,
40
- isLoadingAriaLabel: '@todo loading',
41
- listSkills: state.data.skills.map(skill => ({
42
- 'aria-label': '',
43
- isCustom: skill.custom,
44
- skillTitle: skill.name,
45
- skillAriaLabel: '@todo skill aria label',
46
- buttonLabel: '@todo button',
47
- buttonAriaLabel: '@todo button aria label',
48
- reviseLabel: '@todo revise',
49
- reviseAriaLabel: '@todo revise aria label',
50
- // eslint-disable-next-line no-console
51
- onClick: () => console.log('@todo plug dispatcher select skill')
52
- }))
53
- };
54
- };
55
- const mapStateToSlidesProps = (state) => {
56
- if (!state.data.slides) {
57
- return null;
58
- }
59
- return {
60
- headerProps: {
61
- mode: '__revision_mode',
62
- skillName: '__agility',
63
- onQuitClick: () => {
64
- // eslint-disable-next-line no-console
65
- console.log('onQuitClick');
66
- },
67
- 'aria-label': 'aria-header-wrapper',
68
- closeButtonAriaLabel: 'aria-close-button'
69
- },
70
- slides: state.data.slides,
71
- validate: {
72
- label: '__validate'
73
- },
74
- finishedSlides: state.ui.finishedSlides,
75
- stepItems: state.ui.stepItems,
76
- reviewStatus: state.ui.reviewStatus,
77
- correctionPopinProps,
78
- congratsProps,
79
- progression: state.data.progression
80
- };
81
- };
82
22
  const mapStateToProps = (state) => {
83
23
  return {
84
24
  viewName: getCurrentViewName(state),
@@ -89,7 +29,7 @@ const mapStateToProps = (state) => {
89
29
  const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
90
30
  const AppReview = ({ options }) => {
91
31
  const [store, setStore] = useState(null);
92
- const [isSlideFetched, setIsSlideFetched] = useState(false);
32
+ const [isProgressionCreated, setIsProgressionCreated] = useState(false);
93
33
  useEffect(() => {
94
34
  if (store)
95
35
  return;
@@ -97,14 +37,13 @@ const AppReview = ({ options }) => {
97
37
  setStore(newStore);
98
38
  }, [options, store]);
99
39
  useEffect(() => {
100
- if (!store || isSlideFetched)
40
+ if (!store || isProgressionCreated)
101
41
  return;
102
42
  return store.subscribe(() => {
103
- const isSlidePresent = !isEmpty(store.getState().data.slides[0].questionText);
104
- return isSlidePresent && setIsSlideFetched(isSlidePresent);
105
- }); // using the first slide questionText for now, should only check for a slide's presence
106
- // when the refactor is done (slides will be feed one by one on api's side)
107
- }, [isSlideFetched, options, store]);
43
+ const isProgressionPresent = !isEmpty(store.getState().data.progression);
44
+ return isProgressionPresent && setIsProgressionCreated(isProgressionPresent);
45
+ });
46
+ }, [isProgressionCreated, options, store]);
108
47
  useEffect(() => {
109
48
  const token = get('token', options);
110
49
  if (store === null || isEmpty(token))
@@ -116,8 +55,8 @@ const AppReview = ({ options }) => {
116
55
  if (store === null || isEmpty(token))
117
56
  return;
118
57
  const skillRef = get('skillRef', options);
119
- // ThunkAction is not assignable to parameter of type 'AnyAction'
120
- // ts problem describre here = https://github.com/reduxjs/redux-thunk/issues/333
58
+ /* ThunkAction is not assignable to parameter of type 'AnyAction'
59
+ ts problem is described here = https://github.com/reduxjs/redux-thunk/issues/333 */
121
60
  skillRef
122
61
  ? store.dispatch(postProgression(skillRef, token))
123
62
  : store.dispatch(fetchSkills(token));
@@ -126,16 +65,13 @@ const AppReview = ({ options }) => {
126
65
  if (store === null)
127
66
  return;
128
67
  const { skillRef } = options;
129
- if (skillRef && !isSlideFetched) {
68
+ if (skillRef && !isProgressionCreated) {
130
69
  store.dispatch(navigateTo('loader')); // use loader while posting progression
131
70
  return;
132
71
  }
133
- // TODO: when slides state is refactored (data + mapping),
134
- // use loader in case a skillRef is found && no slides from the API
135
- // are found
136
72
  const initialView = skillRef ? VIEWS.slides : VIEWS.skills;
137
73
  store.dispatch(navigateTo(initialView));
138
- }, [isSlideFetched, options, store]);
74
+ }, [isProgressionCreated, options, store]);
139
75
  if (!store)
140
76
  return null;
141
77
  const { templateContext: values } = options;
@@ -14,5 +14,5 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
14
14
  skills: SkillsState;
15
15
  slides: SlidesState;
16
16
  token: TokenState;
17
- }>, import("../../actions/data/slides").ValidateSlide | import("../../actions/data/slides").SlidesAction | import("../../actions/api/post-progression").ReceiveProgression | import("../../actions/api/fetch-skills").ReceivedSkills | import("../../actions/data/token").StoreToken>;
17
+ }>, import("../../actions/api/post-progression").ReceiveProgression | import("../../actions/api/fetch-skills").ReceivedSkills | import("./slides").SlidesAction | import("../../actions/data/token").StoreToken>;
18
18
  export default _default;
@@ -1,19 +1,6 @@
1
- import { ValidateSlide } from '../../actions/data/slides';
1
+ import { ValidateSlide } from '../../actions/ui/slides';
2
2
  import { ReceiveProgression } from '../../actions/api/post-progression';
3
- export declare type ProgressionState = {
4
- _id?: string;
5
- state: {
6
- isCorrect: boolean;
7
- nextContent: {
8
- ref: 'successExitNode' | string;
9
- type: 'success' | 'slide';
10
- };
11
- pendingSlides: string[];
12
- step: {
13
- current: number;
14
- };
15
- };
16
- slideNumber?: number;
17
- } | null;
3
+ import { ProgressionFromAPI } from '../../types/common';
4
+ export declare type ProgressionState = ProgressionFromAPI | null;
18
5
  declare const reducer: (state: ProgressionState | undefined, action: ValidateSlide | ReceiveProgression) => ProgressionState;
19
6
  export default reducer;
@@ -1,30 +1,12 @@
1
- import { getOr } from 'lodash/fp';
2
- import { VALIDATE_SLIDE } from '../../actions/data/slides';
1
+ import { VALIDATE_SLIDE } from '../../actions/ui/slides';
3
2
  import { POST_PROGRESSION_SUCCESS } from '../../actions/api/post-progression';
4
3
  const reducer = (
5
4
  // eslint-disable-next-line default-param-last
6
5
  state = null, action) => {
7
6
  switch (action.type) {
8
7
  case VALIDATE_SLIDE: {
9
- const previousSlideNumber = getOr(-1, 'slideNumber', state);
10
- // hard coded for now
11
- // TODO: fix on VALIDATE ticket
12
- return {
13
- _id: '1234',
14
- // virtual field
15
- slideNumber: previousSlideNumber + 1,
16
- state: {
17
- pendingSlides: [],
18
- step: {
19
- current: Number.NaN
20
- },
21
- isCorrect: true,
22
- nextContent: {
23
- ref: 'sli_V1gKpYYZ2',
24
- type: 'slide'
25
- }
26
- }
27
- };
8
+ // TODO: fix on VALIDATE ticket -> launch a POST PROGRESSION
9
+ return state;
28
10
  }
29
11
  case POST_PROGRESSION_SUCCESS: {
30
12
  const progression = action.payload;
@@ -34,5 +16,4 @@ state = null, action) => {
34
16
  return state;
35
17
  }
36
18
  };
37
- // -----------------------------------------------------------------------------
38
19
  export default reducer;
@@ -1,9 +1,8 @@
1
- import { SlidesAction } from '../../actions/data/slides';
2
- import { Slide } from '../../types/common';
3
- export declare type SlidesState = {
4
- slideNumbers: number[];
5
- [key: number]: Slide;
6
- };
1
+ import { ValidateSlide } from '../../actions/ui/slides';
2
+ import { ReceivedSlide } from '../../actions/api/fetch-slide';
3
+ import { SlideFromAPI } from '../../types/common';
4
+ export declare type SlidesAction = ReceivedSlide | ValidateSlide;
5
+ export declare type SlidesState = Record<string, SlideFromAPI>;
7
6
  export declare const initialState: SlidesState;
8
7
  declare const reducer: (state: SlidesState | undefined, action: SlidesAction) => SlidesState;
9
8
  export default reducer;
@@ -1,118 +1,15 @@
1
- import map from 'lodash/fp/map';
2
- import { UPDATE_SLIDES_ON_NEXT, UPDATE_SLIDES_ON_VALIDATION } from '../../actions/data/slides';
3
- import { HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK } from '../../common';
4
- import { slide as qcmSlide } from '../../fixtures/qcm-slide';
1
+ import set from 'lodash/fp/set';
5
2
  import { SLIDE_FETCH_SUCCESS } from '../../actions/api/fetch-slide';
6
- const getInitialState = () => {
7
- const state = {
8
- slideNumbers
9
- };
10
- // eslint-disable-next-line fp/no-loops
11
- for (let index = 0; index < TOTAL_SLIDES_STACK; index++) {
12
- state[index] = { hidden: false, position: index };
13
- }
14
- return state;
15
- };
16
- export const initialState = getInitialState();
17
- // -----------------------------------------------------------------------------
18
- const setFirstSlide = (state, slide) => {
19
- const _state = {
20
- slideNumbers
21
- };
22
- // eslint-disable-next-line lodash-fp/no-unused-result
23
- map(index => {
24
- const previousValue = state[index];
25
- // Only update the 1st one
26
- const content = index === 0 ? { ...previousValue, ...slide } : { ...previousValue };
27
- _state[index] = { ...content };
28
- }, state.slideNumbers);
29
- return _state;
30
- };
31
- // ||-------> Handles the updates of a given slide on validation,
32
- // & then updates de remaining slides if this given change should impact their content
33
- const stateUpdateOnValidation = (state, payload) => {
34
- const { slideNumber, newSlideContent, numberOfFinishedSlides, nextContent } = payload;
35
- const _state = {
36
- slideNumbers
37
- };
38
- // eslint-disable-next-line lodash-fp/no-unused-result
39
- map(index => {
40
- const previousValue = state[index];
41
- // the current slide
42
- if (index === slideNumber) {
43
- // only one slide remaining, presets the next value
44
- if (numberOfFinishedSlides === HIGHEST_INDEX) {
45
- _state[index] = {
46
- ...previousValue,
47
- nextContent,
48
- position: newSlideContent.position,
49
- isCorrect: newSlideContent.isCorrect
50
- };
51
- }
52
- else
53
- _state[slideNumber] = { ...previousValue, ...newSlideContent };
54
- }
55
- else {
56
- // updates the rest of the slides here
57
- const { hidden, position } = previousValue;
58
- _state[index] = { ...nextContent, endReview: newSlideContent.endReview, hidden, position };
59
- }
60
- }, state.slideNumbers);
61
- return _state;
62
- };
63
- // ||-------> Handles the updates of a given slide on correction popin's next click,
64
- // & then updates de remaining slides (updates position to trigger animations)
65
- const stateUpdateOnNext = (state, payload) => {
66
- const { slideNumber, newSlideContent, numberOfFinishedSlides } = payload;
67
- const _state = {
68
- slideNumbers
69
- };
70
- // eslint-disable-next-line lodash-fp/no-unused-result
71
- map(index => {
72
- const previousValue = state[index];
73
- // the current slide
74
- if (index === slideNumber) {
75
- // when there is only one slide remaining, updates the slide value
76
- if (numberOfFinishedSlides === HIGHEST_INDEX && previousValue.nextContent) {
77
- _state[index] = { ...previousValue.nextContent, position: previousValue.position };
78
- }
79
- else
80
- _state[slideNumber] = newSlideContent;
81
- }
82
- else {
83
- // updates the rest of the slides here
84
- const { hidden, position, answerUI, questionText } = previousValue;
85
- _state[index] = {
86
- hidden,
87
- position: position - 1,
88
- answerUI,
89
- questionText,
90
- endReview: newSlideContent.endReview
91
- };
92
- }
93
- }, state.slideNumbers);
94
- return _state;
95
- };
96
- // -----------------------------------------------------------------------------
3
+ export const initialState = {};
97
4
  // eslint-disable-next-line default-param-last
98
5
  const reducer = (state = initialState, action) => {
99
6
  switch (action.type) {
100
7
  case SLIDE_FETCH_SUCCESS: {
101
- // TODO: An intermediate slide transform is needed here (or in fetchSlide)
102
- // const apiSlide = action.payload;
103
- // apiSlide adapt to uiSlide
104
- const uiSlide = qcmSlide;
105
- return setFirstSlide(state, uiSlide);
106
- }
107
- case UPDATE_SLIDES_ON_VALIDATION: {
108
- return stateUpdateOnValidation(state, action.payload);
109
- }
110
- case UPDATE_SLIDES_ON_NEXT: {
111
- return stateUpdateOnNext(state, action.payload);
8
+ const slide = action.payload;
9
+ return set(slide.id, slide, state);
112
10
  }
113
11
  default:
114
12
  return state;
115
13
  }
116
14
  };
117
- // -----------------------------------------------------------------------------
118
15
  export default reducer;
@@ -12,10 +12,9 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
12
  token: import("./data/token").TokenState;
13
13
  }>;
14
14
  ui: import("redux").CombinedState<{
15
- finishedSlides: import("./ui/finished-slides").FinishedSlidesState;
15
+ currentSlideRef: string;
16
16
  navigation: import("./ui/navigation").NavigationState;
17
- reviewStatus: import("./ui/review-status").ReviewStatusState;
18
- stepItems: import("./ui/step-items").StepItemsState;
17
+ slides: import("./ui/slides").UISlidesState;
19
18
  }>;
20
- }>, import("../actions/data/slides").ValidateSlide | import("../actions/data/slides").SlidesAction | import("../actions/api/post-progression").ReceiveProgression | import("../actions/api/fetch-skills").ReceivedSkills | import("../actions/data/token").StoreToken | import("../actions/ui/finished-slides").UpdateFinishedSlides | import("../actions/ui/navigation").NavigateTo | import("../actions/ui/navigation").NavigateBack | import("../actions/ui/review-status").UpdateReviewStatus | import("../actions/ui/step-items").StepItemsAction>;
19
+ }>, import("../actions/ui/slides").SetCurrentSlide | import("../actions/api/post-progression").ReceiveProgression | import("../actions/api/fetch-skills").ReceivedSkills | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/ui/navigation").NavigateTo | import("../actions/ui/navigation").NavigateBack>;
21
20
  export default _default;
@@ -0,0 +1,4 @@
1
+ import { UISlidesAction } from '../../actions/ui/slides';
2
+ export declare type CurrentSlideRefState = string;
3
+ declare const reducer: (state: string | undefined, action: UISlidesAction) => CurrentSlideRefState;
4
+ export default reducer;
@@ -1,10 +1,10 @@
1
- import { UPDATE_REVIEW_STATUS } from '../../actions/ui/review-status';
1
+ import { SET_CURRENT_SLIDE } from '../../actions/ui/slides';
2
2
  const reducer = (
3
3
  // eslint-disable-next-line default-param-last
4
- state = 'ongoing', action) => {
4
+ state = '', action) => {
5
5
  switch (action.type) {
6
- case UPDATE_REVIEW_STATUS: {
7
- return action.payload;
6
+ case SET_CURRENT_SLIDE: {
7
+ return action.payload.id;
8
8
  }
9
9
  default:
10
10
  return state;
@@ -1,17 +1,14 @@
1
- import { FinishedSlidesState } from './finished-slides';
1
+ import { CurrentSlideRefState } from './current-slide-ref';
2
2
  import { NavigationState } from './navigation';
3
- import { ReviewStatusState } from './review-status';
4
- import { StepItemsState } from './step-items';
3
+ import { UISlidesState } from './slides';
5
4
  export declare type UIState = {
5
+ currentSlideRef: CurrentSlideRefState;
6
6
  navigation: NavigationState;
7
- stepItems: StepItemsState;
8
- finishedSlides: FinishedSlidesState;
9
- reviewStatus: ReviewStatusState;
7
+ slides: UISlidesState;
10
8
  };
11
9
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
- finishedSlides: FinishedSlidesState;
10
+ currentSlideRef: string;
13
11
  navigation: NavigationState;
14
- reviewStatus: ReviewStatusState;
15
- stepItems: StepItemsState;
16
- }>, import("../../actions/ui/finished-slides").UpdateFinishedSlides | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack | import("../../actions/ui/review-status").UpdateReviewStatus | import("../../actions/ui/step-items").StepItemsAction>;
12
+ slides: UISlidesState;
13
+ }>, import("../../actions/ui/slides").SetCurrentSlide | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack>;
17
14
  export default _default;
@@ -1,11 +1,9 @@
1
1
  import { combineReducers } from 'redux';
2
- import finishedSlides from './finished-slides';
2
+ import currentSlideRef from './current-slide-ref';
3
3
  import navigation from './navigation';
4
- import reviewStatus from './review-status';
5
- import stepItems from './step-items';
4
+ import slides from './slides';
6
5
  export default combineReducers({
7
- finishedSlides,
6
+ currentSlideRef,
8
7
  navigation,
9
- reviewStatus,
10
- stepItems
8
+ slides
11
9
  });
@@ -0,0 +1,9 @@
1
+ import type { UISlide } from '../../types/common';
2
+ import { SlideIndexes } from '../../common';
3
+ import { UISlidesAction } from '../../actions/ui/slides';
4
+ export declare type UISlidesState = {
5
+ [key in SlideIndexes]: UISlide;
6
+ };
7
+ export declare const initialState: UISlidesState;
8
+ declare const reducer: (state: UISlidesState | undefined, action: UISlidesAction) => UISlidesState;
9
+ export default reducer;
@@ -0,0 +1,42 @@
1
+ import pipe from 'lodash/fp/pipe';
2
+ import set from 'lodash/fp/set';
3
+ import { mapApiSlideToUi } from '../../helpers/map-api-slide-to-ui';
4
+ import { SET_CURRENT_SLIDE } from '../../actions/ui/slides';
5
+ export const initialState = {
6
+ '0': {
7
+ hidden: false,
8
+ position: 0
9
+ },
10
+ '1': {
11
+ hidden: false,
12
+ position: 1
13
+ },
14
+ '2': {
15
+ hidden: false,
16
+ position: 2
17
+ },
18
+ '3': {
19
+ hidden: false,
20
+ position: 3
21
+ },
22
+ '4': {
23
+ hidden: false,
24
+ position: 4
25
+ }
26
+ };
27
+ const setFirstSlide = (state, slideFromAPI) => {
28
+ const { questionText, answerUI } = mapApiSlideToUi({ translate: (text) => text })(slideFromAPI);
29
+ return pipe(set(['0', 'questionText'], questionText), set(['0', 'answerUI'], answerUI), set(['0', 'parentContentTitle'], 'Parent Title') // TODO parentContentTitle + translate
30
+ )(state);
31
+ };
32
+ // eslint-disable-next-line default-param-last
33
+ const reducer = (state = initialState, action) => {
34
+ switch (action.type) {
35
+ case SET_CURRENT_SLIDE: {
36
+ return setFirstSlide(state, action.payload);
37
+ }
38
+ default:
39
+ return state;
40
+ }
41
+ };
42
+ export default reducer;
@@ -5,15 +5,17 @@ const skillRef = '_skill-ref';
5
5
  const result = {
6
6
  _id: '123456123456',
7
7
  state: {
8
+ allAnswers: [],
8
9
  isCorrect: true,
9
- step: {
10
- current: 1
11
- },
12
10
  nextContent: {
13
11
  type: 'slide',
14
12
  ref: 'sli_NJ3m5KtWh'
15
13
  },
16
- pendingSlides: []
14
+ pendingSlides: [],
15
+ slides: [],
16
+ step: {
17
+ current: 1
18
+ }
17
19
  }
18
20
  };
19
21
  test.before(() => {
@@ -7,12 +7,15 @@ export const services = {
7
7
  slidesToReview: 2,
8
8
  name: 'skill-test',
9
9
  custom: false
10
+ // TODO parentContentTitle
10
11
  },
11
12
  {
12
13
  skillRef: '_skill-ref-2',
13
14
  slidesToReview: 2,
14
15
  name: 'skill-test-2',
15
- custom: true
16
+ custom: true,
17
+ parentContentTitle: 'parentContentTitle 2'
18
+ // TODO parentContentTitle
16
19
  }
17
20
  ]);
18
21
  },
@@ -22,15 +25,24 @@ export const services = {
22
25
  postProgression: () => {
23
26
  return Promise.resolve({
24
27
  _id: '62b1d1087aa12f00253f40ee',
28
+ content: {
29
+ ref: '_skill-ref',
30
+ type: 'skill'
31
+ },
32
+ engine: {
33
+ ref: 'review'
34
+ },
25
35
  state: {
26
- pendingSlides: [],
27
- step: {
28
- current: 1
29
- },
36
+ allAnswers: [],
30
37
  isCorrect: true,
31
38
  nextContent: {
32
39
  ref: 'sli_N1XACJobn',
33
40
  type: 'slide'
41
+ },
42
+ pendingSlides: [],
43
+ slides: [],
44
+ step: {
45
+ current: 1
34
46
  }
35
47
  }
36
48
  });