@coorpacademy/app-review 0.46.14-alpha.9 → 0.46.14-react18.80

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 (119) hide show
  1. package/es/reducers/data/corrections.d.ts +1 -1
  2. package/es/reducers/data/current-skill.d.ts +1 -1
  3. package/es/reducers/data/index.d.ts +3 -3
  4. package/es/reducers/data/progression.d.ts +1 -1
  5. package/es/reducers/data/rank.d.ts +1 -1
  6. package/es/reducers/data/slides.d.ts +1 -1
  7. package/es/reducers/data/token.d.ts +1 -1
  8. package/es/reducers/data/videos.d.ts +1 -1
  9. package/es/reducers/index.d.ts +3 -7
  10. package/es/reducers/ui/answers.d.ts +1 -1
  11. package/es/reducers/ui/current-slide-ref.d.ts +1 -1
  12. package/es/reducers/ui/index.d.ts +1 -5
  13. package/es/reducers/ui/navigation.d.ts +1 -1
  14. package/es/reducers/ui/positions.d.ts +1 -1
  15. package/es/reducers/ui/quit-popin.d.ts +1 -1
  16. package/es/reducers/ui/show-button-revising.d.ts +1 -1
  17. package/es/reducers/ui/show-congrats.d.ts +1 -1
  18. package/es/reducers/ui/slide.d.ts +1 -1
  19. package/lib/reducers/data/corrections.d.ts +1 -1
  20. package/lib/reducers/data/current-skill.d.ts +1 -1
  21. package/lib/reducers/data/index.d.ts +3 -3
  22. package/lib/reducers/data/progression.d.ts +1 -1
  23. package/lib/reducers/data/rank.d.ts +1 -1
  24. package/lib/reducers/data/slides.d.ts +1 -1
  25. package/lib/reducers/data/token.d.ts +1 -1
  26. package/lib/reducers/data/videos.d.ts +1 -1
  27. package/lib/reducers/index.d.ts +3 -7
  28. package/lib/reducers/ui/answers.d.ts +1 -1
  29. package/lib/reducers/ui/current-slide-ref.d.ts +1 -1
  30. package/lib/reducers/ui/index.d.ts +1 -5
  31. package/lib/reducers/ui/navigation.d.ts +1 -1
  32. package/lib/reducers/ui/positions.d.ts +1 -1
  33. package/lib/reducers/ui/quit-popin.d.ts +1 -1
  34. package/lib/reducers/ui/show-button-revising.d.ts +1 -1
  35. package/lib/reducers/ui/show-congrats.d.ts +1 -1
  36. package/lib/reducers/ui/slide.d.ts +1 -1
  37. package/package.json +19 -10
  38. package/es/actions/api/fetch-correction.js +0 -18
  39. package/es/actions/api/fetch-rank.js +0 -34
  40. package/es/actions/api/fetch-skill.js +0 -16
  41. package/es/actions/api/fetch-slide.js +0 -31
  42. package/es/actions/api/fetch-slides-to-review-by-skill-ref.js +0 -32
  43. package/es/actions/api/fetch-video-props.js +0 -34
  44. package/es/actions/api/post-answer.js +0 -36
  45. package/es/actions/api/post-progression.js +0 -25
  46. package/es/actions/data/token.js +0 -5
  47. package/es/actions/ui/answers.js +0 -54
  48. package/es/actions/ui/navigation.js +0 -26
  49. package/es/actions/ui/next-slide.js +0 -33
  50. package/es/actions/ui/quit-popin.js +0 -8
  51. package/es/actions/ui/show-button-revising.js +0 -6
  52. package/es/actions/ui/slides.js +0 -10
  53. package/es/common/index.js +0 -10
  54. package/es/configure-store.js +0 -26
  55. package/es/helpers/css-register.js +0 -2
  56. package/es/index.js +0 -48
  57. package/es/reducers/data/corrections.js +0 -25
  58. package/es/reducers/data/current-skill.js +0 -13
  59. package/es/reducers/data/index.js +0 -17
  60. package/es/reducers/data/progression.js +0 -20
  61. package/es/reducers/data/rank.js +0 -27
  62. package/es/reducers/data/slides.js +0 -20
  63. package/es/reducers/data/token.js +0 -11
  64. package/es/reducers/data/videos.js +0 -33
  65. package/es/reducers/index.js +0 -7
  66. package/es/reducers/ui/answers.js +0 -28
  67. package/es/reducers/ui/current-slide-ref.js +0 -21
  68. package/es/reducers/ui/index.js +0 -19
  69. package/es/reducers/ui/navigation.js +0 -18
  70. package/es/reducers/ui/positions.js +0 -30
  71. package/es/reducers/ui/quit-popin.js +0 -16
  72. package/es/reducers/ui/show-button-revising.js +0 -17
  73. package/es/reducers/ui/show-congrats.js +0 -20
  74. package/es/reducers/ui/slide.js +0 -52
  75. package/es/types/common.js +0 -1
  76. package/es/types/slides.js +0 -1
  77. package/es/views/slides/index.js +0 -387
  78. package/es/views/slides/map-api-slide-to-ui.js +0 -177
  79. package/lib/actions/api/fetch-correction.js +0 -25
  80. package/lib/actions/api/fetch-rank.js +0 -43
  81. package/lib/actions/api/fetch-skill.js +0 -23
  82. package/lib/actions/api/fetch-slide.js +0 -38
  83. package/lib/actions/api/fetch-slides-to-review-by-skill-ref.js +0 -39
  84. package/lib/actions/api/fetch-video-props.js +0 -43
  85. package/lib/actions/api/post-answer.js +0 -43
  86. package/lib/actions/api/post-progression.js +0 -32
  87. package/lib/actions/data/token.js +0 -9
  88. package/lib/actions/ui/answers.js +0 -61
  89. package/lib/actions/ui/navigation.js +0 -31
  90. package/lib/actions/ui/next-slide.js +0 -40
  91. package/lib/actions/ui/quit-popin.js +0 -11
  92. package/lib/actions/ui/show-button-revising.js +0 -10
  93. package/lib/actions/ui/slides.js +0 -14
  94. package/lib/common/index.js +0 -17
  95. package/lib/configure-store.js +0 -32
  96. package/lib/helpers/css-register.js +0 -7
  97. package/lib/index.js +0 -76
  98. package/lib/reducers/data/corrections.js +0 -30
  99. package/lib/reducers/data/current-skill.js +0 -15
  100. package/lib/reducers/data/index.js +0 -22
  101. package/lib/reducers/data/progression.js +0 -22
  102. package/lib/reducers/data/rank.js +0 -32
  103. package/lib/reducers/data/slides.js +0 -26
  104. package/lib/reducers/data/token.js +0 -13
  105. package/lib/reducers/data/videos.js +0 -36
  106. package/lib/reducers/index.js +0 -12
  107. package/lib/reducers/ui/answers.js +0 -31
  108. package/lib/reducers/ui/current-slide-ref.js +0 -23
  109. package/lib/reducers/ui/index.js +0 -24
  110. package/lib/reducers/ui/navigation.js +0 -20
  111. package/lib/reducers/ui/positions.js +0 -35
  112. package/lib/reducers/ui/quit-popin.js +0 -18
  113. package/lib/reducers/ui/show-button-revising.js +0 -19
  114. package/lib/reducers/ui/show-congrats.js +0 -22
  115. package/lib/reducers/ui/slide.js +0 -58
  116. package/lib/types/common.js +0 -2
  117. package/lib/types/slides.js +0 -2
  118. package/lib/views/slides/index.js +0 -395
  119. package/lib/views/slides/map-api-slide-to-ui.js +0 -182
