@coorpacademy/app-review 0.1.16 → 0.1.17

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 (183) 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 +10 -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 +39 -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 +90 -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 +2 -3
  32. package/es/reducers/data/progression.js +0 -5
  33. package/es/reducers/data/slides.d.ts +2 -3
  34. package/es/reducers/data/test/progression.test.js +1 -1
  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 +19 -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 +2 -1
  48. package/es/test/util/services.mock.js +86 -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 +18 -14
  56. package/es/views/slides/map-api-slide-to-ui.js +44 -51
  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/select-template.d.ts +2 -1
  62. package/es/views/slides/test/fixtures/slider.d.ts +2 -1
  63. package/es/views/slides/test/fixtures/text-template.d.ts +2 -1
  64. package/es/views/slides/test/index.test.d.ts +1 -0
  65. package/es/views/slides/test/index.test.js +234 -0
  66. package/lib/actions/api/fetch-skills.d.ts +3 -3
  67. package/lib/actions/api/fetch-skills.js +22 -19
  68. package/lib/actions/api/fetch-slide.d.ts +1 -1
  69. package/lib/actions/api/fetch-slide.js +3 -1
  70. package/lib/actions/api/post-answer.d.ts +10 -0
  71. package/lib/actions/api/post-answer.js +75 -0
  72. package/lib/actions/api/post-progression.d.ts +3 -3
  73. package/lib/actions/api/post-progression.js +6 -3
  74. package/lib/actions/api/test/fetch-skills.test.js +7 -4
  75. package/lib/actions/api/test/fetch-slide.test.js +7 -4
  76. package/lib/actions/api/test/post-answer.test.d.ts +1 -0
  77. package/lib/actions/api/test/post-answer.test.js +145 -0
  78. package/lib/actions/api/test/post-progression.test.js +7 -4
  79. package/lib/actions/data/test/token.test.d.ts +1 -0
  80. package/lib/actions/data/test/token.test.js +70 -0
  81. package/lib/actions/index.d.ts +1 -8
  82. package/lib/actions/{api/test → test}/create-test-store.d.ts +2 -2
  83. package/lib/actions/{api/test → test}/create-test-store.js +1 -1
  84. package/lib/actions/ui/answers.d.ts +17 -3
  85. package/lib/actions/ui/answers.js +48 -3
  86. package/lib/actions/ui/slides.d.ts +0 -5
  87. package/lib/actions/ui/slides.js +0 -4
  88. package/lib/actions/ui/test/answers.test.d.ts +1 -0
  89. package/lib/actions/ui/test/answers.test.js +171 -0
  90. package/lib/actions/ui/test/slides.test.d.ts +1 -0
  91. package/lib/actions/ui/test/slides.test.js +71 -0
  92. package/lib/common/index.d.ts +0 -3
  93. package/lib/common/index.js +0 -4
  94. package/lib/index.js +1 -3
  95. package/lib/reducers/data/index.d.ts +1 -1
  96. package/lib/reducers/data/progression.d.ts +2 -3
  97. package/lib/reducers/data/progression.js +0 -5
  98. package/lib/reducers/data/slides.d.ts +2 -3
  99. package/lib/reducers/data/test/progression.test.js +1 -1
  100. package/lib/reducers/index.d.ts +2 -1
  101. package/lib/reducers/ui/answers.d.ts +2 -2
  102. package/lib/reducers/ui/answers.js +4 -8
  103. package/lib/reducers/ui/index.d.ts +4 -1
  104. package/lib/reducers/ui/index.js +3 -1
  105. package/lib/reducers/ui/slide.d.ts +8 -0
  106. package/lib/reducers/ui/slide.js +27 -0
  107. package/lib/reducers/ui/test/answers.test.js +19 -3
  108. package/lib/reducers/ui/test/current-slide-ref.test.js +1 -1
  109. package/lib/reducers/ui/test/navigation.test.js +5 -5
  110. package/lib/reducers/ui/test/slide.test.d.ts +1 -0
  111. package/lib/reducers/ui/test/slide.test.js +12 -0
  112. package/lib/test/util/services.mock.d.ts +2 -1
  113. package/lib/test/util/services.mock.js +86 -72
  114. package/lib/types/common.d.ts +0 -25
  115. package/lib/views/skills/index.d.ts +1 -1
  116. package/lib/views/skills/index.js +0 -3
  117. package/lib/views/skills/test/skills.test.d.ts +1 -0
  118. package/lib/views/skills/test/skills.test.js +94 -0
  119. package/lib/views/slides/index.d.ts +13 -2
  120. package/lib/views/slides/index.js +18 -14
  121. package/lib/views/slides/map-api-slide-to-ui.js +77 -76
  122. package/lib/views/slides/test/fixtures/free-text.d.ts +2 -1
  123. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +2 -1
  124. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +2 -1
  125. package/lib/views/slides/test/fixtures/qcm.d.ts +2 -1
  126. package/lib/views/slides/test/fixtures/select-template.d.ts +2 -1
  127. package/lib/views/slides/test/fixtures/slider.d.ts +2 -1
  128. package/lib/views/slides/test/fixtures/text-template.d.ts +2 -1
  129. package/lib/views/slides/test/index.test.d.ts +1 -0
  130. package/lib/views/slides/test/index.test.js +234 -0
  131. package/package.json +6 -5
  132. package/src/actions/api/fetch-skills.ts +18 -11
  133. package/src/actions/api/fetch-slide.ts +3 -1
  134. package/src/actions/api/post-answer.ts +39 -0
  135. package/src/actions/api/post-progression.ts +7 -4
  136. package/src/actions/api/test/fetch-skills.test.ts +9 -6
  137. package/src/actions/api/test/fetch-slide.test.ts +9 -6
  138. package/src/actions/api/test/post-answer.test.ts +101 -0
  139. package/src/actions/api/test/post-progression.test.ts +9 -6
  140. package/src/actions/data/test/token.test.ts +29 -0
  141. package/src/actions/index.ts +1 -17
  142. package/src/actions/{api/test → test}/create-test-store.ts +2 -2
  143. package/src/actions/ui/answers.ts +52 -5
  144. package/src/actions/ui/slides.ts +1 -8
  145. package/src/actions/ui/test/answers.test.ts +103 -0
  146. package/src/actions/ui/test/slides.test.ts +30 -0
  147. package/src/common/index.ts +0 -7
  148. package/src/index.tsx +1 -3
  149. package/src/reducers/data/progression.ts +2 -7
  150. package/src/reducers/data/slides.ts +2 -3
  151. package/src/reducers/data/test/progression.test.ts +3 -3
  152. package/src/reducers/ui/answers.ts +5 -9
  153. package/src/reducers/ui/index.ts +4 -1
  154. package/src/reducers/ui/slide.ts +43 -0
  155. package/src/reducers/ui/test/answers.test.ts +24 -4
  156. package/src/reducers/ui/test/current-slide-ref.test.ts +1 -1
  157. package/src/reducers/ui/test/navigation.test.ts +5 -5
  158. package/src/reducers/ui/test/slide.test.ts +15 -0
  159. package/src/test/util/services.mock.ts +91 -73
  160. package/src/types/common.ts +0 -30
  161. package/src/views/skills/index.ts +1 -5
  162. package/src/views/skills/test/skills.test.ts +101 -0
  163. package/src/views/slides/index.ts +37 -22
  164. package/src/views/slides/map-api-slide-to-ui.ts +89 -89
  165. package/src/views/slides/test/fixtures/free-text.ts +2 -1
  166. package/src/views/slides/test/fixtures/qcm-drag.ts +2 -1
  167. package/src/views/slides/test/fixtures/qcm-graphic.ts +2 -1
  168. package/src/views/slides/test/fixtures/qcm.ts +2 -1
  169. package/src/views/slides/test/fixtures/select-template.ts +2 -1
  170. package/src/views/slides/test/fixtures/slider.ts +2 -1
  171. package/src/views/slides/test/fixtures/text-template.ts +2 -1
  172. package/src/views/slides/test/index.test.ts +240 -0
  173. package/src/views/slides/test/map-api-slide-to-ui.test.ts +2 -1
  174. package/es/fixtures/qcm-slide.d.ts +0 -2
  175. package/es/fixtures/qcm-slide.js +0 -33
  176. package/es/fixtures/temp-fixture.d.ts +0 -3
  177. package/es/fixtures/temp-fixture.js +0 -84
  178. package/lib/fixtures/qcm-slide.d.ts +0 -2
  179. package/lib/fixtures/qcm-slide.js +0 -33
  180. package/lib/fixtures/temp-fixture.d.ts +0 -3
  181. package/lib/fixtures/temp-fixture.js +0 -84
  182. package/src/fixtures/qcm-slide.ts +0 -35
  183. package/src/fixtures/temp-fixture.ts +0 -94
