@coorpacademy/app-review 0.2.12 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/es/actions/api/fetch-correction.js +1 -1
  2. package/es/actions/api/post-answer.d.ts +6 -0
  3. package/es/actions/api/post-answer.js +3 -1
  4. package/es/actions/ui/answers.d.ts +3 -0
  5. package/es/actions/ui/answers.js +3 -1
  6. package/es/reducers/index.d.ts +1 -1
  7. package/es/reducers/ui/answers.d.ts +4 -2
  8. package/es/reducers/ui/answers.js +6 -3
  9. package/es/reducers/ui/index.d.ts +4 -4
  10. package/es/reducers/ui/slide.d.ts +6 -4
  11. package/es/reducers/ui/slide.js +12 -4
  12. package/es/views/slides/index.js +4 -4
  13. package/lib/actions/api/fetch-correction.js +1 -1
  14. package/lib/actions/api/post-answer.d.ts +6 -0
  15. package/lib/actions/api/post-answer.js +4 -2
  16. package/lib/actions/ui/answers.d.ts +3 -0
  17. package/lib/actions/ui/answers.js +3 -1
  18. package/lib/reducers/index.d.ts +1 -1
  19. package/lib/reducers/ui/answers.d.ts +4 -2
  20. package/lib/reducers/ui/answers.js +6 -3
  21. package/lib/reducers/ui/index.d.ts +4 -4
  22. package/lib/reducers/ui/slide.d.ts +6 -4
  23. package/lib/reducers/ui/slide.js +12 -4
  24. package/lib/views/slides/index.js +4 -4
  25. package/package.json +2 -2
  26. package/src/actions/api/fetch-correction.ts +1 -1
  27. package/src/actions/api/post-answer.ts +5 -1
  28. package/src/actions/api/test/fetch-correction.test.ts +6 -2
  29. package/src/actions/api/test/fetch-rank.test.ts +2 -4
  30. package/src/actions/api/test/fetch-skills.test.ts +2 -4
  31. package/src/actions/api/test/fetch-slide.test.ts +2 -4
  32. package/src/actions/api/test/post-answer.test.ts +52 -13
  33. package/src/actions/api/test/post-progression.test.ts +2 -4
  34. package/src/actions/data/test/token.test.ts +2 -4
  35. package/src/actions/ui/answers.ts +4 -1
  36. package/src/actions/ui/test/answers.test.ts +38 -14
  37. package/src/actions/ui/test/next-slide.test.ts +8 -4
  38. package/src/actions/ui/test/slides.test.ts +2 -4
  39. package/src/reducers/data/test/progression.test.ts +1 -0
  40. package/src/reducers/ui/answers.ts +11 -5
  41. package/src/reducers/ui/index.ts +2 -2
  42. package/src/reducers/ui/slide.ts +30 -9
  43. package/src/reducers/ui/test/answers.test.ts +61 -13
  44. package/src/reducers/ui/test/slide.test.ts +36 -7
  45. package/src/views/skills/test/skills.test.ts +4 -8
  46. package/src/views/slides/index.ts +4 -4
  47. package/src/views/slides/test/index.test.ts +173 -28
  48. package/src/views/slides/test/slide.free-text.on-change.test.ts +7 -2
  49. package/src/views/slides/test/slide.qcm-drag.on-click.test.ts +7 -2
  50. package/src/views/slides/test/slide.qcm-graphic.on-click.test.ts +7 -2
  51. package/src/views/slides/test/slide.qcm.on-click.test.ts +7 -2
  52. package/src/views/slides/test/slide.slider.on-change.test.ts +7 -2
  53. package/src/views/slides/test/slide.slider.on-slider-change.test.ts +7 -2
  54. package/src/views/slides/test/slide.template.on-change.test.ts +12 -4
  55. package/es/actions/api/test/fetch-correction.test.d.ts +0 -1
  56. package/es/actions/api/test/fetch-correction.test.js +0 -91
  57. package/es/actions/api/test/fetch-rank.test.d.ts +0 -1
  58. package/es/actions/api/test/fetch-rank.test.js +0 -100
  59. package/es/actions/api/test/fetch-skills.test.d.ts +0 -1
  60. package/es/actions/api/test/fetch-skills.test.js +0 -61
  61. package/es/actions/api/test/fetch-slide.test.d.ts +0 -1
  62. package/es/actions/api/test/fetch-slide.test.js +0 -68
  63. package/es/actions/api/test/post-answer.test.d.ts +0 -1
  64. package/es/actions/api/test/post-answer.test.js +0 -172
  65. package/es/actions/api/test/post-progression.test.d.ts +0 -1
  66. package/es/actions/api/test/post-progression.test.js +0 -109
  67. package/es/actions/data/test/token.test.d.ts +0 -1
  68. package/es/actions/data/test/token.test.js +0 -27
  69. package/es/actions/ui/test/answers.test.d.ts +0 -1
  70. package/es/actions/ui/test/answers.test.js +0 -117
  71. package/es/actions/ui/test/next-slide.test.d.ts +0 -1
  72. package/es/actions/ui/test/next-slide.test.js +0 -63
  73. package/es/actions/ui/test/slides.test.d.ts +0 -1
  74. package/es/actions/ui/test/slides.test.js +0 -28
  75. package/es/reducers/data/test/corrections.test.d.ts +0 -1
  76. package/es/reducers/data/test/corrections.test.js +0 -27
  77. package/es/reducers/data/test/progression.test.d.ts +0 -1
  78. package/es/reducers/data/test/progression.test.js +0 -24
  79. package/es/reducers/data/test/rank.test.d.ts +0 -1
  80. package/es/reducers/data/test/rank.test.js +0 -59
  81. package/es/reducers/data/test/skills.test.d.ts +0 -1
  82. package/es/reducers/data/test/skills.test.js +0 -12
  83. package/es/reducers/data/test/slides.test.d.ts +0 -1
  84. package/es/reducers/data/test/slides.test.js +0 -21
  85. package/es/reducers/data/test/token.test.d.ts +0 -1
  86. package/es/reducers/data/test/token.test.js +0 -11
  87. package/es/reducers/ui/test/answers.test.d.ts +0 -1
  88. package/es/reducers/ui/test/answers.test.js +0 -31
  89. package/es/reducers/ui/test/current-slide-ref.test.d.ts +0 -1
  90. package/es/reducers/ui/test/current-slide-ref.test.js +0 -12
  91. package/es/reducers/ui/test/navigation.test.d.ts +0 -1
  92. package/es/reducers/ui/test/navigation.test.js +0 -15
  93. package/es/reducers/ui/test/slide.test.d.ts +0 -1
  94. package/es/reducers/ui/test/slide.test.js +0 -24
  95. package/es/services/test/fetch-correction.test.d.ts +0 -1
  96. package/es/services/test/fetch-correction.test.js +0 -39
  97. package/es/services/test/fetch-rank.test.d.ts +0 -1
  98. package/es/services/test/fetch-rank.test.js +0 -24
  99. package/es/services/test/fetch-skills.test.d.ts +0 -1
  100. package/es/services/test/fetch-skills.test.js +0 -29
  101. package/es/services/test/fetch-slide.test.d.ts +0 -1
  102. package/es/services/test/fetch-slide.test.js +0 -22
  103. package/es/services/test/post-answer.test.d.ts +0 -1
  104. package/es/services/test/post-answer.test.js +0 -88
  105. package/es/services/test/post-progression.test.d.ts +0 -1
  106. package/es/services/test/post-progression.test.js +0 -56
  107. package/es/views/skills/test/skills.test.d.ts +0 -1
  108. package/es/views/skills/test/skills.test.js +0 -98
  109. package/es/views/slides/test/index.test.d.ts +0 -1
  110. package/es/views/slides/test/index.test.js +0 -979
  111. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +0 -1
  112. package/es/views/slides/test/map-api-slide-to-ui.test.js +0 -36
  113. package/es/views/slides/test/slide.free-text.on-change.test.d.ts +0 -1
  114. package/es/views/slides/test/slide.free-text.on-change.test.js +0 -72
  115. package/es/views/slides/test/slide.qcm-drag.on-click.test.d.ts +0 -1
  116. package/es/views/slides/test/slide.qcm-drag.on-click.test.js +0 -72
  117. package/es/views/slides/test/slide.qcm-graphic.on-click.test.d.ts +0 -1
  118. package/es/views/slides/test/slide.qcm-graphic.on-click.test.js +0 -72
  119. package/es/views/slides/test/slide.qcm.on-click.test.d.ts +0 -1
  120. package/es/views/slides/test/slide.qcm.on-click.test.js +0 -74
  121. package/es/views/slides/test/slide.slider.on-change.test.d.ts +0 -1
  122. package/es/views/slides/test/slide.slider.on-change.test.js +0 -73
  123. package/es/views/slides/test/slide.slider.on-slider-change.test.d.ts +0 -1
  124. package/es/views/slides/test/slide.slider.on-slider-change.test.js +0 -63
  125. package/es/views/slides/test/slide.template.on-change.test.d.ts +0 -1
  126. package/es/views/slides/test/slide.template.on-change.test.js +0 -85
  127. package/lib/actions/api/test/fetch-correction.test.d.ts +0 -1
  128. package/lib/actions/api/test/fetch-correction.test.js +0 -151
  129. package/lib/actions/api/test/fetch-rank.test.d.ts +0 -1
  130. package/lib/actions/api/test/fetch-rank.test.js +0 -171
  131. package/lib/actions/api/test/fetch-skills.test.d.ts +0 -1
  132. package/lib/actions/api/test/fetch-skills.test.js +0 -120
  133. package/lib/actions/api/test/fetch-slide.test.d.ts +0 -1
  134. package/lib/actions/api/test/fetch-slide.test.js +0 -127
  135. package/lib/actions/api/test/post-answer.test.d.ts +0 -1
  136. package/lib/actions/api/test/post-answer.test.js +0 -254
  137. package/lib/actions/api/test/post-progression.test.d.ts +0 -1
  138. package/lib/actions/api/test/post-progression.test.js +0 -167
  139. package/lib/actions/data/test/token.test.d.ts +0 -1
  140. package/lib/actions/data/test/token.test.js +0 -72
  141. package/lib/actions/ui/test/answers.test.d.ts +0 -1
  142. package/lib/actions/ui/test/answers.test.js +0 -233
  143. package/lib/actions/ui/test/next-slide.test.d.ts +0 -1
  144. package/lib/actions/ui/test/next-slide.test.js +0 -64
  145. package/lib/actions/ui/test/slides.test.d.ts +0 -1
  146. package/lib/actions/ui/test/slides.test.js +0 -73
  147. package/lib/reducers/data/test/corrections.test.d.ts +0 -1
  148. package/lib/reducers/data/test/corrections.test.js +0 -28
  149. package/lib/reducers/data/test/progression.test.d.ts +0 -1
  150. package/lib/reducers/data/test/progression.test.js +0 -24
  151. package/lib/reducers/data/test/rank.test.d.ts +0 -1
  152. package/lib/reducers/data/test/rank.test.js +0 -59
  153. package/lib/reducers/data/test/skills.test.d.ts +0 -1
  154. package/lib/reducers/data/test/skills.test.js +0 -12
  155. package/lib/reducers/data/test/slides.test.d.ts +0 -1
  156. package/lib/reducers/data/test/slides.test.js +0 -22
  157. package/lib/reducers/data/test/token.test.d.ts +0 -1
  158. package/lib/reducers/data/test/token.test.js +0 -11
  159. package/lib/reducers/ui/test/answers.test.d.ts +0 -1
  160. package/lib/reducers/ui/test/answers.test.js +0 -31
  161. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +0 -1
  162. package/lib/reducers/ui/test/current-slide-ref.test.js +0 -12
  163. package/lib/reducers/ui/test/navigation.test.d.ts +0 -1
  164. package/lib/reducers/ui/test/navigation.test.js +0 -15
  165. package/lib/reducers/ui/test/slide.test.d.ts +0 -1
  166. package/lib/reducers/ui/test/slide.test.js +0 -24
  167. package/lib/services/test/fetch-correction.test.d.ts +0 -1
  168. package/lib/services/test/fetch-correction.test.js +0 -95
  169. package/lib/services/test/fetch-rank.test.d.ts +0 -1
  170. package/lib/services/test/fetch-rank.test.js +0 -78
  171. package/lib/services/test/fetch-skills.test.d.ts +0 -1
  172. package/lib/services/test/fetch-skills.test.js +0 -83
  173. package/lib/services/test/fetch-slide.test.d.ts +0 -1
  174. package/lib/services/test/fetch-slide.test.js +0 -76
  175. package/lib/services/test/post-answer.test.d.ts +0 -1
  176. package/lib/services/test/post-answer.test.js +0 -142
  177. package/lib/services/test/post-progression.test.d.ts +0 -1
  178. package/lib/services/test/post-progression.test.js +0 -110
  179. package/lib/views/skills/test/skills.test.d.ts +0 -1
  180. package/lib/views/skills/test/skills.test.js +0 -98
  181. package/lib/views/slides/test/index.test.d.ts +0 -1
  182. package/lib/views/slides/test/index.test.js +0 -990
  183. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +0 -1
  184. package/lib/views/slides/test/map-api-slide-to-ui.test.js +0 -47
  185. package/lib/views/slides/test/slide.free-text.on-change.test.d.ts +0 -1
  186. package/lib/views/slides/test/slide.free-text.on-change.test.js +0 -74
  187. package/lib/views/slides/test/slide.qcm-drag.on-click.test.d.ts +0 -1
  188. package/lib/views/slides/test/slide.qcm-drag.on-click.test.js +0 -74
  189. package/lib/views/slides/test/slide.qcm-graphic.on-click.test.d.ts +0 -1
  190. package/lib/views/slides/test/slide.qcm-graphic.on-click.test.js +0 -74
  191. package/lib/views/slides/test/slide.qcm.on-click.test.d.ts +0 -1
  192. package/lib/views/slides/test/slide.qcm.on-click.test.js +0 -76
  193. package/lib/views/slides/test/slide.slider.on-change.test.d.ts +0 -1
  194. package/lib/views/slides/test/slide.slider.on-change.test.js +0 -75
  195. package/lib/views/slides/test/slide.slider.on-slider-change.test.d.ts +0 -1
  196. package/lib/views/slides/test/slide.slider.on-slider-change.test.js +0 -65
  197. package/lib/views/slides/test/slide.template.on-change.test.d.ts +0 -1
  198. package/lib/views/slides/test/slide.template.on-change.test.js +0 -88
