@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
@@ -1,7 +1,7 @@
1
1
  import { Dispatch } from 'redux';
2
- import { UISlide } from '../../types/common';
3
2
  import { SlideIndexes } from '../../common';
4
3
  import { StoreState } from '../../reducers';
4
+ import { AnswerUI } from '../../types/slides';
5
5
  declare const ICON_VALUES: {
6
6
  readonly right: "right";
7
7
  readonly wrong: "wrong";
@@ -13,6 +13,17 @@ declare type StepItem = {
13
13
  icon: IconValue;
14
14
  value: string;
15
15
  };
16
+ declare type SlideUIAnimations = 'unstack' | 'restack';
17
+ export declare type UISlide = {
18
+ questionText?: string;
19
+ answerUI?: AnswerUI;
20
+ hidden?: boolean;
21
+ position: number;
22
+ animationType?: SlideUIAnimations;
23
+ isCorrect?: boolean;
24
+ endReview?: boolean;
25
+ loading: boolean;
26
+ };
16
27
  declare type SlidesStack = {
17
28
  [key in SlideIndexes]: UISlide;
18
29
  };
@@ -75,5 +86,5 @@ export declare type SlidesViewProps = {
75
86
  };
76
87
  };
77
88
  export declare const initialState: SlidesStack;
78
- export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch) => SlidesViewProps | null;
89
+ export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch) => SlidesViewProps;
79
90
  export {};
@@ -7,6 +7,7 @@ import reduce from 'lodash/fp/reduce';
7
7
  import set from 'lodash/fp/set';
8
8
  import slice from 'lodash/fp/slice';
9
9
  import toInteger from 'lodash/fp/toInteger';
10
+ import { postAnswer } from '../../actions/api/post-answer';
10
11
  import { mapApiSlideToUi } from './map-api-slide-to-ui';