@@ -9,83 +9,97 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { qcmSlide } from '../../views/slides/test/fixtures/qcm';
13
+ import { qcmGraphicSlide } from '../../views/slides/test/fixtures/qcm-graphic';
12
14
  import { freeTextSlide } from '../../views/slides/test/fixtures/free-text';
13
- export var services = {
14
- fetchSkills: function () {
15
- return Promise.resolve([
16
- {
17
- skillRef: '_skill-ref',
18
- slidesToReview: 2,
19
- name: 'skill-test',
20
- custom: false
21
- },
22
- {
23
- skillRef: '_skill-ref-2',
24
- slidesToReview: 2,
25
- name: 'skill-test-2',
26
- custom: true
27
- }
28
- ]);
15
+ import { sliderSlide } from '../../views/slides/test/fixtures/slider';
16
+ var getSlideFixture = function (ref) {
17
+ switch (ref) {
18
+ case qcmSlide.universalRef:
19
+ return qcmSlide;
20
+ case qcmGraphicSlide.universalRef:
21
+ return qcmGraphicSlide;
22
+ case freeTextSlide.universalRef:
23
+ return freeTextSlide;
24
+ default:
25
+ return sliderSlide;
26
+ }
27
+ };
28
+ var fetchSkillsResponse = [
29
+ {
30
+ skillRef: '_skill-ref',
31
+ slidesToReview: 2,
32
+ name: 'skill-test',
33
+ custom: false
29
34
  },
30
- fetchSlide: function (ref) {
31
- return Promise.resolve(__assign(__assign({}, freeTextSlide), { universalRef: ref, id: ref }));
35
+ {
36
+ skillRef: '_skill-ref-2',
37
+ slidesToReview: 2,
38
+ name: 'skill-test-2',
39
+ custom: true
40
+ }
41
+ ];
42
+ var postProgressionResponse = {
43
+ _id: '62b1d1087aa12f00253f40ee',
44
+ content: {
45
+ ref: '_skill-ref',
46
+ type: 'skill'
32
47
  },
33
- postProgression: function () {
34
- return Promise.resolve({
35
- _id: '62b1d1087aa12f00253f40ee',
36
- content: {
37
- ref: '_skill-ref',
38
- type: 'skill'
39
- },
40
- engine: {
41
- ref: 'review'
42
- },
43
- state: {
44
- allAnswers: [],
45
- isCorrect: true,
46
- nextContent: {
47
- ref: 'sli_N1XACJobn',
48
- type: 'slide'
49
- },
50
- pendingSlides: [],
51
- slides: [],
52
- step: {
53
- current: 1
54
- },
55
- stars: 0
56
- }
57
- });
48
+ engine: {
49
+ ref: 'review'
50
+ },
51
+ state: {
52
+ allAnswers: [],
53
+ isCorrect: true,
54
+ nextContent: {
55
+ ref: 'sli_VJYjJnJhg',
56
+ type: 'slide'
57
+ },
58
+ pendingSlides: [],
59
+ slides: [],
60
+ step: {
61
+ current: 1
62
+ },
63
+ stars: 0
64
+ }
65
+ };
66
+ export var postAnswerResponse = {
67
+ _id: '62b1d1087aa12f00253f40ee',
68
+ content: {
69
+ ref: '_skill-ref',
70
+ type: 'skill'
58
71
  },
59
- postAnswer: function () {
60
- return Promise.resolve({
61
- _id: '62b1d1087aa12f00253f40ee',
62
- content: {
63
- ref: '_skill-ref',
64
- type: 'skill'
65
- },
66
- engine: {
67
- ref: 'review'
68
- },
69
- state: {
70
- allAnswers: [
71
- {
72
- slideRef: 'sli_N1XACJobn',
73
- isCorrect: true,
74
- answer: ['Le créateur peut fixer un pourcentage pour chaque transaction future']
75
- }
76
- ],
72
+ engine: {
73
+ ref: 'review'
74
+ },
75
+ state: {
76
+ allAnswers: [
77
+ {
78
+ slideRef: 'sli_VJYjJnJhg',
77
79
  isCorrect: true,
78
- nextContent: {
79
- ref: 'sli_VkSQroQnx',
80
- type: 'slide'
81
- },
82
- pendingSlides: [],
83
- slides: ['sli_N1XACJobn'],
84
- step: {
85
- current: 2
86
- },
87
- stars: 4
80
+ answer: ['Benchmark']
88
81
  }
89
- });
82
+ ],
83
+ isCorrect: true,
84
+ nextContent: {
85
+ ref: 'sli_VkSQroQnx',
86
+ type: 'slide'
87
+ },
88
+ content: {
89
+ ref: 'sli_VJYjJnJhg',
90
+ type: 'slide'
91
+ },
92
+ pendingSlides: [],
93
+ slides: ['sli_VJYjJnJhg'],
94
+ step: {
95
+ current: 2
96
+ },
97
+ stars: 4
90
98
  }
91
99
  };
100
+ export var services = {
101
+ fetchSkills: function () { return Promise.resolve(fetchSkillsResponse); },
102
+ fetchSlide: function (ref) { return Promise.resolve(__assign(__assign({}, getSlideFixture(ref)), { universalRef: ref, id: ref })); },
103
+ postProgression: function () { return Promise.resolve(postProgressionResponse); },
104
+ postAnswer: function () { return Promise.resolve(postAnswerResponse); }
105
+ };
@@ -1,5 +1,3 @@
1
- import { SlideIndexes } from '../common';
2
- import { AnswerUI } from './slides';
3
1
  declare type TemplateContextValues = {
4
2
  brandTheme?: unknown;
5
3
  theme?: unknown;
@@ -142,29 +140,6 @@ export declare type JWT = {
142
140
  usage: string;
143
141
  host: string;
144
142
  };
145
- declare type SlideUIAnimations = 'unstack' | 'restack';
146
- export declare type NextUISlide = {
147
- questionText?: string;
148
- answerUI?: AnswerUI;
149
- hidden?: boolean;
150
- position?: number;
151
- animationType?: SlideUIAnimations;
152
- isCorrect?: boolean;
153
- endReview?: boolean;
154
- };
155
- export declare type UISlide = {
156
- questionText?: string;
157
- answerUI?: AnswerUI;
158
- hidden?: boolean;
159
- position: number;
160
- animationType?: SlideUIAnimations;
161
- isCorrect?: boolean;
162
- endReview?: boolean;
163
- nextContent?: NextUISlide;
164
- };
165
- export declare type FinishedSlides = {
166
- [key in SlideIndexes]?: true;
167
- };
168
143
  export declare type WithRequired<T, K extends keyof T> = T & {
169
144
  [P in K]-?: T[P];
170
145
  };
@@ -23,4 +23,4 @@ declare type SkillsProps = NoSkillsProps & {
23
23
  listSkills: SkillCard[];
24
24
  };
25
25
  export { SkillsProps };
26
- export declare const mapStateToSkillsProps: (state: StoreState) => SkillsProps | null;
26
+ export declare const mapStateToSkillsProps: (state: StoreState) => SkillsProps;
@@ -1,7 +1,4 @@
1
1
  export var mapStateToSkillsProps = function (state) {
2
- if (!state.data.skills) {
3
- return null;
4
- }
5
2
  return {
6
3
  title: '@todo title',
7
4
  titleNoSkills: '@todo titleNoSkills',
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
1
+ import test from 'ava';
2
+ import map from 'lodash/fp/map';
3
+ import omit from 'lodash/fp/omit';
4
+ import { mapStateToSkillsProps } from '..';
5
+ test('should create initial props when there are no skills on the state', function (t) {
6
+ var state = {
7
+ data: {
8
+ progression: null,
9
+ skills: [],
10
+ slides: {},
11
+ token: '1234'
12
+ },
13
+ ui: {
14
+ currentSlideRef: '',
15
+ navigation: ['loader', 'skills'],
16
+ answers: [],
17
+ slide: {
18
+ validateButton: false
19
+ }
20
+ }
21
+ };
22
+ var props = mapStateToSkillsProps(state);
23
+ t.deepEqual(props, {
24
+ title: '@todo title',
25
+ titleNoSkills: '@todo titleNoSkills',
26
+ textNoSkills: '@todo textNoSkills',
27
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
28
+ isLoading: false,
29
+ isLoadingAriaLabel: '@todo loading',
30
+ listSkills: []
31
+ });
32
+ });
33
+ test('should create initial props when skills on the state', function (t) {
34
+ var state = {
35
+ data: {
36
+ progression: null,
37
+ skills: [
38
+ {
39
+ skillRef: '_skill-ref',
40
+ slidesToReview: 2,
41
+ name: 'skill-test',
42
+ custom: false
43
+ },
44
+ {
45
+ skillRef: '_skill-ref-2',
46
+ slidesToReview: 5,
47
+ name: 'skill-test-2',
48
+ custom: true
49
+ }
50
+ ],
51
+ slides: {},
52
+ token: '1234'
53
+ },
54
+ ui: {
55
+ currentSlideRef: '',
56
+ navigation: ['loader', 'skills'],
57
+ answers: [],
58
+ slide: {
59
+ validateButton: false
60
+ }
61
+ }
62
+ };
63
+ var props = mapStateToSkillsProps(state);
64
+ t.deepEqual(omit('listSkills', props), {
65
+ title: '@todo title',
66
+ titleNoSkills: '@todo titleNoSkills',
67
+ textNoSkills: '@todo textNoSkills',
68
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
69
+ isLoading: false,
70
+ isLoadingAriaLabel: '@todo loading'
71
+ });
72
+ t.deepEqual(map(omit('onClick'), props.listSkills), [
73
+ {
74
+ 'aria-label': '',
75
+ isCustom: false,
76
+ skillTitle: 'skill-test',
77
+ skillAriaLabel: '@todo skill aria label',
78
+ buttonLabel: '@todo button',
79
+ buttonAriaLabel: '@todo button aria label',
80
+ reviseLabel: '@todo revise',
81
+ reviseAriaLabel: '@todo revise aria label'
82
+ },
83
+ {
84
+ 'aria-label': '',
85
+ isCustom: true,
86
+ skillTitle: 'skill-test-2',
87
+ skillAriaLabel: '@todo skill aria label',
88
+ buttonLabel: '@todo button',
89
+ buttonAriaLabel: '@todo button aria label',
90
+ reviseLabel: '@todo revise',
91
+ reviseAriaLabel: '@todo revise aria label'
92
+ }
93
+ ]);
94
+ });
@@ -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 {};
@@ -18,6 +18,7 @@ import reduce from 'lodash/fp/reduce';
18
18
  import set from 'lodash/fp/set';
19
19
  import slice from 'lodash/fp/slice';
20
20
  import toInteger from 'lodash/fp/toInteger';
21
+ import { postAnswer } from '../../actions/api/post-answer';
21
22
  import { mapApiSlideToUi } from './map-api-slide-to-ui';
22
23
  var ICON_VALUES = {
23
24
  right: 'right',
@@ -27,26 +28,31 @@ var ICON_VALUES = {
27
28
  export var initialState = {
28
29
  '0': {
29
30
  hidden: false,
30
- position: 0
31
+ position: 0,
32
+ loading: true
31
33
  },
32
34
  '1': {
33
35
  hidden: false,
34
- position: 1
36
+ position: 1,
37
+ loading: true
35
38
  },
36
39
  '2': {
37
40
  hidden: false,
38
- position: 2
41
+ position: 2,
42
+ loading: true
39
43
  },
40
44
  '3': {
41
45
  hidden: false,
42
- position: 3
46
+ position: 3,
47
+ loading: true
43
48
  },
44
49
  '4': {
45
50
  hidden: false,
46
- position: 4
51
+ position: 4,
52
+ loading: true
47
53
  }
48
54
  };
49
- var getProgressionSlidesRef = function (progression) {
55
+ var getProgressionSlidesRefs = function (progression) {
50
56
  if (progression.state.step.current < 5) {
51
57
  var slideRef = progression.state.nextContent.ref;
52
58
  return concat([slideRef], progression.state.slides);
@@ -58,18 +64,20 @@ var buildStackSlides = function (state, dispatch) {
58
64
  var progression = state.data.progression;
59
65
  if (!currentSlideRef || !progression)
60
66
  return initialState;
61
- var slideRefs = getProgressionSlidesRef(progression);
67
+ var slideRefs = getProgressionSlidesRefs(progression);
62
68
  // @ts-expect-error typescript does not support capped versions of lodash functions
63
69
  var stack = reduce.convert({ cap: false })(function (acc, uiSlide, index) {
64
70
  var slideRef = slideRefs[toInteger(index)];
65
71
  if (!slideRef)
66
72
  return set(index, uiSlide, acc);
67
73
  var slideFromAPI = get(slideRef, state.data.slides);
74
+ if (!slideFromAPI)
75
+ return set(index, uiSlide, acc);
68
76
  var answers = state.ui.answers;
69
77
  var _a = mapApiSlideToUi(dispatch)(slideFromAPI, answers), questionText = _a.questionText, answerUI = _a.answerUI;
70
78
  var parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
71
79
  var parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
72
- var updatedUiSlide = pipe(set(['questionText'], questionText), set(['answerUI'], answerUI), set(['parentContentTitle'], "From \"".concat(parentContentTitle, "\" ").concat(parentContentType)) // TODO translate: -From- .... -Course/chapter-
80
+ var updatedUiSlide = pipe(set('loading', false), set('questionText', questionText), set('answerUI', answerUI), set('parentContentTitle', "From \"".concat(parentContentTitle, "\" ").concat(parentContentType)) // TODO translate: -From- .... -Course/chapter-
73
81
  // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
74
82
  )(uiSlide);
75
83
  return set(index, updatedUiSlide, acc);
@@ -122,9 +130,6 @@ var buildStepItems = function (state) {
122
130
  return steps;
123
131
  };
124
132
  export var mapStateToSlidesProps = function (state, dispatch) {
125
- if (!state.data.slides) {
126
- return null;
127
- }
128
133
  return {
129
134
  header: {
130
135
  mode: '__revision_mode',
@@ -141,10 +146,9 @@ export var mapStateToSlidesProps = function (state, dispatch) {
141
146
  slides: buildStackSlides(state, dispatch),
142
147
  validateButton: {
143
148
  label: '__validate',
144
- disabled: true,
149
+ disabled: !get('ui.slide.validateButton', state),
145
150
  onClick: function () {
146
- // eslint-disable-next-line no-console
147
- console.log('TODO: validate question');
151
+ dispatch(postAnswer);
148
152
  }
149
153
  },
150
154
  correctionPopinProps: undefined,
@@ -1,57 +1,58 @@
1
- import { concat, divide, get, getOr, head, includes, indexOf, isEmpty, map, rangeStep, size, toInteger } from 'lodash/fp';
1
+ import { concat, divide, get, getOr, head, includes, indexOf, isEmpty, map, multiply, pipe, rangeStep, round, size, toInteger, toString as _toString, __ } from 'lodash/fp';
2
2
  import { editAnswer } from '../../actions/ui/answers';
3
- var qcmProps = function (question) {
4
- // TODO: EDIT_CHOICES -> getAnswerValues
5
- var answers = [];
6
- return {
7
- type: 'qcm',
8
- answers: map(function (choice) { return ({
9
- title: choice.label,
10
- selected: includes(choice.label, answers),
11
- // TODO: EDIT_CHOICES
12
- // eslint-disable-next-line no-console
13
- onClick: function () { return console.log('TODO: on choice click'); },
14
- ariaLabel: choice.label
15
- }); },
16
- // TODO: EDIT_CHOICES -> getChoices
17
- question.content.choices)
3
+ var qcmProps = function (dispatch) {
4
+ return function (answers, question) {
5
+ return {
6
+ type: 'qcm',
7
+ answers: map(function (choice) {
8
+ var label = choice.label || '';
9
+ return {
10
+ title: label,
11
+ selected: includes(label, answers),
12
+ onClick: function () {
13
+ dispatch(editAnswer(label));
14
+ },
15
+ ariaLabel: choice.label
16
+ };
17
+ }, question.content.choices)
18
+ };
18
19
  };
19
20
  };
20
- var qcmDragProps = function (question) {
21
- // TODO: EDIT_CHOICES -> getAnswerValues
22
- var answers = [];
23
- return {
24
- type: 'qcmDrag',
25
- answers: map(function (choice) {
26
- var indexInAnswer = indexOf(choice.label, answers);
27
- return {
28
- title: choice.label,
29
- selected: includes(choice.label, answers),
30
- order: indexInAnswer,
31
- // TODO: EDIT_CHOICES
32
- // eslint-disable-next-line no-console
33
- onClick: function () { return console.log('TODO: on choice click'); }
34
- };
35
- // TODO: EDIT_CHOICES -> getChoices
36
- }, question.content.choices)
21
+ var qcmDragProps = function (dispatch) {
22
+ return function (answers, question) {
23
+ return {
24
+ type: 'qcmDrag',
25
+ answers: map(function (choice) {
26
+ var label = choice.label || '';
27
+ var indexInAnswer = indexOf(label, answers);
28
+ return {
29
+ title: label,
30
+ selected: includes(label, answers),
31
+ order: indexInAnswer,
32
+ onClick: function () {
33
+ dispatch(editAnswer(label));
34
+ }
35
+ };
36
+ }, question.content.choices)
37
+ };
37
38
  };
38
39
  };
39
- var qcmGraphicProps = function (question) {
40
- // mock the answers
41
- // TODO: EDIT_CHOICES -> getAnswerValues
42
- var answers = [];
43
- return {
44
- type: 'qcmGraphic',
45
- answers: map(function (choice) { return ({
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: function () { return console.log('TODO: on choice click'); }
52
- }); },
53
- // TODO: EDIT_CHOICES -> getChoices
54
- question.content.choices)
40
+ var qcmGraphicProps = function (dispatch) {
41
+ return function (answers, question) {
42
+ return {
43
+ type: 'qcmGraphic',
44
+ answers: map(function (choice) {
45
+ var label = choice.label || '';
46
+ return {
47
+ title: label,
48
+ image: get('media.src.0.url', choice),
49
+ selected: includes(label, answers),
50
+ onClick: function () {
51
+ dispatch(editAnswer(label));
52
+ }
53
+ };
54
+ }, question.content.choices)
55
+ };
55
56
  };
56
57
  };
57
58
  var templateTextProps = function (choice, index) {
@@ -113,34 +114,34 @@ var basicProps = function (dispatch) {
113
114
  placeholder: question.content.placeholder || '',
114
115
  value: answers[0] || '',
115
116
  onChange: function (text) {
116
- // eslint-disable-next-line no-console
117
- console.log(text);
118
117
  dispatch(editAnswer(text));
119
118
  }
120
119
  };
121
120
  };
122
121
  };
123
- var sliderProps = function (question) {
124
- var values = rangeStep(getOr(1, 'content.step', question), get('content.min', question), get('content.max', question) + 1
125
- // Lodash doesn't infer the type very well here
126
- );
127
- // TODO: EDIT_CHOICES -> getAnswerValues
128
- var answers = [];
129
- var stateValue = head(answers) || question.content.min;
130
- var currentValue = toInteger(stateValue);
131
- var indexValue = indexOf(currentValue, values);
132
- var sliderPosition = divide(indexValue, size(values) - 1);
133
- var unitLabel = get('content.unitLabel', question);
134
- return {
135
- type: 'slider',
136
- placeholder: question.explanation,
137
- minLabel: "".concat(question.content.min, " ").concat(unitLabel),
138
- maxLabel: "".concat(question.content.max, " ").concat(unitLabel),
139
- title: "".concat(currentValue, " ").concat(question.content.unitLabel),
140
- value: sliderPosition,
141
- // TODO: EDIT_CHOICES
142
- // eslint-disable-next-line no-console
143
- onChange: function () { return console.log('TODO: on choice change'); }
122
+ var sliderProps = function (dispatch) {
123
+ return function (answers, question) {
124
+ var values = rangeStep(getOr(1, 'content.step', question), get('content.min', question), get('content.max', question) + 1
125
+ // Lodash doesn't infer the type very well here
126
+ );
127
+ var stateValue = head(answers) || question.content.min;
128
+ var currentValue = toInteger(stateValue);
129
+ var indexValue = indexOf(currentValue, values);
130
+ var maxValue = size(values) - 1;
131
+ var sliderPosition = divide(indexValue, maxValue);
132
+ var unitLabel = get('content.unitLabel', question);
133
+ return {
134
+ type: 'slider',
135
+ placeholder: question.explanation,
136
+ minLabel: "".concat(question.content.min, " ").concat(unitLabel),
137
+ maxLabel: "".concat(question.content.max, " ").concat(unitLabel),
138
+ title: "".concat(currentValue, " ").concat(question.content.unitLabel),
139
+ value: sliderPosition,
140
+ onChange: function (position) {
141
+ var newValue = pipe(multiply(maxValue), round, get(__, values), _toString)(position);
142
+ dispatch(editAnswer(newValue));
143
+ }
144
+ };
144
145
  };
145
146
  };
146
147
  export var getQuestionType = function (question) { return question.type; };
@@ -149,17 +150,17 @@ var getAnswerUIModel = function (question, answers, dispatch) {
149
150
  var type = getQuestionType(question);
150
151
  switch (type) {
151
152
  case 'qcm':
152
- return qcmProps(question);
153
+ return qcmProps(dispatch)(answers, question);
153
154
  case 'qcmGraphic':
154
- return qcmGraphicProps(question);
155
+ return qcmGraphicProps(dispatch)(answers, question);
155
156
  case 'qcmDrag':
156
- return qcmDragProps(question);
157
+ return qcmDragProps(dispatch)(answers, question);
157
158
  case 'basic':
158
159
  return basicProps(dispatch)(answers, question);
159
160
  case 'template':
160
161
  return templateProps(question);
161
162
  case 'slider':
162
- return sliderProps(question);
163
+ return sliderProps(dispatch)(answers, question);
163
164
  default:
164
165
  throw new Error("".concat(type, " is not an handled question.type"));
165
166
  }
@@ -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>;