@@ -8,7 +8,7 @@ export const fetchCorrection = (dispatch, getState, { services }) => {
8
8
  const slideRef = get(['ui', 'currentSlideRef'], state);
9
9
  const token = get(['data', 'token'], state);
10
10
  const progressionId = get(['data', 'progression', '_id'], state);
11
- const answer = get(['ui', 'answers'], state);
11
+ const answer = get(['ui', 'answers', slideRef], state);
12
12
  const action = buildTask({
13
13
  types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
14
14
  meta: { slideRef },
@@ -6,9 +6,15 @@ export declare const POST_ANSWER_SUCCESS: "@@answer/POST_SUCCESS";
6
6
  export declare const POST_ANSWER_FAILURE: "@@answer/POST_FAILURE";
7
7
  export declare type PostAnswerRequestAction = {
8
8
  type: typeof POST_ANSWER_REQUEST;
9
+ meta: {
10
+ slideRef: string;
11
+ };
9
12
  };
10
13
  export declare type PostAnswerSuccessAction = {
11
14
  type: typeof POST_ANSWER_SUCCESS;
15
+ meta: {
16
+ slideRef: string;
17
+ };
12
18
  payload: ProgressionFromAPI;
13
19
  };
14
20
  export declare const postAnswer: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -8,13 +8,15 @@ export const POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS';
8
8
  export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
9
9
  export const postAnswer = async (dispatch, getState, { services }) => {
10
10
  const state = getState();
11
+ const currentSlideRef = get(['ui', 'currentSlideRef'], state);
11
12
  const token = get(['data', 'token'], state);
12
- const answer = get(['ui', 'answers'], state);
13
+ const answer = get(['ui', 'answers', currentSlideRef], state);
13
14
  const progression = get(['data', 'progression'], state);
14
15
  if (!progression)
15
16
  throw new Error('Cannot answer a question of an inexistent progression');
16
17
  const action = buildTask({
17
18
  types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
19
+ meta: { slideRef: currentSlideRef },
18
20
  task: () => services.postAnswer(progression, token, answer)
19
21
  });
20
22
  const response = await dispatch(action);
@@ -16,6 +16,9 @@ export declare const ANSWER_EDIT: {
16
16
  };
17
17
  export declare type EditAnswerAction = {
18
18
  type: typeof EDIT_QCM | typeof EDIT_QCM_GRAPHIC | typeof EDIT_QCM_DRAG | typeof EDIT_TEMPLATE | typeof EDIT_BASIC | typeof EDIT_SLIDER;
19
+ meta: {
20
+ slideRef: string;
21
+ };
19
22
  payload: string[];
20
23
  };
21
24
  export declare const editAnswer: (answer: string[]) => (dispatch: Dispatch, getState: () => StoreState) => EditAnswerAction;
@@ -1,5 +1,6 @@
1
1
  import flatten from 'lodash/fp/flatten';
2
2
  import get from 'lodash/fp/get';
3
+ import getOr from 'lodash/fp/getOr';
3
4
  import includes from 'lodash/fp/includes';
4
5
  import pull from 'lodash/fp/pull';
5
6
  export const EDIT_QCM = '@@answer/EDIT_QCM';
@@ -37,7 +38,7 @@ const buildAnswer = (userAnswers, questionType, newValue) => {
37
38
  export const editAnswer = (answer) => (dispatch, getState) => {
38
39
  const state = getState();
39
40
  const currentSlideRef = get(['ui', 'currentSlideRef'], state);
40
- const userAnswers = get(['ui', 'answers'], state);
41
+ const userAnswers = getOr([], ['ui', 'answers', currentSlideRef], state);
41
42
  const slide = get(['data', 'slides', currentSlideRef], state);
42
43
  if (!slide)
43
44
  throw new Error('No slide was found');
@@ -47,6 +48,7 @@ export const editAnswer = (answer) => (dispatch, getState) => {
47
48
  throw new Error(`Question type ${questionType} is not supported`);
48
49
  return dispatch({
49
50
  type,
51
+ meta: { slideRef: currentSlideRef },
50
52
  payload: buildAnswer(userAnswers, questionType, answer)
51
53
  });
52
54
  };
@@ -16,7 +16,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
16
16
  ui: import("redux").CombinedState<{
17
17
  currentSlideRef: string;
18
18
  navigation: import("./ui/navigation").NavigationState;
19
- answers: import("./ui/answers").AnswerState;
19
+ answers: import("./ui/answers").UIAnswerState;
20
20
  slide: import("./ui/slide").UISlideState;
21
21
  }>;
22
22
  }>, import("./data/corrections").CorrectionsAction | import("../actions/ui/slides").SetCurrentSlide | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("../actions/api/post-progression").ReceivedProgression | 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 | import("../actions/ui/answers").EditAnswerAction>;
@@ -1,4 +1,6 @@
1
1
  import { EditAnswerAction } from '../../actions/ui/answers';
2
- export declare type AnswerState = string[];
3
- declare const reducer: (state: AnswerState | undefined, action: EditAnswerAction) => AnswerState;
2
+ export declare type UISlideAnswer = string[];
3
+ export declare type UIAnswerState = Record<string, UISlideAnswer>;
4
+ export declare const initialState: UIAnswerState;
5
+ declare const reducer: (state: UIAnswerState | undefined, action: EditAnswerAction) => UIAnswerState;
4
6
  export default reducer;
@@ -1,9 +1,12 @@
1
- import { includes, values } from 'lodash/fp';
1
+ import { includes, set, values } from 'lodash/fp';
2
2
  import { ANSWER_EDIT } from '../../actions/ui/answers';
3
3
  const ANSWER_EDIT_ACTIONS = values(ANSWER_EDIT);
4
+ export const initialState = {};
4
5
  const reducer = (
5
6
  // eslint-disable-next-line default-param-last
6
- state = [], action) => {
7
- return includes(action.type, ANSWER_EDIT_ACTIONS) ? action.payload : state;
7
+ state = initialState, action) => {
8
+ return includes(action.type, ANSWER_EDIT_ACTIONS)
9
+ ? set(action.meta.slideRef, action.payload, initialState)
10
+ : state;
8
11
  };
9
12
  export default reducer;
@@ -1,17 +1,17 @@
1
1
  import { CurrentSlideRefState } from './current-slide-ref';
2
2
  import { NavigationState } from './navigation';
3
- import { AnswerState } from './answers';
3
+ import { UIAnswerState } from './answers';
4
4
  import { UISlideState } from './slide';
5
5
  export declare type UIState = {
6
6
  currentSlideRef: CurrentSlideRefState;
7
7
  navigation: NavigationState;
8
- answers: AnswerState;
8
+ answers: UIAnswerState;
9
9
  slide: UISlideState;
10
10
  };
11
11
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
12
  currentSlideRef: string;
13
13
  navigation: NavigationState;
14
- answers: AnswerState;
14
+ answers: UIAnswerState;
15
15
  slide: UISlideState;
16
- }>, import("../../actions/api/fetch-correction").ReceivedCorrection | import("../../actions/ui/slides").SetCurrentSlide | import("../../actions/api/post-answer").PostAnswerRequestAction | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack | import("../../actions/ui/answers").EditAnswerAction>;
16
+ }>, import("../../actions/api/fetch-correction").ReceivedCorrection | import("../../actions/ui/slides").SetCurrentSlide | import("../../actions/api/fetch-slide").FetchSlide | import("../../actions/api/post-answer").PostAnswerRequestAction | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack | import("../../actions/ui/answers").EditAnswerAction>;
17
17
  export default _default;
@@ -1,11 +1,13 @@
1
1
  import { EditAnswerAction } from '../../actions/ui/answers';
2
2
  import { PostAnswerRequestAction } from '../../actions/api/post-answer';
3
3
  import { ReceivedCorrection } from '../../actions/api/fetch-correction';
4
- export declare type UISlideState = {
4
+ import { FetchSlide } from '../../actions/api/fetch-slide';
5
+ export declare type UISlide = {
5
6
  validateButton: boolean;
6
- animateCorrectionPopin?: boolean;
7
- showCorrectionPopin?: boolean;
7
+ animateCorrectionPopin: boolean;
8
+ showCorrectionPopin: boolean;
8
9
  };
10
+ export declare type UISlideState = Record<string, UISlide>;
9
11
  export declare const initialState: UISlideState;
10
- declare const reducer: (state: UISlideState | undefined, action: PostAnswerRequestAction | EditAnswerAction | ReceivedCorrection) => UISlideState;
12
+ declare const reducer: (state: UISlideState | undefined, action: FetchSlide | PostAnswerRequestAction | EditAnswerAction | ReceivedCorrection) => UISlideState;
11
13
  export default reducer;
@@ -5,24 +5,32 @@ import set from 'lodash/fp/set';
5
5
  import { EDIT_BASIC, EDIT_QCM, EDIT_QCM_DRAG, EDIT_QCM_GRAPHIC, EDIT_SLIDER, EDIT_TEMPLATE } from '../../actions/ui/answers';
6
6
  import { POST_ANSWER_REQUEST } from '../../actions/api/post-answer';
7
7
  import { CORRECTION_FETCH_SUCCESS } from '../../actions/api/fetch-correction';
8
- export const initialState = { validateButton: false };
8
+ import { SLIDE_FETCH_REQUEST } from '../../actions/api/fetch-slide';
9
+ export const initialState = {};
9
10
  const reducer = (
10
11
  // eslint-disable-next-line default-param-last
11
12
  state = initialState, action) => {
12
13
  switch (action.type) {
14
+ case SLIDE_FETCH_REQUEST: {
15
+ return set([action.meta.slideRef], {
16
+ validateButton: false,
17
+ animateCorrectionPopin: false,
18
+ showCorrectionPopin: false
19
+ }, state);
20
+ }
13
21
  case EDIT_QCM:
14
22
  case EDIT_QCM_GRAPHIC:
15
23
  case EDIT_QCM_DRAG:
16
24
  case EDIT_TEMPLATE:
17
25
  case EDIT_BASIC:
18
26
  case EDIT_SLIDER: {
19
- return pipe(compact, isEmpty)(action.payload) ? initialState : { validateButton: true };
27
+ return set([action.meta.slideRef, 'validateButton'], !pipe(compact, isEmpty)(action.payload), state);
20
28
  }
21
29
  case POST_ANSWER_REQUEST: {
22
- return initialState;
30
+ return set([action.meta.slideRef, 'validateButton'], false, state);
23
31
  }
24
32
  case CORRECTION_FETCH_SUCCESS: {
25
- return pipe(set(['animateCorrectionPopin'], true), set(['showCorrectionPopin'], true))(state);
33
+ return pipe(set([action.meta.slideRef, 'animateCorrectionPopin'], true), set([action.meta.slideRef, 'showCorrectionPopin'], true))(state);
26
34
  }
27
35
  default:
28
36
  return state;
@@ -64,13 +64,13 @@ const buildStackSlides = (state, dispatch) => {
64
64
  const slideFromAPI = get(slideRef, state.data.slides);
65
65
  if (!slideFromAPI)
66
66
  return set(index, uiSlide, acc);
67
- const answers = state.ui.answers;
67
+ const answers = getOr([], ['ui', 'answers', slideRef], state);
68
68
  const { questionText, answerUI } = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
69
69
  const parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
70
70
  const parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
71
71
  const isCurrentSlideRef = currentSlideRef === slideRef;
72
- const animateCorrectionPopin = isCurrentSlideRef && getOr(false, ['ui', 'slide', 'animateCorrectionPopin'], state);
73
- const showCorrectionPopin = isCurrentSlideRef && getOr(false, ['ui', 'slide', 'showCorrectionPopin'], state);
72
+ const animateCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'animateCorrectionPopin'], state);
73
+ const showCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'showCorrectionPopin'], state);
74
74
  const updatedUiSlide = pipe(set('showCorrectionPopin', showCorrectionPopin), set('animateCorrectionPopin', animateCorrectionPopin), set('loading', false), set('questionText', questionText), set('answerUI', answerUI), set('parentContentTitle', `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
75
75
  // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
76
76
  )(uiSlide);
@@ -184,7 +184,7 @@ export const mapStateToSlidesProps = (state, dispatch) => {
184
184
  slides: buildStackSlides(state, dispatch),
185
185
  validateButton: {
186
186
  label: '__validate',
187
- disabled: !get('ui.slide.validateButton', state),
187
+ disabled: !get(['ui', 'slide', currentSlideRef, 'validateButton'], state),
188
188
  onClick: /* istanbul ignore next */ () => {
189
189
  dispatch(postAnswer);
190
190
  }
@@ -9,7 +9,7 @@ export var fetchCorrection = function (dispatch, getState, _a) {
9
9
  var slideRef = get(['ui', 'currentSlideRef'], state);
10
10
  var token = get(['data', 'token'], state);
11
11
  var progressionId = get(['data', 'progression', '_id'], state);
12
- var answer = get(['ui', 'answers'], state);
12
+ var answer = get(['ui', 'answers', slideRef], state);
13
13
  var action = buildTask({
14
14
  types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
15
15
  meta: { slideRef: slideRef },
@@ -6,9 +6,15 @@ export declare const POST_ANSWER_SUCCESS: "@@answer/POST_SUCCESS";
6
6
  export declare const POST_ANSWER_FAILURE: "@@answer/POST_FAILURE";
7
7
  export declare type PostAnswerRequestAction = {
8
8
  type: typeof POST_ANSWER_REQUEST;
9
+ meta: {
10
+ slideRef: string;
11
+ };
9
12
  };
10
13
  export declare type PostAnswerSuccessAction = {
11
14
  type: typeof POST_ANSWER_SUCCESS;
15
+ meta: {
16
+ slideRef: string;
17
+ };
12
18
  payload: ProgressionFromAPI;
13
19
  };
14
20
  export declare const postAnswer: (dispatch: Dispatch, getState: () => StoreState, { services }: Options) => Promise<void>;
@@ -45,18 +45,20 @@ export var POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
45
45
  export var postAnswer = function (dispatch, getState, _a) {
46
46
  var services = _a.services;
47
47
  return __awaiter(void 0, void 0, void 0, function () {
48
- var state, token, answer, progression, action, response, updatedProgression, slideRef;
48
+ var state, currentSlideRef, token, answer, progression, action, response, updatedProgression, slideRef;
49
49
  return __generator(this, function (_b) {
50
50
  switch (_b.label) {
51
51
  case 0:
52
52
  state = getState();
53
+ currentSlideRef = get(['ui', 'currentSlideRef'], state);
53
54
  token = get(['data', 'token'], state);
54
- answer = get(['ui', 'answers'], state);
55
+ answer = get(['ui', 'answers', currentSlideRef], state);
55
56
  progression = get(['data', 'progression'], state);
56
57
  if (!progression)
57
58
  throw new Error('Cannot answer a question of an inexistent progression');
58
59
  action = buildTask({
59
60
  types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
61
+ meta: { slideRef: currentSlideRef },
60
62
  task: function () { return services.postAnswer(progression, token, answer); }
61
63
  });
62
64
  return [4 /*yield*/, dispatch(action)];
@@ -16,6 +16,9 @@ export declare const ANSWER_EDIT: {
16
16
  };
17
17
  export declare type EditAnswerAction = {
18
18
  type: typeof EDIT_QCM | typeof EDIT_QCM_GRAPHIC | typeof EDIT_QCM_DRAG | typeof EDIT_TEMPLATE | typeof EDIT_BASIC | typeof EDIT_SLIDER;
19
+ meta: {
20
+ slideRef: string;
21
+ };
19
22
  payload: string[];
20
23
  };
21
24
  export declare const editAnswer: (answer: string[]) => (dispatch: Dispatch, getState: () => StoreState) => EditAnswerAction;
@@ -9,6 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
9
  };
10
10
  import flatten from 'lodash/fp/flatten';
11
11
  import get from 'lodash/fp/get';
12
+ import getOr from 'lodash/fp/getOr';
12
13
  import includes from 'lodash/fp/includes';
13
14
  import pull from 'lodash/fp/pull';
14
15
  export var EDIT_QCM = '@@answer/EDIT_QCM';
@@ -47,7 +48,7 @@ export var editAnswer = function (answer) {
47
48
  return function (dispatch, getState) {
48
49
  var state = getState();
49
50
  var currentSlideRef = get(['ui', 'currentSlideRef'], state);
50
- var userAnswers = get(['ui', 'answers'], state);
51
+ var userAnswers = getOr([], ['ui', 'answers', currentSlideRef], state);
51
52
  var slide = get(['data', 'slides', currentSlideRef], state);
52
53
  if (!slide)
53
54
  throw new Error('No slide was found');
@@ -57,6 +58,7 @@ export var editAnswer = function (answer) {
57
58
  throw new Error("Question type ".concat(questionType, " is not supported"));
58
59
  return dispatch({
59
60
  type: type,
61
+ meta: { slideRef: currentSlideRef },
60
62
  payload: buildAnswer(userAnswers, questionType, answer)
61
63
  });
62
64
  };
@@ -16,7 +16,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
16
16
  ui: import("redux").CombinedState<{
17
17
  currentSlideRef: string;
18
18
  navigation: import("./ui/navigation").NavigationState;
19
- answers: import("./ui/answers").AnswerState;
19
+ answers: import("./ui/answers").UIAnswerState;
20
20
  slide: import("./ui/slide").UISlideState;
21
21
  }>;
22
22
  }>, import("./data/corrections").CorrectionsAction | import("../actions/ui/slides").SetCurrentSlide | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("../actions/api/post-progression").ReceivedProgression | 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 | import("../actions/ui/answers").EditAnswerAction>;
@@ -1,4 +1,6 @@
1
1
  import { EditAnswerAction } from '../../actions/ui/answers';
2
- export declare type AnswerState = string[];
3
- declare const reducer: (state: AnswerState | undefined, action: EditAnswerAction) => AnswerState;
2
+ export declare type UISlideAnswer = string[];
3
+ export declare type UIAnswerState = Record<string, UISlideAnswer>;
4
+ export declare const initialState: UIAnswerState;
5
+ declare const reducer: (state: UIAnswerState | undefined, action: EditAnswerAction) => UIAnswerState;
4
6
  export default reducer;
@@ -1,10 +1,13 @@
1
- import { includes, values } from 'lodash/fp';
1
+ import { includes, set, values } from 'lodash/fp';
2
2
  import { ANSWER_EDIT } from '../../actions/ui/answers';
3
3
  var ANSWER_EDIT_ACTIONS = values(ANSWER_EDIT);
4
+ export var initialState = {};
4
5
  var reducer = function (
5
6
  // eslint-disable-next-line default-param-last
6
7
  state, action) {
7
- if (state === void 0) { state = []; }
8
- return includes(action.type, ANSWER_EDIT_ACTIONS) ? action.payload : state;
8
+ if (state === void 0) { state = initialState; }
9
+ return includes(action.type, ANSWER_EDIT_ACTIONS)
10
+ ? set(action.meta.slideRef, action.payload, initialState)
11
+ : state;
9
12
  };
10
13
  export default reducer;
@@ -1,17 +1,17 @@
1
1
  import { CurrentSlideRefState } from './current-slide-ref';
2
2
  import { NavigationState } from './navigation';
3
- import { AnswerState } from './answers';
3
+ import { UIAnswerState } from './answers';
4
4
  import { UISlideState } from './slide';
5
5
  export declare type UIState = {
6
6
  currentSlideRef: CurrentSlideRefState;
7
7
  navigation: NavigationState;
8
- answers: AnswerState;
8
+ answers: UIAnswerState;
9
9
  slide: UISlideState;
10
10
  };
11
11
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
12
  currentSlideRef: string;
13
13
  navigation: NavigationState;
14
- answers: AnswerState;
14
+ answers: UIAnswerState;
15
15
  slide: UISlideState;
16
- }>, import("../../actions/api/fetch-correction").ReceivedCorrection | import("../../actions/ui/slides").SetCurrentSlide | import("../../actions/api/post-answer").PostAnswerRequestAction | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack | import("../../actions/ui/answers").EditAnswerAction>;
16
+ }>, import("../../actions/api/fetch-correction").ReceivedCorrection | import("../../actions/ui/slides").SetCurrentSlide | import("../../actions/api/fetch-slide").FetchSlide | import("../../actions/api/post-answer").PostAnswerRequestAction | import("../../actions/ui/navigation").NavigateTo | import("../../actions/ui/navigation").NavigateBack | import("../../actions/ui/answers").EditAnswerAction>;
17
17
  export default _default;
@@ -1,11 +1,13 @@
1
1
  import { EditAnswerAction } from '../../actions/ui/answers';
2
2
  import { PostAnswerRequestAction } from '../../actions/api/post-answer';
3
3
  import { ReceivedCorrection } from '../../actions/api/fetch-correction';
4
- export declare type UISlideState = {
4
+ import { FetchSlide } from '../../actions/api/fetch-slide';
5
+ export declare type UISlide = {
5
6
  validateButton: boolean;
6
- animateCorrectionPopin?: boolean;
7
- showCorrectionPopin?: boolean;
7
+ animateCorrectionPopin: boolean;
8
+ showCorrectionPopin: boolean;
8
9
  };
10
+ export declare type UISlideState = Record<string, UISlide>;
9
11
  export declare const initialState: UISlideState;
10
- declare const reducer: (state: UISlideState | undefined, action: PostAnswerRequestAction | EditAnswerAction | ReceivedCorrection) => UISlideState;
12
+ declare const reducer: (state: UISlideState | undefined, action: FetchSlide | PostAnswerRequestAction | EditAnswerAction | ReceivedCorrection) => UISlideState;
11
13
  export default reducer;
@@ -5,25 +5,33 @@ import set from 'lodash/fp/set';
5
5
  import { EDIT_BASIC, EDIT_QCM, EDIT_QCM_DRAG, EDIT_QCM_GRAPHIC, EDIT_SLIDER, EDIT_TEMPLATE } from '../../actions/ui/answers';
6
6
  import { POST_ANSWER_REQUEST } from '../../actions/api/post-answer';
7
7
  import { CORRECTION_FETCH_SUCCESS } from '../../actions/api/fetch-correction';
8
- export var initialState = { validateButton: false };
8
+ import { SLIDE_FETCH_REQUEST } from '../../actions/api/fetch-slide';
9
+ export var initialState = {};
9
10
  var reducer = function (
10
11
  // eslint-disable-next-line default-param-last
11
12
  state, action) {
12
13
  if (state === void 0) { state = initialState; }
13
14
  switch (action.type) {
15
+ case SLIDE_FETCH_REQUEST: {
16
+ return set([action.meta.slideRef], {
17
+ validateButton: false,
18
+ animateCorrectionPopin: false,
19
+ showCorrectionPopin: false
20
+ }, state);
21
+ }
14
22
  case EDIT_QCM:
15
23
  case EDIT_QCM_GRAPHIC:
16
24
  case EDIT_QCM_DRAG:
17
25
  case EDIT_TEMPLATE:
18
26
  case EDIT_BASIC:
19
27
  case EDIT_SLIDER: {
20
- return pipe(compact, isEmpty)(action.payload) ? initialState : { validateButton: true };
28
+ return set([action.meta.slideRef, 'validateButton'], !pipe(compact, isEmpty)(action.payload), state);
21
29
  }
22
30
  case POST_ANSWER_REQUEST: {
23
- return initialState;
31
+ return set([action.meta.slideRef, 'validateButton'], false, state);
24
32
  }
25
33
  case CORRECTION_FETCH_SUCCESS: {
26
- return pipe(set(['animateCorrectionPopin'], true), set(['showCorrectionPopin'], true))(state);
34
+ return pipe(set([action.meta.slideRef, 'animateCorrectionPopin'], true), set([action.meta.slideRef, 'showCorrectionPopin'], true))(state);
27
35
  }
28
36
  default:
29
37
  return state;
@@ -75,13 +75,13 @@ var buildStackSlides = function (state, dispatch) {
75
75
  var slideFromAPI = get(slideRef, state.data.slides);
76
76
  if (!slideFromAPI)
77
77
  return set(index, uiSlide, acc);
78
- var answers = state.ui.answers;
78
+ var answers = getOr([], ['ui', 'answers', slideRef], state);
79
79
  var _a = mapApiSlideToUi(dispatch)(slideFromAPI, answers), questionText = _a.questionText, answerUI = _a.answerUI;
80
80
  var parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
81
81
  var parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
82
82
  var isCurrentSlideRef = currentSlideRef === slideRef;
83
- var animateCorrectionPopin = isCurrentSlideRef && getOr(false, ['ui', 'slide', 'animateCorrectionPopin'], state);
84
- var showCorrectionPopin = isCurrentSlideRef && getOr(false, ['ui', 'slide', 'showCorrectionPopin'], state);
83
+ var animateCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'animateCorrectionPopin'], state);
84
+ var showCorrectionPopin = isCurrentSlideRef && get(['ui', 'slide', slideRef, 'showCorrectionPopin'], state);
85
85
  var updatedUiSlide = pipe(set('showCorrectionPopin', showCorrectionPopin), set('animateCorrectionPopin', animateCorrectionPopin), set('loading', false), set('questionText', questionText), set('answerUI', answerUI), set('parentContentTitle', "From \"".concat(parentContentTitle, "\" ").concat(parentContentType)) // TODO translate: -From- .... -Course/chapter-
86
86
  // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
87
87
  )(uiSlide);
@@ -188,7 +188,7 @@ export var mapStateToSlidesProps = function (state, dispatch) {
188
188
  slides: buildStackSlides(state, dispatch),
189
189
  validateButton: {
190
190
  label: '__validate',
191
- disabled: !get('ui.slide.validateButton', state),
191
+ disabled: !get(['ui', 'slide', currentSlideRef, 'validateButton'], state),
192
192
  onClick: /* istanbul ignore next */ function () {
193
193
  dispatch(postAnswer);
194
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.2.12",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -78,5 +78,5 @@
78
78
  "ts-node": "^10.9.1",
79
79
  "typescript": "^4.7.4"
80
80
  },
81
- "gitHead": "88cfaeaa957c9e0b85a6eada4b1155a147eab302"
81
+ "gitHead": "b516f7af0b9b76910d5c4589ce0d6fee90966c36"
82
82
  }
@@ -28,7 +28,7 @@ export const fetchCorrection = (
28
28
  const slideRef = get(['ui', 'currentSlideRef'], state);
29
29
  const token = get(['data', 'token'], state);
30
30
  const progressionId = get(['data', 'progression', '_id'], state);
31
- const answer = get(['ui', 'answers'], state);
31
+ const answer = get(['ui', 'answers', slideRef], state);
32
32
 
33
33
  const action = buildTask({
34
34
  types: [CORRECTION_FETCH_REQUEST, CORRECTION_FETCH_SUCCESS, CORRECTION_FETCH_FAILURE],
@@ -13,10 +13,12 @@ export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE' as const;
13
13
 
14
14
  export type PostAnswerRequestAction = {
15
15
  type: typeof POST_ANSWER_REQUEST;
16
+ meta: {slideRef: string};
16
17
  };
17
18
 
18
19
  export type PostAnswerSuccessAction = {
19
20
  type: typeof POST_ANSWER_SUCCESS;
21
+ meta: {slideRef: string};
20
22
  payload: ProgressionFromAPI;
21
23
  };
22
24
 
@@ -26,13 +28,15 @@ export const postAnswer = async (
26
28
  {services}: Options
27
29
  ): Promise<void> => {
28
30
  const state = getState();
31
+ const currentSlideRef = get(['ui', 'currentSlideRef'], state);
29
32
  const token = get(['data', 'token'], state);
30
- const answer = get(['ui', 'answers'], state);
33
+ const answer = get(['ui', 'answers', currentSlideRef], state);
31
34
  const progression = get(['data', 'progression'], state);
32
35
  if (!progression) throw new Error('Cannot answer a question of an inexistent progression');
33
36
 
34
37
  const action = buildTask({
35
38
  types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
39
+ meta: {slideRef: currentSlideRef},
36
40
  task: () => services.postAnswer(progression, token, answer)
37
41
  });
38
42
  const response = await dispatch(action);
@@ -35,9 +35,13 @@ const initialState: StoreState = {
35
35
  ui: {
36
36
  currentSlideRef: freeTextSlide._id,
37
37
  navigation: ['skills', 'slides'],
38
- answers: answer,
38
+ answers: {[freeTextSlide.universalRef]: answer},
39
39
  slide: {
40
- validateButton: false
40
+ [freeTextSlide.universalRef]: {
41
+ validateButton: false,
42
+ animateCorrectionPopin: false,
43
+ showCorrectionPopin: false
44
+ }
41
45
  }
42
46
  }
43
47
  };
@@ -26,10 +26,8 @@ const initialState: StoreState = {
26
26
  ui: {
27
27
  currentSlideRef: '',
28
28
  navigation: [],
29
- answers: [],
30
- slide: {
31
- validateButton: false
32
- }
29
+ answers: {},
30
+ slide: {}
33
31
  }
34
32
  };
35
33
 
@@ -22,10 +22,8 @@ const initialState: StoreState = {
22
22
  ui: {
23
23
  currentSlideRef: '',
24
24
  navigation: [],
25
- answers: [],
26
- slide: {
27
- validateButton: false
28
- }
25
+ answers: {},
26
+ slide: {}
29
27
  }
30
28
  };
31
29
 
@@ -24,10 +24,8 @@ const initialState: StoreState = {
24
24
  ui: {
25
25
  currentSlideRef: '',
26
26
  navigation: [],
27
- answers: [],
28
- slide: {
29
- validateButton: false
30
- }
27
+ answers: {},
28
+ slide: {}
31
29
  }
32
30
  };
33
31