11
12
  const ICON_VALUES = {
12
13
  right: 'right',
@@ -16,29 +17,34 @@ const ICON_VALUES = {
16
17
  export const initialState = {
17
18
  '0': {
18
19
  hidden: false,
19
- position: 0
20
+ position: 0,
21
+ loading: true
20
22
  },
21
23
  '1': {
22
24
  hidden: false,
23
- position: 1
25
+ position: 1,
26
+ loading: true
24
27
  },
25
28
  '2': {
26
29
  hidden: false,
27
- position: 2
30
+ position: 2,
31
+ loading: true
28
32
  },
29
33
  '3': {
30
34
  hidden: false,
31
- position: 3
35
+ position: 3,
36
+ loading: true
32
37
  },
33
38
  '4': {
34
39
  hidden: false,
35
- position: 4
40
+ position: 4,
41
+ loading: true
36
42
  }
37
43
  };
38
- const getProgressionSlidesRef = (progression) => {
44
+ const getProgressionSlidesRefs = (progression) => {
39
45
  if (progression.state.step.current < 5) {
40
46
  const slideRef = progression.state.nextContent.ref;
41
- return concat([slideRef], progression.state.slides);
47
+ return concat(progression.state.slides, [slideRef]);
42
48
  }
43
49
  return slice(0, 5, progression.state.slides);
44
50
  };
@@ -47,18 +53,20 @@ const buildStackSlides = (state, dispatch) => {
47
53
  const progression = state.data.progression;
48
54
  if (!currentSlideRef || !progression)
49
55
  return initialState;
50
- const slideRefs = getProgressionSlidesRef(progression);
56
+ const slideRefs = getProgressionSlidesRefs(progression);
51
57
  // @ts-expect-error typescript does not support capped versions of lodash functions
52
58
  const stack = reduce.convert({ cap: false })((acc, uiSlide, index) => {
53
59
  const slideRef = slideRefs[toInteger(index)];
54
60
  if (!slideRef)
55
61
  return set(index, uiSlide, acc);
56
62
  const slideFromAPI = get(slideRef, state.data.slides);
63
+ if (!slideFromAPI)
64
+ return set(index, uiSlide, acc);
57
65
  const answers = state.ui.answers;
58
66
  const { questionText, answerUI } = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
59
67
  const parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
60
68
  const parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
61
- const updatedUiSlide = pipe(set(['questionText'], questionText), set(['answerUI'], answerUI), set(['parentContentTitle'], `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
69
+ const updatedUiSlide = pipe(set('loading', false), set('questionText', questionText), set('answerUI', answerUI), set('parentContentTitle', `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
62
70
  // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
63
71
  )(uiSlide);
64
72
  return set(index, updatedUiSlide, acc);
@@ -118,9 +126,6 @@ const buildStepItems = (state) => {
118
126
  return steps;
119
127
  };
120
128
  export const mapStateToSlidesProps = (state, dispatch) => {
121
- if (!state.data.slides) {
122
- return null;
123
- }
124
129
  return {
125
130
  header: {
126
131
  mode: '__revision_mode',
@@ -137,10 +142,9 @@ export const mapStateToSlidesProps = (state, dispatch) => {
137
142
  slides: buildStackSlides(state, dispatch),
138
143
  validateButton: {
139
144
  label: '__validate',
140
- disabled: true,
145
+ disabled: !get('ui.slide.validateButton', state),
141
146
  onClick: () => {
142
- // eslint-disable-next-line no-console
143
- console.log('TODO: validate question');
147
+ dispatch(postAnswer);
144
148
  }
145
149
  },
146
150
  correctionPopinProps: undefined,
@@ -1,75 +1,71 @@
1
- import { concat, divide, get, getOr, head, includes, indexOf, isEmpty, map, rangeStep, size, toInteger } from 'lodash/fp';
1
+ import { concat, constant, divide, get, getOr, head, includes, indexOf, isEmpty, isNil, map, multiply, pipe, rangeStep, round, set, size, times, toInteger, toString as _toString, __ } from 'lodash/fp';
2
2
  import { editAnswer } from '../../actions/ui/answers';
3
- const qcmProps = (question) => {
4
- // TODO: EDIT_CHOICES -> getAnswerValues
5
- const answers = [];
3
+ const qcmProps = (dispatch) => (answers, question) => {
6
4
  return {
7
5
  type: 'qcm',
8
- answers: map(choice => ({
9
- title: choice.label,
10
- selected: includes(choice.label, answers),
11
- // TODO: EDIT_CHOICES
12
- // eslint-disable-next-line no-console
13
- onClick: () => console.log('TODO: on choice click'),
14
- ariaLabel: choice.label
15
- }),
16
- // TODO: EDIT_CHOICES -> getChoices
17
- question.content.choices)
6
+ answers: map(choice => {
7
+ const label = choice.label || '';
8
+ return {
9
+ title: label,
10
+ selected: includes(label, answers),
11
+ onClick: () => {
12
+ dispatch(editAnswer([label]));
13
+ },
14
+ ariaLabel: choice.label
15
+ };
16
+ }, question.content.choices)
18
17
  };
19
18
  };
20
- const qcmDragProps = (question) => {
21
- // TODO: EDIT_CHOICES -> getAnswerValues
22
- const answers = [];
19
+ const qcmDragProps = (dispatch) => (answers, question) => {
23
20
  return {
24
21
  type: 'qcmDrag',
25
22
  answers: map(choice => {
26
- const indexInAnswer = indexOf(choice.label, answers);
23
+ const label = choice.label || '';
24
+ const indexInAnswer = indexOf(label, answers);
27
25
  return {
28
- title: choice.label,
29
- selected: includes(choice.label, answers),
26
+ title: label,
27
+ selected: includes(label, answers),
30
28
  order: indexInAnswer,
31
- // TODO: EDIT_CHOICES
32
- // eslint-disable-next-line no-console
33
- onClick: () => console.log('TODO: on choice click')
29
+ onClick: () => {
30
+ dispatch(editAnswer([label]));
31
+ }
34
32
  };
35
- // TODO: EDIT_CHOICES -> getChoices
36
33
  }, question.content.choices)
37
34
  };
38
35
  };
39
- const qcmGraphicProps = (question) => {
40
- // mock the answers
41
- // TODO: EDIT_CHOICES -> getAnswerValues
42
- const answers = [];
36
+ const qcmGraphicProps = (dispatch) => (answers, question) => {
43
37
  return {
44
38
  type: 'qcmGraphic',
45
- answers: map(choice => ({
46
- title: choice.label,
47
- image: get('media.src.0.url', choice),
48
- selected: includes(choice.label, answers),
49
- // TODO: EDIT_CHOICES
50
- // eslint-disable-next-line no-console
51
- onClick: () => console.log('TODO: on choice click')
52
- }),
53
- // TODO: EDIT_CHOICES -> getChoices
54
- question.content.choices)
39
+ answers: map(choice => {
40
+ const label = choice.label || '';
41
+ return {
42
+ title: label,
43
+ image: get('media.src.0.url', choice),
44
+ selected: includes(label, answers),
45
+ onClick: () => {
46
+ dispatch(editAnswer([label]));
47
+ }
48
+ };
49
+ }, question.content.choices)
55
50
  };
56
51
  };
57
- const templateTextProps = (choice, index) => {
58
- // TODO: EDIT_CHOICES -> getAnswerValues
59
- const answers = [];
52
+ const updateTemplateAnswer = (text, _answers, index, max) => {
53
+ const answers = isEmpty(_answers) ? times(constant(undefined), max) : _answers;
54
+ return map(a => (isNil(a) ? '' : a), set(index, text, answers));
55
+ };
56
+ const templateTextProps = (dispatch, answers, choice, index, maxLength) => {
60
57
  return {
61
58
  type: 'text',
62
59
  name: getOr('', 'name', choice),
63
60
  placeholder: 'Type here',
64
61
  value: get(index, answers),
65
- // TODO: EDIT_CHOICES
66
- // eslint-disable-next-line no-console
67
- onChange: () => console.log('TODO: on choice change')
62
+ onChange: (text) => {
63
+ const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
64
+ dispatch(editAnswer(newAnswers));
65
+ }
68
66
  };
69
67
  };
70
- const templateSelectProps = (choice, index) => {
71
- // TODO: EDIT_CHOICES -> getAnswerValues
72
- const answers = [];
68
+ const templateSelectProps = (dispatch, answers, choice, index, maxLength) => {
73
69
  const answer = get(index, answers);
74
70
  const temporaryOption = {
75
71
  name: 'Select an answer',
@@ -89,19 +85,22 @@ const templateSelectProps = (choice, index) => {
89
85
  return {
90
86
  type: 'select',
91
87
  name: getOr('', 'name', choice),
92
- // TODO: EDIT_CHOICES
93
- // eslint-disable-next-line no-console
94
- onChange: () => console.log('TODO: on choice change'),
88
+ onChange: (text) => {
89
+ const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
90
+ dispatch(editAnswer(newAnswers));
91
+ },
95
92
  options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
96
93
  };
97
94
  };
98
- const templateProps = (question) => {
99
- // TODO: EDIT_CHOICES -> getChoices
95
+ const templateProps = (dispatch) => (answers, question) => {
100
96
  const choices = question.content.choices;
97
+ const maxLength = size(choices);
101
98
  return {
102
99
  type: 'template',
103
100
  template: get('content.template', question),
104
- answers: choices.map((choice, index) => choice.type === 'text' ? templateTextProps(choice, index) : templateSelectProps(choice, index))
101
+ answers: choices.map((choice, index) => choice.type === 'text'
102
+ ? templateTextProps(dispatch, answers, choice, index, maxLength)
103
+ : templateSelectProps(dispatch, answers, choice, index, maxLength))
105
104
  };
106
105
  };
107
106
  const basicProps = (dispatch) => (answers, question) => {
@@ -110,22 +109,19 @@ const basicProps = (dispatch) => (answers, question) => {
110
109
  placeholder: question.content.placeholder || '',
111
110
  value: answers[0] || '',
112
111
  onChange: (text) => {
113
- // eslint-disable-next-line no-console
114
- console.log(text);
115
- dispatch(editAnswer(text));
112
+ dispatch(editAnswer([text]));
116
113
  }
117
114
  };
118
115
  };
119
- const sliderProps = (question) => {
116
+ const sliderProps = (dispatch) => (answers, question) => {
120
117
  const values = rangeStep(getOr(1, 'content.step', question), get('content.min', question), get('content.max', question) + 1
121
118
  // Lodash doesn't infer the type very well here
122
119
  );
123
- // TODO: EDIT_CHOICES -> getAnswerValues
124
- const answers = [];
125
120
  const stateValue = head(answers) || question.content.min;
126
121
  const currentValue = toInteger(stateValue);
127
122
  const indexValue = indexOf(currentValue, values);
128
- const sliderPosition = divide(indexValue, size(values) - 1);
123
+ const maxValue = size(values) - 1;
124
+ const sliderPosition = divide(indexValue, maxValue);
129
125
  const unitLabel = get('content.unitLabel', question);
130
126
  return {
131
127
  type: 'slider',
@@ -134,9 +130,10 @@ const sliderProps = (question) => {
134
130
  maxLabel: `${question.content.max} ${unitLabel}`,
135
131
  title: `${currentValue} ${question.content.unitLabel}`,
136
132
  value: sliderPosition,
137
- // TODO: EDIT_CHOICES
138
- // eslint-disable-next-line no-console
139
- onChange: () => console.log('TODO: on choice change')
133
+ onChange: (position) => {
134
+ const newValue = pipe(multiply(maxValue), round, get(__, values), _toString)(position);
135
+ dispatch(editAnswer([newValue]));
136
+ }
140
137
  };
141
138
  };
142
139
  export const getQuestionType = (question) => question.type;
@@ -145,17 +142,17 @@ const getAnswerUIModel = (question, answers, dispatch) => {
145
142
  const type = getQuestionType(question);
146
143
  switch (type) {
147
144
  case 'qcm':
148
- return qcmProps(question);
145
+ return qcmProps(dispatch)(answers, question);
149
146
  case 'qcmGraphic':
150
- return qcmGraphicProps(question);
147
+ return qcmGraphicProps(dispatch)(answers, question);
151
148
  case 'qcmDrag':
152
- return qcmDragProps(question);
149
+ return qcmDragProps(dispatch)(answers, question);
153
150
  case 'basic':
154
151
  return basicProps(dispatch)(answers, question);
155
152
  case 'template':
156
- return templateProps(question);
153
+ return templateProps(dispatch)(answers, question);
157
154
  case 'slider':
158
- return sliderProps(question);
155
+ return sliderProps(dispatch)(answers, question);
159
156
  default:
160
157
  throw new Error(`${type} is not an handled question.type`);
161
158
  }
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const freeTextSlide: SlideFromAPI;
3
4
  export declare const freeTextUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const qcmDragSlide: SlideFromAPI;
3
4
  export declare const qcmDragUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const qcmGraphicSlide: SlideFromAPI;
3
4
  export declare const qcmGraphicUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const qcmSlide: SlideFromAPI;
3
4
  export declare const qcmUISlide: Partial<UISlide>;
@@ -1,3 +1,4 @@
1
- import { SlideFromAPI, UISlide } from '../../../../types/common';
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
2
3
  export declare const sliderSlide: SlideFromAPI;
3
4
  export declare const sliderUISlide: Partial<UISlide>;
@@ -0,0 +1,4 @@
1
+ import { UISlide } from '../..';
2
+ import { SlideFromAPI } from '../../../../types/common';
3
+ export declare const templateSlide: SlideFromAPI;
4
+ export declare const templateUISlide: Partial<UISlide>;
@@ -1,8 +1,8 @@
1
1
  import noop from 'lodash/fp/noop';
2
- export var selectTemplateSlide = {
2
+ export const templateSlide = {
3
3
  question: {
4
4
  content: {
5
- template: 'La vue {{sel80495}} présente la liste des utilisateurs ayant le plus grand nombre d’étoiles cumulées.',
5
+ template: 'La vue {{sel80495}} présente la liste des {{inp58402}} ayant le plus grand nombre d’{{sel80496}} cumulées.',
6
6
  choices: [
7
7
  {
8
8
  items: [
@@ -30,6 +30,45 @@ export var selectTemplateSlide = {
30
30
  _id: '5b57464e3b594d002e8829f3',
31
31
  name: 'sel80495',
32
32
  type: 'select'
33
+ },
34
+ {
35
+ media: {
36
+ src: [],
37
+ posters: [],
38
+ subtitles: []
39
+ },
40
+ items: [],
41
+ _id: '62433c2c58920f02c4950de0',
42
+ type: 'text',
43
+ name: 'inp58402',
44
+ id: '62433c2c58920f02c4950de0'
45
+ },
46
+ {
47
+ items: [
48
+ {
49
+ _id: '5b57464e3b594d002e8829f7',
50
+ value: 'sli_N13-hG3kX.choice_NJgC3aznJm',
51
+ text: 'étoiles'
52
+ },
53
+ {
54
+ _id: '5b57464e3b594d002e8829f6',
55
+ value: 'sli_N13-hG3kX.choice_EJZ02aMny7',
56
+ text: 'idées'
57
+ },
58
+ {
59
+ _id: '5b57464e3b594d002e8829f5',
60
+ value: 'sli_N13-hG3kX.choice_4keCaf21Q',
61
+ text: 'envies'
62
+ },
63
+ {
64
+ _id: '5b57464e3b594d002e8829f4',
65
+ value: 'sli_N13-hG3kX.choice_NkbJAMn17',
66
+ text: 'images'
67
+ }
68
+ ],
69
+ _id: '5b57464e3b594d002e8829f3',
70
+ name: 'sel80496',
71
+ type: 'select'
33
72
  }
34
73
  ]
35
74
  },
@@ -46,13 +85,13 @@ export var selectTemplateSlide = {
46
85
  type: 'course'
47
86
  }
48
87
  };
49
- export var selectTemplateUISlide = {
88
+ export const templateUISlide = {
50
89
  questionText: 'Complétez la phrase ci-dessous.',
51
90
  answerUI: {
52
91
  help: 'Saisissez votre réponse ou sélectionnez la bonne réponse dans le(s) menu(s) déroulant(s).',
53
92
  model: {
54
93
  type: 'template',
55
- template: 'La vue {{sel80495}} présente la liste des utilisateurs ayant le plus grand nombre d’étoiles cumulées.',
94
+ template: 'La vue {{sel80495}} présente la liste des {{inp58402}} ayant le plus grand nombre d’{{sel80496}} cumulées.',
56
95
  answers: [
57
96
  {
58
97
  type: 'select',
@@ -85,6 +124,45 @@ export var selectTemplateUISlide = {
85
124
  selected: false
86
125
  }
87
126
  ]
127
+ },
128
+ {
129
+ type: 'text',
130
+ name: 'inp58402',
131
+ placeholder: 'Type here',
132
+ value: undefined,
133
+ onChange: noop
134
+ },
135
+ {
136
+ type: 'select',
137
+ name: 'sel80496',
138
+ onChange: noop,
139
+ options: [
140
+ { name: 'Select an answer', value: '', validOption: false, selected: true },
141
+ {
142
+ name: 'étoiles',
143
+ value: 'étoiles',
144
+ validOption: true,
145
+ selected: false
146
+ },
147
+ {
148
+ name: 'idées',
149
+ value: 'idées',
150
+ validOption: true,
151
+ selected: false
152
+ },
153
+ {
154
+ name: 'envies',
155
+ value: 'envies',
156
+ validOption: true,
157
+ selected: false
158
+ },
159
+ {
160
+ name: 'images',
161
+ value: 'images',
162
+ validOption: true,
163
+ selected: false
164
+ }
165
+ ]
88
166
  }
89
167
  ]
90
168
  }
@@ -0,0 +1 @@
1
+ export {};