@coorpacademy/app-review 0.1.16 → 0.1.18

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 (196) hide show
  1. package/es/actions/api/fetch-skills.d.ts +3 -3
  2. package/es/actions/api/fetch-skills.js +7 -2
  3. package/es/actions/api/fetch-slide.d.ts +1 -1
  4. package/es/actions/api/fetch-slide.js +3 -1
  5. package/es/actions/api/post-answer.d.ts +14 -0
  6. package/es/actions/api/post-answer.js +25 -0
  7. package/es/actions/api/post-progression.d.ts +3 -3
  8. package/es/actions/api/post-progression.js +5 -2
  9. package/es/actions/api/test/fetch-skills.test.js +7 -4
  10. package/es/actions/api/test/fetch-slide.test.js +7 -4
  11. package/es/actions/api/test/post-answer.test.d.ts +1 -0
  12. package/es/actions/api/test/post-answer.test.js +82 -0
  13. package/es/actions/api/test/post-progression.test.js +7 -4
  14. package/es/actions/data/test/token.test.d.ts +1 -0
  15. package/es/actions/data/test/token.test.js +25 -0
  16. package/es/actions/index.d.ts +1 -8
  17. package/es/actions/{api/test → test}/create-test-store.d.ts +2 -2
  18. package/es/actions/{api/test → test}/create-test-store.js +1 -1
  19. package/es/actions/ui/answers.d.ts +17 -3
  20. package/es/actions/ui/answers.js +41 -3
  21. package/es/actions/ui/slides.d.ts +0 -5
  22. package/es/actions/ui/slides.js +0 -4
  23. package/es/actions/ui/test/answers.test.d.ts +1 -0
  24. package/es/actions/ui/test/answers.test.js +100 -0
  25. package/es/actions/ui/test/slides.test.d.ts +1 -0
  26. package/es/actions/ui/test/slides.test.js +26 -0
  27. package/es/common/index.d.ts +0 -3
  28. package/es/common/index.js +0 -4
  29. package/es/index.js +1 -3
  30. package/es/reducers/data/index.d.ts +1 -1
  31. package/es/reducers/data/progression.d.ts +3 -3
  32. package/es/reducers/data/progression.js +2 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +12 -27
  35. package/es/reducers/index.d.ts +2 -1
  36. package/es/reducers/ui/answers.d.ts +2 -2
  37. package/es/reducers/ui/answers.js +4 -8
  38. package/es/reducers/ui/index.d.ts +4 -1
  39. package/es/reducers/ui/index.js +3 -1
  40. package/es/reducers/ui/slide.d.ts +8 -0
  41. package/es/reducers/ui/slide.js +26 -0
  42. package/es/reducers/ui/test/answers.test.js +23 -3
  43. package/es/reducers/ui/test/current-slide-ref.test.js +1 -1
  44. package/es/reducers/ui/test/navigation.test.js +5 -5
  45. package/es/reducers/ui/test/slide.test.d.ts +1 -0
  46. package/es/reducers/ui/test/slide.test.js +12 -0
  47. package/es/test/util/services.mock.d.ts +3 -1
  48. package/es/test/util/services.mock.js +89 -72
  49. package/es/types/common.d.ts +0 -25
  50. package/es/views/skills/index.d.ts +1 -1
  51. package/es/views/skills/index.js +0 -3
  52. package/es/views/skills/test/skills.test.d.ts +1 -0
  53. package/es/views/skills/test/skills.test.js +94 -0
  54. package/es/views/slides/index.d.ts +13 -2
  55. package/es/views/slides/index.js +19 -15
  56. package/es/views/slides/map-api-slide-to-ui.js +65 -68
  57. package/es/views/slides/test/fixtures/free-text.d.ts +2 -1
  58. package/es/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  60. package/es/views/slides/test/fixtures/qcm.d.ts +2 -1
  61. package/es/views/slides/test/fixtures/slider.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/template.d.ts +4 -0
  63. package/{lib/views/slides/test/fixtures/select-template.js → es/views/slides/test/fixtures/template.js} +82 -4
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +473 -0
  66. package/es/views/slides/test/map-api-slide-to-ui.test.js +4 -10
  67. package/es/views/slides/test/slide.template.on-change.test.d.ts +1 -0
  68. package/es/views/slides/test/slide.template.on-change.test.js +79 -0
  69. package/lib/actions/api/fetch-skills.d.ts +3 -3
  70. package/lib/actions/api/fetch-skills.js +22 -19
  71. package/lib/actions/api/fetch-slide.d.ts +1 -1
  72. package/lib/actions/api/fetch-slide.js +3 -1
  73. package/lib/actions/api/post-answer.d.ts +14 -0
  74. package/lib/actions/api/post-answer.js +75 -0
  75. package/lib/actions/api/post-progression.d.ts +3 -3
  76. package/lib/actions/api/post-progression.js +6 -3
  77. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  78. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  79. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  80. package/lib/actions/api/test/post-answer.test.js +145 -0
  81. package/lib/actions/api/test/post-progression.test.js +7 -4
  82. package/lib/actions/data/test/token.test.d.ts +1 -0
  83. package/lib/actions/data/test/token.test.js +70 -0
  84. package/lib/actions/index.d.ts +1 -8
  85. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  86. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  87. package/lib/actions/ui/answers.d.ts +17 -3
  88. package/lib/actions/ui/answers.js +50 -3
  89. package/lib/actions/ui/slides.d.ts +0 -5
  90. package/lib/actions/ui/slides.js +0 -4
  91. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  92. package/lib/actions/ui/test/answers.test.js +190 -0
  93. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  94. package/lib/actions/ui/test/slides.test.js +71 -0
  95. package/lib/common/index.d.ts +0 -3
  96. package/lib/common/index.js +0 -4
  97. package/lib/index.js +1 -3
  98. package/lib/reducers/data/index.d.ts +1 -1
  99. package/lib/reducers/data/progression.d.ts +3 -3
  100. package/lib/reducers/data/progression.js +2 -5
  101. package/lib/reducers/data/slides.d.ts +2 -3
  102. package/lib/reducers/data/test/progression.test.js +12 -27
  103. package/lib/reducers/index.d.ts +2 -1
  104. package/lib/reducers/ui/answers.d.ts +2 -2
  105. package/lib/reducers/ui/answers.js +4 -8
  106. package/lib/reducers/ui/index.d.ts +4 -1
  107. package/lib/reducers/ui/index.js +3 -1
  108. package/lib/reducers/ui/slide.d.ts +8 -0
  109. package/lib/reducers/ui/slide.js +27 -0
  110. package/lib/reducers/ui/test/answers.test.js +23 -3
  111. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  112. package/lib/reducers/ui/test/navigation.test.js +5 -5
  113. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  114. package/lib/reducers/ui/test/slide.test.js +12 -0
  115. package/lib/test/util/services.mock.d.ts +3 -1
  116. package/lib/test/util/services.mock.js +89 -72
  117. package/lib/types/common.d.ts +0 -25
  118. package/lib/views/skills/index.d.ts +1 -1
  119. package/lib/views/skills/index.js +0 -3
  120. package/lib/views/skills/test/skills.test.d.ts +1 -0
  121. package/lib/views/skills/test/skills.test.js +94 -0
  122. package/lib/views/slides/index.d.ts +13 -2
  123. package/lib/views/slides/index.js +19 -15
  124. package/lib/views/slides/map-api-slide-to-ui.js +106 -99
  125. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  129. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  130. package/lib/views/slides/test/fixtures/template.d.ts +4 -0
  131. package/{es/views/slides/test/fixtures/select-template.js → lib/views/slides/test/fixtures/template.js} +82 -4
  132. package/lib/views/slides/test/index.test.d.ts +1 -0
  133. package/lib/views/slides/test/index.test.js +473 -0
  134. package/lib/views/slides/test/map-api-slide-to-ui.test.js +4 -10
  135. package/lib/views/slides/test/slide.template.on-change.test.d.ts +1 -0
  136. package/lib/views/slides/test/slide.template.on-change.test.js +82 -0
  137. package/package.json +6 -5
  138. package/src/actions/api/fetch-skills.ts +18 -11
  139. package/src/actions/api/fetch-slide.ts +3 -1
  140. package/src/actions/api/post-answer.ts +44 -0
  141. package/src/actions/api/post-progression.ts +7 -4
  142. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  143. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  144. package/src/actions/api/test/post-answer.test.ts +101 -0
  145. package/src/actions/api/test/post-progression.test.ts +9 -6
  146. package/src/actions/data/test/token.test.ts +29 -0
  147. package/src/actions/index.ts +1 -17
  148. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  149. package/src/actions/ui/answers.ts +55 -6
  150. package/src/actions/ui/slides.ts +1 -8
  151. package/src/actions/ui/test/answers.test.ts +115 -0
  152. package/src/actions/ui/test/slides.test.ts +30 -0
  153. package/src/common/index.ts +0 -7
  154. package/src/index.tsx +1 -3
  155. package/src/reducers/data/progression.ts +4 -7
  156. package/src/reducers/data/slides.ts +2 -3
  157. package/src/reducers/data/test/progression.test.ts +15 -31
  158. package/src/reducers/ui/answers.ts +5 -9
  159. package/src/reducers/ui/index.ts +4 -1
  160. package/src/reducers/ui/slide.ts +43 -0
  161. package/src/reducers/ui/test/answers.test.ts +29 -4
  162. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  163. package/src/reducers/ui/test/navigation.test.ts +5 -5
  164. package/src/reducers/ui/test/slide.test.ts +15 -0
  165. package/src/test/util/services.mock.ts +94 -73
  166. package/src/types/common.ts +0 -30
  167. package/src/views/skills/index.ts +1 -5
  168. package/src/views/skills/test/skills.test.ts +101 -0
  169. package/src/views/slides/index.ts +38 -23
  170. package/src/views/slides/map-api-slide-to-ui.ts +146 -113
  171. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  172. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  173. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  174. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  175. package/src/views/slides/test/fixtures/slider.ts +2 -1
  176. package/src/views/slides/test/fixtures/{select-template.ts → template.ts} +84 -5
  177. package/src/views/slides/test/index.test.ts +493 -0
  178. package/src/views/slides/test/map-api-slide-to-ui.test.ts +6 -11
  179. package/src/views/slides/test/slide.template.on-change.test.ts +92 -0
  180. package/es/fixtures/qcm-slide.d.ts +0 -2
  181. package/es/fixtures/qcm-slide.js +0 -33
  182. package/es/fixtures/temp-fixture.d.ts +0 -3
  183. package/es/fixtures/temp-fixture.js +0 -84
  184. package/es/views/slides/test/fixtures/select-template.d.ts +0 -3
  185. package/es/views/slides/test/fixtures/text-template.d.ts +0 -3
  186. package/es/views/slides/test/fixtures/text-template.js +0 -58
  187. package/lib/fixtures/qcm-slide.d.ts +0 -2
  188. package/lib/fixtures/qcm-slide.js +0 -33
  189. package/lib/fixtures/temp-fixture.d.ts +0 -3
  190. package/lib/fixtures/temp-fixture.js +0 -84
  191. package/lib/views/slides/test/fixtures/select-template.d.ts +0 -3
  192. package/lib/views/slides/test/fixtures/text-template.d.ts +0 -3
  193. package/lib/views/slides/test/fixtures/text-template.js +0 -58
  194. package/src/fixtures/qcm-slide.ts +0 -35
  195. package/src/fixtures/temp-fixture.ts +0 -94
  196. package/src/views/slides/test/fixtures/text-template.ts +0 -61