@@ -1,395 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapStateToSlidesProps = exports.buildStepItems = exports.initialState = void 0;
7
- const findLast_1 = __importDefault(require("lodash/fp/findLast"));
8
- const get_1 = __importDefault(require("lodash/fp/get"));
9
- const getOr_1 = __importDefault(require("lodash/fp/getOr"));
10
- const last_1 = __importDefault(require("lodash/fp/last"));
11
- const reduce_1 = __importDefault(require("lodash/fp/reduce"));
12
- const set_1 = __importDefault(require("lodash/fp/set"));
13
- const toInteger_1 = __importDefault(require("lodash/fp/toInteger"));
14
- const join_1 = __importDefault(require("lodash/fp/join"));
15
- const quit_popin_1 = require("../../actions/ui/quit-popin");
16
- const common_1 = require("../../common");
17
- const post_answer_1 = require("../../actions/api/post-answer");
18
- const post_progression_1 = require("../../actions/api/post-progression");
19
- const next_slide_1 = require("../../actions/ui/next-slide");
20
- const map_api_slide_to_ui_1 = require("./map-api-slide-to-ui");
21
- const ICON_VALUES = {
22
- right: 'right',
23
- wrong: 'wrong',
24
- 'no-answer': 'no-answer'
25
- };
26
- const buildConfettiAnimation = (translate) => ({
27
- 'aria-label': translate('Congratulations confetti animation'),
28
- 'data-name': 'default-lottie',
29
- className: undefined,
30
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/confetti.json',
31
- loop: undefined,
32
- autoplay: true,
33
- rendererSettings: {
34
- hideOnTransparent: false
35
- }
36
- });
37
- exports.initialState = {
38
- '0': {
39
- position: 0,
40
- loading: true
41
- },
42
- '1': {
43
- position: 1,
44
- loading: true
45
- },
46
- '2': {
47
- position: 2,
48
- loading: true
49
- },
50
- '3': {
51
- position: 3,
52
- loading: true
53
- },
54
- '4': {
55
- position: 4,
56
- loading: true
57
- }
58
- };
59
- const getCurrentSlideRef = (state) => {
60
- const currentSlideRef = (0, get_1.default)(['ui', 'currentSlideRef'], state);
61
- const endReview = currentSlideRef === 'successExitNode';
62
- if (!endReview)
63
- return currentSlideRef;
64
- const progression = state.data.progression;
65
- const content = progression.state.content;
66
- return content.ref;
67
- };
68
- const isLastSlideAnswered = (slidesRef, slideRef) => {
69
- return (0, last_1.default)(slidesRef) === slideRef;
70
- };
71
- const getSlideMedia = (state, slideFromAPI) => {
72
- const media = (0, get_1.default)(['question', 'medias', '0'], slideFromAPI);
73
- if (!media)
74
- return;
75
- const { type } = media;
76
- const resource = (0, get_1.default)(['src', '0'], media);
77
- switch (type) {
78
- case 'img':
79
- case 'audio': {
80
- const mediaProps = {
81
- ...resource,
82
- type,
83
- url: (0, get_1.default)('url', resource)
84
- };
85
- return mediaProps;
86
- }
87
- case 'video': {
88
- const videoProps = (0, get_1.default)(['data', 'videos', slideFromAPI._id, 'src', '0'], state);
89
- return videoProps;
90
- }
91
- }
92
- };
93
- const buildStackSlides = (state, dispatch, options) => {
94
- const { translate } = options;
95
- const currentSlideRef = getCurrentSlideRef(state);
96
- const progression = state.data.progression;
97
- if (!currentSlideRef || !progression)
98
- return exports.initialState;
99
- const slideRefs = (0, common_1.getProgressionSlidesRefs)(progression);
100
- // @ts-expect-error typescript does not support capped versions of lodash functions
101
- const stack = reduce_1.default.convert({ cap: false })((acc, uiSlide, _index) => {
102
- const index = (0, toInteger_1.default)(_index);
103
- const slideRef = slideRefs[index];
104
- const lastAnsweredSlideRef = isLastSlideAnswered(progression.state.slides, slideRef);
105
- const positions = state.ui.positions;
106
- // when unstack the last answered slide (position -1), we set the position to 0 only during the animation
107
- // to avoid to hide the slide (caused by the position -1).
108
- const position = lastAnsweredSlideRef && positions[index] === -1 ? 0 : positions[index];
109
- if (!slideRef)
110
- return (0, set_1.default)(index, { ...uiSlide, position }, acc);
111
- const slideFromAPI = (0, get_1.default)(slideRef, state.data.slides);
112
- if (!slideFromAPI)
113
- return (0, set_1.default)(index, { ...uiSlide, position }, acc);
114
- const answers = (0, getOr_1.default)([], ['ui', 'answers', slideRef], state);
115
- const media = getSlideMedia(state, slideFromAPI);
116
- const { questionText, answerUI } = (0, map_api_slide_to_ui_1.mapApiSlideToUi)(dispatch, translate)(slideFromAPI, answers, media);
117
- const { title: parentContentTitle, type: parentContentType } = slideFromAPI.parentContentTitle;
118
- const isCurrentSlideRef = currentSlideRef === slideRef;
119
- const slideUI = (0, get_1.default)(['ui', 'slide', slideRef], state);
120
- const animateCorrectionPopin = isCurrentSlideRef && slideUI.animateCorrectionPopin;
121
- const showCorrectionPopin = isCurrentSlideRef && slideUI.showCorrectionPopin;
122
- const animationType = lastAnsweredSlideRef ? slideUI.animationType : undefined;
123
- const disabledContent = (0, get_1.default)(['ui', 'slide', slideRef, 'pendingAnswerRequest'], state);
124
- const updatedUiSlide = {
125
- ...uiSlide,
126
- position,
127
- showCorrectionPopin,
128
- animateCorrectionPopin,
129
- loading: false,
130
- questionText,
131
- answerUI,
132
- disabledContent,
133
- parentContentTitle: translate('Content Parent Title', {
134
- contentTitle: parentContentTitle,
135
- contentType: parentContentType
136
- }),
137
- animationType
138
- };
139
- return (0, set_1.default)(index, updatedUiSlide, acc);
140
- }, exports.initialState, exports.initialState);
141
- return stack;
142
- };
143
- const getIconForCurrentStep = (slideRef, lastGivenAnswerForSlide, currentSlideRef, lastGivenAnswer) => {
144
- if (slideRef !== currentSlideRef)
145
- return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
146
- if (lastGivenAnswer.slideRef !== slideRef)
147
- return 'no-answer';
148
- return lastGivenAnswerForSlide.isCorrect ? 'right' : 'wrong';
149
- };
150
- const buildStepItems = (state) => {
151
- const { progression } = state.data;
152
- const { currentSlideRef } = state.ui;
153
- if (!progression)
154
- return [];
155
- const defaultProps = [
156
- {
157
- icon: 'no-answer',
158
- current: true,
159
- value: '1'
160
- },
161
- {
162
- icon: 'no-answer',
163
- current: false,
164
- value: '2'
165
- },
166
- {
167
- icon: 'no-answer',
168
- current: false,
169
- value: '3'
170
- },
171
- {
172
- icon: 'no-answer',
173
- current: false,
174
- value: '4'
175
- },
176
- {
177
- icon: 'no-answer',
178
- current: false,
179
- value: '5'
180
- }
181
- ];
182
- const slideRefs = (0, common_1.getProgressionSlidesRefs)(progression);
183
- const allAnswers = progression.state.allAnswers;
184
- const step = progression.state.step;
185
- const nextContentRef = progression.state.nextContent.ref;
186
- const lastGivenAnswer = (0, last_1.default)(allAnswers);
187
- if (!lastGivenAnswer)
188
- return defaultProps;
189
- const steps = defaultProps.map((stepItem, index) => {
190
- const slideRef = slideRefs[index];
191
- if (!slideRef)
192
- return stepItem; // non fecthed slide pour given index
193
- const lastGivenAnswerForSlide = (0, findLast_1.default)(answer => answer.slideRef === slideRef, allAnswers);
194
- // never answered slide
195
- if (!lastGivenAnswerForSlide) {
196
- return {
197
- ...stepItem,
198
- current: nextContentRef === currentSlideRef && step.current === index + 1
199
- };
200
- }
201
- // already answered slide, we computed based on the lastGivenAnswer
202
- return {
203
- ...stepItem,
204
- icon: getIconForCurrentStep(slideRef, lastGivenAnswerForSlide, currentSlideRef, lastGivenAnswer),
205
- current: lastGivenAnswerForSlide.slideRef === currentSlideRef
206
- };
207
- });
208
- return steps;
209
- };
210
- exports.buildStepItems = buildStepItems;
211
- const getCorrectionPopinProps = (dispatch) => (isCorrect, correctAnswer, klf, translate, endReview) => {
212
- const nextLabel = endReview ? translate('Continue') : translate('Next Question');
213
- return {
214
- klf: isCorrect
215
- ? undefined
216
- : {
217
- label: translate('KLF'),
218
- tooltip: klf
219
- },
220
- resultLabel: isCorrect ? translate('Correct Answer') : translate('Wrong Answer'),
221
- information: {
222
- label: isCorrect ? translate('KLF') : translate('Correct Answer'),
223
- message: isCorrect ? klf : (0, join_1.default)(', ', correctAnswer)
224
- },
225
- next: {
226
- 'aria-label': nextLabel,
227
- label: nextLabel,
228
- onClick: () => {
229
- dispatch(next_slide_1.nextSlide);
230
- }
231
- },
232
- type: isCorrect ? 'right' : 'wrong'
233
- };
234
- };
235
- const buildQuitPopinProps = (dispatch) => (onQuitClick, translate, skin) => {
236
- return {
237
- content: translate('Quit Title'),
238
- icon: `MoonRocket`,
239
- mode: 'alert',
240
- descriptionText: translate('Quit Description Text'),
241
- firstButton: {
242
- label: translate('Stop learning'),
243
- type: 'tertiary',
244
- customStyle: {
245
- color: '#ED3436'
246
- },
247
- handleOnclick: () => {
248
- dispatch(quit_popin_1.closeQuitPopin);
249
- onQuitClick();
250
- },
251
- 'aria-label': translate('Stop learning')
252
- },
253
- secondButton: {
254
- label: translate('Continue learning'),
255
- type: 'primary',
256
- customStyle: {
257
- backgroundColor: (0, get_1.default)(['common', 'primary'], skin)
258
- },
259
- handleOnclick: () => {
260
- dispatch(quit_popin_1.closeQuitPopin);
261
- },
262
- 'aria-label': translate('Continue learning')
263
- }
264
- };
265
- };
266
- const buildRankCard = (rank, translate) => {
267
- return {
268
- 'aria-label': 'Review Card Congrats Container',
269
- 'data-name': 'card-rank',
270
- animationLottie: {
271
- 'aria-label': translate('New rank animation'),
272
- 'data-name': 'default-lottie',
273
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/rank.json',
274
- loop: true,
275
- autoplay: true
276
- },
277
- cardType: 'card-rank',
278
- iconAriaLabel: 'Image without information',
279
- className: undefined,
280
- reviewCardTitle: translate('You are now'),
281
- reviewCardValue: `${rank}`,
282
- rankSuffix: 'th',
283
- timerAnimation: 200
284
- };
285
- };
286
- const buildCongratsProps = (state, dispatch, options) => {
287
- if (!state.ui.showCongrats)
288
- return;
289
- const { translate, onQuitClick } = options;
290
- const progression = state.data.progression;
291
- const stars = progression.state.stars;
292
- const cardCongratsStar = {
293
- 'aria-label': 'Review Card Congrats Container',
294
- 'data-name': 'card-star',
295
- animationLottie: {
296
- 'aria-label': translate('Acquired stars animation'),
297
- 'data-name': 'default-lottie',
298
- className: undefined,
299
- animationSrc: 'https://static-staging.coorpacademy.com/animations/review/star.json',
300
- loop: false,
301
- autoplay: undefined,
302
- rendererSettings: {
303
- hideOnTransparent: false
304
- }
305
- },
306
- iconAriaLabel: 'Image without information',
307
- className: undefined,
308
- cardType: 'card-star',
309
- reviewCardTitle: translate('You have won'),
310
- reviewCardValue: `${stars}`,
311
- timerAnimation: 200
312
- };
313
- const { start, end } = state.data.rank;
314
- const newRank = start - end;
315
- const cardCongratsRank = !Number.isNaN(newRank) && newRank > 0 ? buildRankCard(end, translate) : undefined;
316
- const skillRef = progression.content.ref;
317
- const buttonRevising = state.ui.showButtonRevising
318
- ? {
319
- 'aria-label': translate('Continue reviewing'),
320
- label: translate('Continue reviewing'),
321
- onClick: () => {
322
- dispatch((0, post_progression_1.postProgression)(skillRef));
323
- },
324
- type: 'tertiary'
325
- }
326
- : undefined;
327
- const buttonRevisingSkill = {
328
- 'aria-label': translate('Revise another skill'),
329
- label: translate('Revise another skill'),
330
- onClick: onQuitClick,
331
- type: 'primary'
332
- };
333
- return {
334
- 'aria-label': 'Review Congratulations',
335
- 'data-name': 'review-congrats',
336
- animationLottie: buildConfettiAnimation(translate),
337
- title: translate('Congratulations!'),
338
- cardCongratsStar,
339
- cardCongratsRank,
340
- buttonRevising,
341
- buttonRevisingSkill
342
- };
343
- };
344
- const isEndOfProgression = (progression) => {
345
- if (!progression)
346
- return false;
347
- return progression.state.nextContent.ref === 'successExitNode';
348
- };
349
- const mapStateToSlidesProps = (state, dispatch, options) => {
350
- const { translate, onQuitClick, skin, backgroundImage } = options;
351
- const currentSlideRef = getCurrentSlideRef(state);
352
- const endReview = isEndOfProgression(state.data.progression);
353
- const correction = (0, get_1.default)(['data', 'corrections', currentSlideRef], state);
354
- const isCorrect = (0, get_1.default)(['data', 'progression', 'state', 'isCorrect'], state);
355
- const klf = (0, getOr_1.default)('', ['data', 'slides', currentSlideRef, 'klf'], state);
356
- const showQuitPopin = (0, get_1.default)(['ui', 'showQuitPopin'], state);
357
- const showCongrats = (0, get_1.default)(['ui', 'showCongrats'], state);
358
- const skillName = (0, getOr_1.default)('', ['data', 'currentSkill', 'name'], state);
359
- return {
360
- header: {
361
- mode: translate('Review Title'),
362
- skillName,
363
- onQuitClick: showCongrats
364
- ? onQuitClick
365
- : () => {
366
- dispatch(quit_popin_1.openQuitPopin);
367
- },
368
- 'aria-label': 'aria-header-wrapper',
369
- closeButtonAriaLabel: 'aria-close-button',
370
- steps: (0, exports.buildStepItems)(state),
371
- hiddenSteps: showCongrats
372
- },
373
- stack: state.data.progression
374
- ? {
375
- slides: buildStackSlides(state, dispatch, options),
376
- validateButton: {
377
- label: translate('Validate'),
378
- disabled: !(0, get_1.default)(['ui', 'slide', currentSlideRef, 'validateButton'], state),
379
- onClick: () => {
380
- dispatch(post_answer_1.postAnswer);
381
- }
382
- },
383
- correctionPopinProps: correction &&
384
- getCorrectionPopinProps(dispatch)(isCorrect, correction.correctAnswer, klf, translate, endReview),
385
- endReview: endReview && state.ui.showCongrats
386
- }
387
- : null,
388
- backgroundImage,
389
- congrats: buildCongratsProps(state, dispatch, options),
390
- quitPopin: showQuitPopin
391
- ? buildQuitPopinProps(dispatch)(onQuitClick, translate, skin)
392
- : undefined
393
- };
394
- };
395
- exports.mapStateToSlidesProps = mapStateToSlidesProps;
@@ -1,182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapApiSlideToUi = exports.getQuestionType = void 0;
4
- const fp_1 = require("lodash/fp");
5
- const answers_1 = require("../../actions/ui/answers");
6
- const qcmProps = (dispatch) => (answers, question) => {
7
- return {
8
- type: 'qcm',
9
- answers: (0, fp_1.map)(choice => {
10
- const label = (0, fp_1.getOr)('', 'label', choice);
11
- return {
12
- title: label,
13
- selected: (0, fp_1.includes)(label, answers),
14
- onClick: () => {
15
- dispatch((0, answers_1.editAnswer)([label]));
16
- },
17
- 'aria-label': label
18
- };
19
- }, question.content.choices)
20
- };
21
- };
22
- const qcmDragProps = (dispatch) => (answers, question) => {
23
- return {
24
- type: 'qcmDrag',
25
- answers: (0, fp_1.map)(choice => {
26
- const label = (0, fp_1.getOr)('', 'label', choice);
27
- const indexInAnswer = (0, fp_1.indexOf)(label, answers);
28
- return {
29
- title: label,
30
- selected: (0, fp_1.includes)(label, answers),
31
- order: indexInAnswer,
32
- onClick: () => {
33
- dispatch((0, answers_1.editAnswer)([label]));
34
- }
35
- };
36
- }, question.content.choices)
37
- };
38
- };
39
- const qcmGraphicProps = (dispatch) => (answers, question) => {
40
- return {
41
- type: 'qcmGraphic',
42
- answers: (0, fp_1.map)(choice => {
43
- const label = (0, fp_1.getOr)('', 'label', choice);
44
- return {
45
- title: label,
46
- image: (0, fp_1.get)('media.src.0.url', choice),
47
- selected: (0, fp_1.includes)(label, answers),
48
- onClick: () => {
49
- dispatch((0, answers_1.editAnswer)([label]));
50
- },
51
- ariaLabel: label
52
- };
53
- }, question.content.choices)
54
- };
55
- };
56
- const updateTemplateAnswer = (text, _answers, index, max) => {
57
- const answers = (0, fp_1.isEmpty)(_answers) ? (0, fp_1.times)((0, fp_1.constant)(undefined), max) : _answers;
58
- return (0, fp_1.map)(a => ((0, fp_1.isNil)(a) ? '' : a), (0, fp_1.set)(index, text, answers));
59
- };
60
- const templateTextProps = (dispatch, translate, answers, choice, index, maxLength) => {
61
- return {
62
- type: 'text',
63
- name: (0, fp_1.getOr)('', 'name', choice),
64
- placeholder: translate('Type here'),
65
- value: (0, fp_1.get)(index, answers),
66
- onChange: (text) => {
67
- const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
68
- dispatch((0, answers_1.editAnswer)(newAnswers));
69
- }
70
- };
71
- };
72
- const templateSelectProps = (dispatch, translate, answers, choice, index, maxLength) => {
73
- const answer = (0, fp_1.get)(index, answers);
74
- const temporaryOption = {
75
- name: translate('Select an answer'),
76
- value: '',
77
- validOption: false,
78
- selected: true
79
- };
80
- const selectOptions = choice.items.map((item) => {
81
- const itemText = (0, fp_1.getOr)('', 'text', item);
82
- return {
83
- name: itemText,
84
- value: itemText,
85
- validOption: true,
86
- selected: itemText === answer
87
- };
88
- });
89
- return {
90
- type: 'select',
91
- name: (0, fp_1.getOr)('', 'name', choice),
92
- onChange: (text) => {
93
- const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
94
- dispatch((0, answers_1.editAnswer)(newAnswers));
95
- },
96
- options: (0, fp_1.isEmpty)(answer) ? (0, fp_1.concat)([temporaryOption], selectOptions) : selectOptions,
97
- 'aria-label': translate('Select an answer')
98
- };
99
- };
100
- const templateProps = (dispatch, translate) => (answers, question) => {
101
- const choices = question.content.choices;
102
- const maxLength = (0, fp_1.size)(choices);
103
- return {
104
- type: 'template',
105
- template: (0, fp_1.get)('content.template', question),
106
- answers: choices.map((choice, index) => choice.type === 'text'
107
- ? templateTextProps(dispatch, translate, answers, choice, index, maxLength)
108
- : templateSelectProps(dispatch, translate, answers, choice, index, maxLength))
109
- };
110
- };
111
- const basicProps = (dispatch) => (answers, question) => {
112
- return {
113
- type: 'freeText',
114
- placeholder: (0, fp_1.getOr)('', 'content.placeholder', question),
115
- value: (0, fp_1.getOr)('', '0', answers),
116
- onChange: (text) => {
117
- dispatch((0, answers_1.editAnswer)([text]));
118
- }
119
- };
120
- };
121
- const sliderProps = (dispatch) => (answers, question) => {
122
- const values = (0, fp_1.rangeStep)((0, fp_1.getOr)(1, 'content.step', question), (0, fp_1.get)('content.min', question), (0, fp_1.get)('content.max', question) + 1
123
- // Lodash doesn't infer the type very well here
124
- );
125
- const stateValue = (0, fp_1.head)(answers) || question.content.min;
126
- const currentValue = (0, fp_1.toInteger)(stateValue);
127
- const indexValue = (0, fp_1.indexOf)(currentValue, values);
128
- const maxValue = (0, fp_1.size)(values) - 1;
129
- const sliderPosition = (0, fp_1.divide)(indexValue, maxValue);
130
- const unitLabel = (0, fp_1.get)('content.unitLabel', question);
131
- return {
132
- type: 'slider',
133
- placeholder: question.explanation,
134
- minLabel: `${question.content.min} ${unitLabel}`,
135
- maxLabel: `${question.content.max} ${unitLabel}`,
136
- title: `${currentValue} ${question.content.unitLabel}`,
137
- value: sliderPosition,
138
- onChange: (position) => {
139
- // atom/range handler
140
- const newValue = (0, fp_1.pipe)((0, fp_1.multiply)(maxValue), fp_1.round, (0, fp_1.get)(fp_1.__, values), fp_1.toString)(position);
141
- dispatch((0, answers_1.editAnswer)([newValue]));
142
- },
143
- onSliderChange: (newValue) => {
144
- // mobile/slider handler
145
- dispatch((0, answers_1.editAnswer)([`${newValue}`]));
146
- }
147
- };
148
- };
149
- const getQuestionType = (question) => question.type;
150
- exports.getQuestionType = getQuestionType;
151
- const getHelp = (slide) => (0, fp_1.get)('question.explanation', slide);
152
- const getAnswerUIModel = (question, answers, dispatch, translate) => {
153
- const type = (0, exports.getQuestionType)(question);
154
- switch (type) {
155
- case 'qcm':
156
- return qcmProps(dispatch)(answers, question);
157
- case 'qcmGraphic':
158
- return qcmGraphicProps(dispatch)(answers, question);
159
- case 'qcmDrag':
160
- return qcmDragProps(dispatch)(answers, question);
161
- case 'basic':
162
- return basicProps(dispatch)(answers, question);
163
- case 'template':
164
- return templateProps(dispatch, translate)(answers, question);
165
- case 'slider':
166
- return sliderProps(dispatch)(answers, question);
167
- default:
168
- throw new Error(`${type} is not an handled question.type`);
169
- }
170
- };
171
- const mapApiSlideToUi = (dispatch, translate) => (slide, answers, media) => {
172
- const questionText = (0, fp_1.getOr)('', 'question.header', slide);
173
- return {
174
- questionText,
175
- answerUI: {
176
- model: getAnswerUIModel(slide.question, answers, dispatch, translate),
177
- help: getHelp(slide),
178
- media
179
- }
180
- };
181
- };
182
- exports.mapApiSlideToUi = mapApiSlideToUi;