@@ -9,9 +9,11 @@ import set from 'lodash/fp/set';
9
9
  import slice from 'lodash/fp/slice';
10
10
  import toInteger from 'lodash/fp/toInteger';
11
11
  import {Dispatch} from 'redux';
12
- import {ProgressionFromAPI, UISlide} from '../../types/common';
12
+ import {ProgressionFromAPI} from '../../types/common';
13
13
  import {SlideIndexes} from '../../common';
14
14
  import {StoreState} from '../../reducers';
15
+ import {AnswerUI} from '../../types/slides';
16
+ import {postAnswer} from '../../actions/api/post-answer';
15
17
  import {mapApiSlideToUi} from './map-api-slide-to-ui';
16
18
 
17
19
  const ICON_VALUES = {
@@ -28,6 +30,19 @@ type StepItem = {
28
30
  value: string;
29
31
  };
30
32
 
33
+ type SlideUIAnimations = 'unstack' | 'restack';
34
+
35
+ export type UISlide = {
36
+ questionText?: string;
37
+ answerUI?: AnswerUI;
38
+ hidden?: boolean;
39
+ position: number;
40
+ animationType?: SlideUIAnimations;
41
+ isCorrect?: boolean;
42
+ endReview?: boolean;
43
+ loading: boolean;
44
+ };
45
+
31
46
  type SlidesStack = {
32
47
  [key in SlideIndexes]: UISlide;
33
48
  };
@@ -95,30 +110,35 @@ export type SlidesViewProps = {
95
110
  export const initialState: SlidesStack = {
96
111
  '0': {
97
112
  hidden: false,
98
- position: 0
113
+ position: 0,
114
+ loading: true
99
115
  },
100
116
  '1': {
101
117
  hidden: false,
102
- position: 1
118
+ position: 1,
119
+ loading: true
103
120
  },
104
121
  '2': {
105
122
  hidden: false,
106
- position: 2
123
+ position: 2,
124
+ loading: true
107
125
  },
108
126
  '3': {
109
127
  hidden: false,
110
- position: 3
128
+ position: 3,
129
+ loading: true
111
130
  },
112
131
  '4': {
113
132
  hidden: false,
114
- position: 4
133
+ position: 4,
134
+ loading: true
115
135
  }
116
136
  };
117
137
 
118
- const getProgressionSlidesRef = (progression: ProgressionFromAPI): string[] => {
138
+ const getProgressionSlidesRefs = (progression: ProgressionFromAPI): string[] => {
119
139
  if (progression.state.step.current < 5) {
120
140
  const slideRef = progression.state.nextContent.ref;
121
- return concat([slideRef], progression.state.slides);
141
+ return concat(progression.state.slides, [slideRef]);
122
142
  }
123
143
  return slice(0, 5, progression.state.slides);
124
144
  };
@@ -128,7 +148,7 @@ const buildStackSlides = (state: StoreState, dispatch: Dispatch): SlidesStack =>
128
148
  const progression = state.data.progression;
129
149
 
130
150
  if (!currentSlideRef || !progression) return initialState;
131
- const slideRefs = getProgressionSlidesRef(progression);
151
+ const slideRefs = getProgressionSlidesRefs(progression);
132
152
 
133
153
  // @ts-expect-error typescript does not support capped versions of lodash functions
134
154
  const stack = reduce.convert({cap: false})(
@@ -137,15 +157,18 @@ const buildStackSlides = (state: StoreState, dispatch: Dispatch): SlidesStack =>
137
157
  if (!slideRef) return set(index, uiSlide, acc);
138
158
 
139
159
  const slideFromAPI = get(slideRef, state.data.slides);
160
+ if (!slideFromAPI) return set(index, uiSlide, acc);
161
+
140
162
  const answers = state.ui.answers;
141
163
  const {questionText, answerUI} = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
142
164
  const parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
143
165
  const parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
144
166
 
145
167
  const updatedUiSlide = pipe(
146
- set(['questionText'], questionText),
147
- set(['answerUI'], answerUI),
148
- set(['parentContentTitle'], `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
168
+ set('loading', false),
169
+ set('questionText', questionText),
170
+ set('answerUI', answerUI),
171
+ set('parentContentTitle', `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
149
172
  // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
150
173
  )(uiSlide);
151
174
 
@@ -213,14 +236,7 @@ const buildStepItems = (state: StoreState): StepItem[] => {
213
236
  return steps;
214
237
  };
215
238
 
216
- export const mapStateToSlidesProps = (
217
- state: StoreState,
218
- dispatch: Dispatch
219
- ): SlidesViewProps | null => {
220
- if (!state.data.slides) {
221
- return null;
222
- }
223
-
239
+ export const mapStateToSlidesProps = (state: StoreState, dispatch: Dispatch): SlidesViewProps => {
224
240
  return {
225
241
  header: {
226
242
  mode: '__revision_mode',
@@ -237,10 +253,9 @@ export const mapStateToSlidesProps = (
237
253
  slides: buildStackSlides(state, dispatch),
238
254
  validateButton: {
239
255
  label: '__validate',
240
- disabled: true,
256
+ disabled: !get('ui.slide.validateButton', state),
241
257
  onClick: (): void => {
242
- // eslint-disable-next-line no-console
243
- console.log('TODO: validate question');
258
+ dispatch(postAnswer);
244
259
  }
245
260
  },
246
261
  correctionPopinProps: undefined,
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  concat,
3
+ constant,
3
4
  divide,
4
5
  get,
5
6
  getOr,
@@ -7,10 +8,18 @@ import {
7
8
  includes,
8
9
  indexOf,
9
10
  isEmpty,
11
+ isNil,
10
12
  map,
13
+ multiply,
14
+ pipe,
11
15
  rangeStep,
16
+ round,
17
+ set,
12
18
  size,
13
- toInteger
19
+ times,
20
+ toInteger,
21
+ toString as _toString,
22
+ __
14
23
  } from 'lodash/fp';
15
24
  import {Dispatch} from 'redux';
16
25
  import {
@@ -37,85 +46,100 @@ import {
37
46
  } from '../../types/common';
38
47
  import {editAnswer} from '../../actions/ui/answers';
39
48
 
40
- const qcmProps = (question: QcmQuestion): Qcm => {
41
- // TODO: EDIT_CHOICES -> getAnswerValues
42
- const answers: string[] = [];
43
-
44
- return {
45
- type: 'qcm',
46
- answers: map(
47
- choice => ({
48
- title: choice.label,
49
- selected: includes(choice.label, answers),
50
- // TODO: EDIT_CHOICES
51
- // eslint-disable-next-line no-console
52
- onClick: () => console.log('TODO: on choice click'),
53
- ariaLabel: choice.label
54
- }),
55
- // TODO: EDIT_CHOICES -> getChoices
56
- question.content.choices
57
- )
49
+ const qcmProps =
50
+ (dispatch: Dispatch) =>
51
+ (answers: string[], question: QcmQuestion): Qcm => {
52
+ return {
53
+ type: 'qcm',
54
+ answers: map(choice => {
55
+ const label = choice.label || '';
56
+ return {
57
+ title: label,
58
+ selected: includes(label, answers),
59
+ onClick: (): void => {
60
+ dispatch(editAnswer([label]));
61
+ },
62
+ ariaLabel: choice.label
63
+ };
64
+ }, question.content.choices)
65
+ };
58
66
  };
59
- };
60
67
 
61
- const qcmDragProps = (question: QcmDragQuestion): QcmDrag => {
62
- // TODO: EDIT_CHOICES -> getAnswerValues
63
- const answers: string[] = [];
64
- return {
65
- type: 'qcmDrag',
66
- answers: map(choice => {
67
- const indexInAnswer = indexOf(choice.label, answers);
68
- return {
69
- title: choice.label,
70
- selected: includes(choice.label, answers),
71
- order: indexInAnswer,
72
- // TODO: EDIT_CHOICES
73
- // eslint-disable-next-line no-console
74
- onClick: () => console.log('TODO: on choice click')
75
- };
76
- // TODO: EDIT_CHOICES -> getChoices
77
- }, question.content.choices)
68
+ const qcmDragProps =
69
+ (dispatch: Dispatch) =>
70
+ (answers: string[], question: QcmDragQuestion): QcmDrag => {
71
+ return {
72
+ type: 'qcmDrag',
73
+ answers: map(choice => {
74
+ const label = choice.label || '';
75
+ const indexInAnswer = indexOf(label, answers);
76
+ return {
77
+ title: label,
78
+ selected: includes(label, answers),
79
+ order: indexInAnswer,
80
+ onClick: (): void => {
81
+ dispatch(editAnswer([label]));
82
+ }
83
+ };
84
+ }, question.content.choices)
85
+ };
78
86
  };
79
- };
80
87
 
81
- const qcmGraphicProps = (question: QcmGraphicQuestion): QcmGraphic => {
82
- // mock the answers
83
- // TODO: EDIT_CHOICES -> getAnswerValues
84
- const answers: string[] = [];
85
- return {
86
- type: 'qcmGraphic',
87
- answers: map(
88
- choice => ({
89
- title: choice.label,
90
- image: get('media.src.0.url', choice),
91
- selected: includes(choice.label, answers),
92
- // TODO: EDIT_CHOICES
93
- // eslint-disable-next-line no-console
94
- onClick: () => console.log('TODO: on choice click')
95
- }),
96
- // TODO: EDIT_CHOICES -> getChoices
97
- question.content.choices
98
- )
88
+ const qcmGraphicProps =
89
+ (dispatch: Dispatch) =>
90
+ (answers: string[], question: QcmGraphicQuestion): QcmGraphic => {
91
+ return {
92
+ type: 'qcmGraphic',
93
+ answers: map(choice => {
94
+ const label = choice.label || '';
95
+ return {
96
+ title: label,
97
+ image: get('media.src.0.url', choice),
98
+ selected: includes(label, answers),
99
+ onClick: (): void => {
100
+ dispatch(editAnswer([label]));
101
+ }
102
+ };
103
+ }, question.content.choices)
104
+ };
99
105
  };
106
+
107
+ const updateTemplateAnswer = (
108
+ text: string,
109
+ _answers: string[],
110
+ index: number,
111
+ max: number
112
+ ): string[] => {
113
+ const answers = isEmpty(_answers) ? times(constant(undefined), max) : _answers;
114
+ return map(a => (isNil(a) ? '' : a), set(index, text, answers)) as string[];
100
115
  };
101
116
 
102
- const templateTextProps = (choice: ChoiceFromAPI, index: number): TextTemplate => {
103
- // TODO: EDIT_CHOICES -> getAnswerValues
104
- const answers: string[] = [];
117
+ const templateTextProps = (
118
+ dispatch: Dispatch,
119
+ answers: string[],
120
+ choice: ChoiceFromAPI,
121
+ index: number,
122
+ maxLength: number
123
+ ): TextTemplate => {
105
124
  return {
106
125
  type: 'text',
107
- name: getOr('', 'name', choice), // TODO prendre valeur depuis les données de l'api
126
+ name: getOr('', 'name', choice),
108
127
  placeholder: 'Type here',
109
128
  value: get(index, answers),
110
- // TODO: EDIT_CHOICES
111
- // eslint-disable-next-line no-console
112
- onChange: () => console.log('TODO: on choice change')
129
+ onChange: (text: string): void => {
130
+ const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
131
+ dispatch(editAnswer(newAnswers));
132
+ }
113
133
  };
114
134
  };
115
135
 
116
- const templateSelectProps = (choice: ChoiceFromAPI, index: number): SelectionTemplate => {
117
- // TODO: EDIT_CHOICES -> getAnswerValues
118
- const answers: string[] = [];
136
+ const templateSelectProps = (
137
+ dispatch: Dispatch,
138
+ answers: string[],
139
+ choice: ChoiceFromAPI,
140
+ index: number,
141
+ maxLength: number
142
+ ): SelectionTemplate => {
119
143
  const answer = get(index, answers);
120
144
  const temporaryOption = {
121
145
  name: 'Select an answer', // TODO translate
@@ -136,24 +160,29 @@ const templateSelectProps = (choice: ChoiceFromAPI, index: number): SelectionTem
136
160
  return {
137
161
  type: 'select',
138
162
  name: getOr('', 'name', choice),
139
- // TODO: EDIT_CHOICES
140
- // eslint-disable-next-line no-console
141
- onChange: () => console.log('TODO: on choice change'),
163
+ onChange: (text: string): void => {
164
+ const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
165
+ dispatch(editAnswer(newAnswers));
166
+ },
142
167
  options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
143
168
  };
144
169
  };
145
170
 
146
- const templateProps = (question: TemplateQuestion): Template => {
147
- // TODO: EDIT_CHOICES -> getChoices
148
- const choices = question.content.choices;
149
- return {
150
- type: 'template',
151
- template: get('content.template', question),
152
- answers: choices.map((choice, index) =>
153
- choice.type === 'text' ? templateTextProps(choice, index) : templateSelectProps(choice, index)
154
- )
171
+ const templateProps =
172
+ (dispatch: Dispatch) =>
173
+ (answers: string[], question: TemplateQuestion): Template => {
174
+ const choices = question.content.choices;
175
+ const maxLength = size(choices);
176
+ return {
177
+ type: 'template',
178
+ template: get('content.template', question),
179
+ answers: choices.map((choice, index) =>
180
+ choice.type === 'text'
181
+ ? templateTextProps(dispatch, answers, choice, index, maxLength)
182
+ : templateSelectProps(dispatch, answers, choice, index, maxLength)
183
+ )
184
+ };
155
185
  };
156
- };
157
186
 
158
187
  const basicProps =
159
188
  (dispatch: Dispatch) =>
@@ -163,44 +192,48 @@ const basicProps =
163
192
  placeholder: question.content.placeholder || '',
164
193
  value: answers[0] || '',
165
194
  onChange: (text: string): void => {
166
- // eslint-disable-next-line no-console
167
- console.log(text);
168
- dispatch(editAnswer(text));
195
+ dispatch(editAnswer([text]));
169
196
  }
170
197
  };
171
198
  };
172
199
 
173
- const sliderProps = (question: SliderQuestion): QuestionRange => {
174
- const values: number[] = rangeStep(
175
- getOr(1, 'content.step', question),
176
- get('content.min', question),
177
- get('content.max', question) + 1
178
- // Lodash doesn't infer the type very well here
179
- ) as unknown as number[];
180
-
181
- // TODO: EDIT_CHOICES -> getAnswerValues
182
- const answers: string[] = [];
200
+ const sliderProps =
201
+ (dispatch: Dispatch) =>
202
+ (answers: string[], question: SliderQuestion): QuestionRange => {
203
+ const values: number[] = rangeStep(
204
+ getOr(1, 'content.step', question),
205
+ get('content.min', question),
206
+ get('content.max', question) + 1
207
+ // Lodash doesn't infer the type very well here
208
+ ) as unknown as number[];
183
209
 
184
- const stateValue = head(answers) || question.content.min;
185
- const currentValue = toInteger(stateValue);
210
+ const stateValue = head(answers) || question.content.min;
211
+ const currentValue = toInteger(stateValue);
186
212
 
187
- const indexValue = indexOf(currentValue, values);
188
- const sliderPosition = divide(indexValue, size(values) - 1);
213
+ const indexValue = indexOf(currentValue, values);
214
+ const maxValue = size(values) - 1;
215
+ const sliderPosition = divide(indexValue, maxValue);
189
216
 
190
- const unitLabel = get('content.unitLabel', question);
217
+ const unitLabel = get('content.unitLabel', question);
191
218
 
192
- return {
193
- type: 'slider',
194
- placeholder: question.explanation,
195
- minLabel: `${question.content.min} ${unitLabel}`,
196
- maxLabel: `${question.content.max} ${unitLabel}`,
197
- title: `${currentValue} ${question.content.unitLabel}`,
198
- value: sliderPosition,
199
- // TODO: EDIT_CHOICES
200
- // eslint-disable-next-line no-console
201
- onChange: () => console.log('TODO: on choice change')
219
+ return {
220
+ type: 'slider',
221
+ placeholder: question.explanation,
222
+ minLabel: `${question.content.min} ${unitLabel}`,
223
+ maxLabel: `${question.content.max} ${unitLabel}`,
224
+ title: `${currentValue} ${question.content.unitLabel}`,
225
+ value: sliderPosition,
226
+ onChange: (position: number): void => {
227
+ const newValue: string = pipe(
228
+ multiply(maxValue),
229
+ round,
230
+ get(__, values),
231
+ _toString
232
+ )(position);
233
+ dispatch(editAnswer([newValue]));
234
+ }
235
+ };
202
236
  };
203
- };
204
237
 
205
238
  export const getQuestionType = (question: Question): Question['type'] => question.type;
206
239
 
@@ -214,22 +247,22 @@ const getAnswerUIModel = (
214
247
  const type = getQuestionType(question);
215
248
  switch (type) {
216
249
  case 'qcm':
217
- return qcmProps(question as QcmQuestion);
250
+ return qcmProps(dispatch)(answers, question as QcmQuestion);
218
251
 
219
252
  case 'qcmGraphic':
220
- return qcmGraphicProps(question as QcmGraphicQuestion);
253
+ return qcmGraphicProps(dispatch)(answers, question as QcmGraphicQuestion);
221
254
 
222
255
  case 'qcmDrag':
223
- return qcmDragProps(question as QcmDragQuestion);
256
+ return qcmDragProps(dispatch)(answers, question as QcmDragQuestion);
224
257
 
225
258
  case 'basic':
226
259
  return basicProps(dispatch)(answers, question as BasicQuestion);
227
260
 
228
261
  case 'template':
229
- return templateProps(question as TemplateQuestion);
262
+ return templateProps(dispatch)(answers, question as TemplateQuestion);
230
263
 
231
264
  case 'slider':
232
- return sliderProps(question as SliderQuestion);
265
+ return sliderProps(dispatch)(answers, question as SliderQuestion);
233
266
 
234
267
  default:
235
268
  throw new Error(`${type} is not an handled question.type`);
@@ -1,5 +1,6 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
5
  export const freeTextSlide: SlideFromAPI = {
5
6
  question: {
@@ -1,5 +1,6 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
5
  export const qcmDragSlide: SlideFromAPI = {
5
6
  question: {
@@ -1,5 +1,6 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
5
  export const qcmGraphicSlide: SlideFromAPI = {
5
6
  question: {
@@ -1,5 +1,6 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
5
  export const qcmSlide: SlideFromAPI = {
5
6
  question: {
@@ -1,5 +1,6 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
5
  export const sliderSlide: SlideFromAPI = {
5
6
  question: {
@@ -1,11 +1,12 @@
1
1
  import noop from 'lodash/fp/noop';
2
- import {SlideFromAPI, UISlide} from '../../../../types/common';
2
+ import {UISlide} from '../..';
3
+ import {SlideFromAPI} from '../../../../types/common';
3
4
 
4
- export const selectTemplateSlide: SlideFromAPI = {
5
+ export const templateSlide: SlideFromAPI = {
5
6
  question: {
6
7
  content: {
7
8
  template:
8
- 'La vue {{sel80495}} présente la liste des utilisateurs ayant le plus grand nombre d’étoiles cumulées.',
9
+ 'La vue {{sel80495}} présente la liste des {{inp58402}} ayant le plus grand nombre d’{{sel80496}} cumulées.',
9
10
  choices: [
10
11
  {
11
12
  items: [
@@ -33,6 +34,45 @@ export const selectTemplateSlide: SlideFromAPI = {
33
34
  _id: '5b57464e3b594d002e8829f3',
34
35
  name: 'sel80495',
35
36
  type: 'select'
37
+ },
38
+ {
39
+ media: {
40
+ src: [],
41
+ posters: [],
42
+ subtitles: []
43
+ },
44
+ items: [],
45
+ _id: '62433c2c58920f02c4950de0',
46
+ type: 'text',
47
+ name: 'inp58402',
48
+ id: '62433c2c58920f02c4950de0'
49
+ },
50
+ {
51
+ items: [
52
+ {
53
+ _id: '5b57464e3b594d002e8829f7',
54
+ value: 'sli_N13-hG3kX.choice_NJgC3aznJm',
55
+ text: 'étoiles'
56
+ },
57
+ {
58
+ _id: '5b57464e3b594d002e8829f6',
59
+ value: 'sli_N13-hG3kX.choice_EJZ02aMny7',
60
+ text: 'idées'
61
+ },
62
+ {
63
+ _id: '5b57464e3b594d002e8829f5',
64
+ value: 'sli_N13-hG3kX.choice_4keCaf21Q',
65
+ text: 'envies'
66
+ },
67
+ {
68
+ _id: '5b57464e3b594d002e8829f4',
69
+ value: 'sli_N13-hG3kX.choice_NkbJAMn17',
70
+ text: 'images'
71
+ }
72
+ ],
73
+ _id: '5b57464e3b594d002e8829f3',
74
+ name: 'sel80496',
75
+ type: 'select'
36
76
  }
37
77
  ]
38
78
  },
@@ -51,14 +91,14 @@ export const selectTemplateSlide: SlideFromAPI = {
51
91
  }
52
92
  };
53
93
 
54
- export const selectTemplateUISlide: Partial<UISlide> = {
94
+ export const templateUISlide: Partial<UISlide> = {
55
95
  questionText: 'Complétez la phrase ci-dessous.',
56
96
  answerUI: {
57
97
  help: 'Saisissez votre réponse ou sélectionnez la bonne réponse dans le(s) menu(s) déroulant(s).',
58
98
  model: {
59
99
  type: 'template',
60
100
  template:
61
- 'La vue {{sel80495}} présente la liste des utilisateurs ayant le plus grand nombre d’étoiles cumulées.',
101
+ 'La vue {{sel80495}} présente la liste des {{inp58402}} ayant le plus grand nombre d’{{sel80496}} cumulées.',
62
102
  answers: [
63
103
  {
64
104
  type: 'select',
@@ -91,6 +131,45 @@ export const selectTemplateUISlide: Partial<UISlide> = {
91
131
  selected: false
92
132
  }
93
133
  ]
134
+ },
135
+ {
136
+ type: 'text',
137
+ name: 'inp58402',
138
+ placeholder: 'Type here',
139
+ value: undefined,
140
+ onChange: noop
141
+ },
142
+ {
143
+ type: 'select',
144
+ name: 'sel80496',
145
+ onChange: noop,
146
+ options: [
147
+ {name: 'Select an answer', value: '', validOption: false, selected: true},
148
+ {
149
+ name: 'étoiles',
150
+ value: 'étoiles',
151
+ validOption: true,
152
+ selected: false
153
+ },
154
+ {
155
+ name: 'idées',
156
+ value: 'idées',
157
+ validOption: true,
158
+ selected: false
159
+ },
160
+ {
161
+ name: 'envies',
162
+ value: 'envies',
163
+ validOption: true,
164
+ selected: false
165
+ },
166
+ {
167
+ name: 'images',
168
+ value: 'images',
169
+ validOption: true,
170
+ selected: false
171
+ }
172
+ ]
94
173
  }
95
174
  ]
96
175
  }