@coorpacademy/app-review 0.1.14 → 0.1.16
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.
- package/es/actions/api/fetch-skills.d.ts +4 -6
- package/es/actions/api/fetch-skills.js +7 -4
- package/es/actions/api/fetch-slide.d.ts +14 -7
- package/es/actions/api/fetch-slide.js +27 -4
- package/es/actions/api/post-progression.d.ts +4 -6
- package/es/actions/api/post-progression.js +13 -9
- package/es/actions/api/test/create-test-store.d.ts +5 -0
- package/es/actions/api/test/create-test-store.js +16 -0
- package/es/actions/api/test/fetch-skills.test.js +54 -0
- package/es/actions/api/test/fetch-slide.test.js +61 -0
- package/es/actions/api/test/post-progression.test.js +102 -0
- package/es/actions/index.d.ts +1 -10
- package/es/actions/ui/answers.d.ts +7 -0
- package/es/actions/ui/answers.js +7 -0
- package/es/actions/ui/is-fetching.js +0 -2
- package/es/actions/ui/slides.d.ts +26 -0
- package/es/actions/ui/slides.js +9 -0
- package/es/common/index.d.ts +3 -1
- package/es/common/index.js +3 -1
- package/es/fixtures/qcm-slide.d.ts +2 -2
- package/es/fixtures/temp-fixture.d.ts +2 -2
- package/es/index.js +22 -92
- package/es/reducers/data/index.d.ts +2 -2
- package/es/reducers/data/progression.d.ts +3 -16
- package/es/reducers/data/progression.js +3 -22
- package/es/reducers/data/slides.d.ts +5 -6
- package/es/reducers/data/slides.js +9 -108
- package/es/reducers/data/test/progression.test.js +38 -0
- package/es/reducers/data/test/skills.test.js +12 -0
- package/es/reducers/data/test/slides.test.js +20 -0
- package/es/reducers/data/test/token.test.js +11 -0
- package/es/reducers/index.d.ts +3 -4
- package/es/reducers/ui/answers.d.ts +4 -0
- package/es/reducers/ui/{review-status.js → answers.js} +3 -3
- package/es/reducers/ui/current-slide-ref.d.ts +4 -0
- package/es/reducers/ui/current-slide-ref.js +13 -0
- package/es/reducers/ui/index.d.ts +7 -10
- package/es/reducers/ui/index.js +4 -6
- package/es/reducers/ui/test/answers.test.js +11 -0
- package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
- package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
- package/es/reducers/ui/test/navigation.test.d.ts +1 -0
- package/es/reducers/ui/test/navigation.test.js +15 -0
- package/es/services/fetch-slide.js +1 -1
- package/es/services/index.js +3 -1
- package/es/services/post-answer.d.ts +2 -0
- package/es/services/post-answer.js +18 -0
- package/es/services/test/fetch-slide.test.d.ts +1 -0
- package/es/services/test/fetch-slide.test.js +22 -0
- package/es/services/test/post-answer.test.d.ts +1 -0
- package/es/services/test/post-answer.test.js +57 -0
- package/es/services/test/post-progression.test.js +14 -4
- package/es/test/util/services.mock.js +46 -4
- package/es/types/common.d.ts +61 -30
- package/es/types/common.js +0 -5
- package/es/types/slides.d.ts +0 -4
- package/{lib/types/views/skills.d.ts → es/views/skills/index.d.ts} +2 -0
- package/es/views/skills/index.js +25 -0
- package/es/views/slides/index.d.ts +79 -0
- package/es/views/slides/index.js +151 -0
- package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
- package/es/views/slides/map-api-slide-to-ui.js +172 -0
- package/es/views/slides/test/fixtures/free-text.d.ts +3 -0
- package/es/views/slides/test/fixtures/free-text.js +38 -0
- package/es/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
- package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
- package/es/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
- package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
- package/es/views/slides/test/fixtures/qcm.d.ts +3 -0
- package/es/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
- package/es/views/slides/test/fixtures/select-template.d.ts +3 -0
- package/es/views/slides/test/fixtures/select-template.js +92 -0
- package/es/views/slides/test/fixtures/slider.d.ts +3 -0
- package/es/views/slides/test/fixtures/slider.js +36 -0
- package/es/views/slides/test/fixtures/text-template.d.ts +3 -0
- package/es/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
- package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
- package/lib/actions/api/fetch-skills.d.ts +4 -6
- package/lib/actions/api/fetch-skills.js +55 -7
- package/lib/actions/api/fetch-slide.d.ts +14 -7
- package/lib/actions/api/fetch-slide.js +75 -7
- package/lib/actions/api/post-progression.d.ts +4 -6
- package/lib/actions/api/post-progression.js +63 -10
- package/lib/actions/api/test/create-test-store.d.ts +5 -0
- package/lib/actions/api/test/create-test-store.js +18 -0
- package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
- package/lib/actions/api/test/fetch-skills.test.js +113 -0
- package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
- package/lib/actions/api/test/fetch-slide.test.js +120 -0
- package/lib/actions/api/test/post-progression.test.d.ts +1 -0
- package/lib/actions/api/test/post-progression.test.js +160 -0
- package/lib/actions/index.d.ts +1 -10
- package/lib/actions/ui/answers.d.ts +7 -0
- package/lib/actions/ui/answers.js +9 -0
- package/lib/actions/ui/is-fetching.js +0 -2
- package/lib/actions/ui/slides.d.ts +26 -0
- package/lib/actions/ui/slides.js +9 -0
- package/lib/common/index.d.ts +3 -1
- package/lib/common/index.js +3 -1
- package/lib/fixtures/qcm-slide.d.ts +2 -2
- package/lib/fixtures/temp-fixture.d.ts +2 -2
- package/lib/index.js +33 -94
- package/lib/reducers/data/index.d.ts +2 -2
- package/lib/reducers/data/progression.d.ts +3 -16
- package/lib/reducers/data/progression.js +3 -22
- package/lib/reducers/data/slides.d.ts +5 -6
- package/lib/reducers/data/slides.js +9 -114
- package/lib/reducers/data/test/progression.test.d.ts +1 -0
- package/lib/reducers/data/test/progression.test.js +38 -0
- package/lib/reducers/data/test/skills.test.d.ts +1 -0
- package/lib/reducers/data/test/skills.test.js +12 -0
- package/lib/reducers/data/test/slides.test.d.ts +1 -0
- package/lib/reducers/data/test/slides.test.js +20 -0
- package/lib/reducers/data/test/token.test.d.ts +1 -0
- package/lib/reducers/data/test/token.test.js +11 -0
- package/lib/reducers/index.d.ts +3 -4
- package/lib/reducers/ui/answers.d.ts +4 -0
- package/lib/reducers/ui/{review-status.js → answers.js} +3 -3
- package/lib/reducers/ui/current-slide-ref.d.ts +4 -0
- package/lib/reducers/ui/current-slide-ref.js +14 -0
- package/lib/reducers/ui/index.d.ts +7 -10
- package/lib/reducers/ui/index.js +4 -6
- package/lib/reducers/ui/test/answers.test.d.ts +1 -0
- package/lib/reducers/ui/test/answers.test.js +11 -0
- package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
- package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
- package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
- package/lib/reducers/ui/test/navigation.test.js +15 -0
- package/lib/services/fetch-slide.js +1 -1
- package/lib/services/index.js +3 -1
- package/lib/services/post-answer.d.ts +2 -0
- package/lib/services/post-answer.js +62 -0
- package/lib/services/test/fetch-slide.test.d.ts +1 -0
- package/lib/services/test/fetch-slide.test.js +76 -0
- package/lib/services/test/post-answer.test.d.ts +1 -0
- package/lib/services/test/post-answer.test.js +111 -0
- package/lib/services/test/post-progression.test.js +14 -4
- package/lib/test/util/services.mock.js +46 -4
- package/lib/types/common.d.ts +61 -30
- package/lib/types/common.js +0 -5
- package/lib/types/slides.d.ts +0 -4
- package/{es/types/views/skills.d.ts → lib/views/skills/index.d.ts} +2 -0
- package/lib/views/skills/index.js +25 -0
- package/lib/views/slides/index.d.ts +79 -0
- package/lib/views/slides/index.js +155 -0
- package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
- package/lib/views/slides/map-api-slide-to-ui.js +178 -0
- package/lib/views/slides/test/fixtures/free-text.d.ts +3 -0
- package/lib/views/slides/test/fixtures/free-text.js +38 -0
- package/lib/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
- package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
- package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
- package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
- package/lib/views/slides/test/fixtures/qcm.d.ts +3 -0
- package/lib/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
- package/lib/views/slides/test/fixtures/select-template.d.ts +3 -0
- package/lib/views/slides/test/fixtures/select-template.js +92 -0
- package/lib/views/slides/test/fixtures/slider.d.ts +3 -0
- package/lib/views/slides/test/fixtures/slider.js +36 -0
- package/lib/views/slides/test/fixtures/text-template.d.ts +3 -0
- package/lib/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
- package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
- package/package.json +4 -3
- package/src/actions/api/fetch-skills.ts +12 -12
- package/src/actions/api/fetch-slide.ts +38 -13
- package/src/actions/api/post-progression.ts +18 -22
- package/src/actions/api/test/create-test-store.ts +25 -0
- package/src/actions/api/test/fetch-skills.test.ts +70 -0
- package/src/actions/api/test/fetch-slide.test.ts +77 -0
- package/src/actions/api/test/post-progression.test.ts +119 -0
- package/src/actions/index.ts +1 -10
- package/src/actions/ui/answers.ts +16 -0
- package/src/actions/ui/is-fetching.ts +0 -6
- package/src/actions/ui/slides.ts +35 -0
- package/src/common/index.ts +7 -1
- package/src/fixtures/qcm-slide.ts +2 -2
- package/src/fixtures/temp-fixture.ts +2 -2
- package/src/index.tsx +26 -110
- package/src/reducers/data/index.ts +1 -1
- package/src/reducers/data/progression.ts +5 -40
- package/src/reducers/data/slides.ts +17 -125
- package/src/reducers/data/test/progression.test.ts +42 -0
- package/src/reducers/data/test/skills.test.ts +14 -0
- package/src/reducers/data/test/slides.test.ts +26 -0
- package/src/reducers/data/test/token.test.ts +13 -0
- package/src/reducers/ui/answers.ts +19 -0
- package/src/reducers/ui/current-slide-ref.ts +19 -0
- package/src/reducers/ui/index.ts +6 -9
- package/src/reducers/ui/test/answers.test.ts +13 -0
- package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
- package/src/reducers/ui/test/navigation.test.ts +19 -0
- package/src/services/fetch-slide.ts +1 -1
- package/src/services/index.ts +3 -1
- package/src/services/post-answer.ts +27 -0
- package/src/services/test/fetch-slide.test.ts +30 -0
- package/src/services/test/post-answer.test.ts +68 -0
- package/src/services/test/post-progression.test.ts +14 -4
- package/src/test/util/services.mock.ts +46 -4
- package/src/types/common.ts +77 -40
- package/src/types/slides.ts +0 -5
- package/src/views/skills/index.ts +56 -0
- package/src/views/slides/index.ts +251 -0
- package/src/views/slides/map-api-slide-to-ui.ts +251 -0
- package/src/views/slides/test/fixtures/free-text.ts +43 -0
- package/src/views/slides/test/fixtures/qcm-drag.ts +111 -0
- package/src/views/slides/test/fixtures/qcm-graphic.ts +94 -0
- package/src/{helpers → views/slides}/test/fixtures/qcm.ts +43 -33
- package/src/views/slides/test/fixtures/select-template.ts +98 -0
- package/src/views/slides/test/fixtures/slider.ts +41 -0
- package/src/{helpers → views/slides}/test/fixtures/text-template.ts +23 -14
- package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +22 -20
- package/es/actions/data/slides.d.ts +0 -37
- package/es/actions/data/slides.js +0 -16
- package/es/actions/ui/finished-slides.d.ts +0 -10
- package/es/actions/ui/finished-slides.js +0 -8
- package/es/actions/ui/review-status.d.ts +0 -7
- package/es/actions/ui/review-status.js +0 -7
- package/es/actions/ui/step-items.d.ts +0 -24
- package/es/actions/ui/step-items.js +0 -11
- package/es/helpers/map-api-slide-to-ui.d.ts +0 -8
- package/es/helpers/map-api-slide-to-ui.js +0 -175
- package/es/helpers/test/fixtures/free-text.d.ts +0 -4
- package/es/helpers/test/fixtures/free-text.js +0 -24
- package/es/helpers/test/fixtures/qcm-drag.d.ts +0 -4
- package/es/helpers/test/fixtures/qcm-drag.js +0 -106
- package/es/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
- package/es/helpers/test/fixtures/qcm-graphic.js +0 -70
- package/es/helpers/test/fixtures/qcm.d.ts +0 -4
- package/es/helpers/test/fixtures/select-template.d.ts +0 -4
- package/es/helpers/test/fixtures/select-template.js +0 -88
- package/es/helpers/test/fixtures/slider.d.ts +0 -4
- package/es/helpers/test/fixtures/slider.js +0 -27
- package/es/helpers/test/fixtures/text-template.d.ts +0 -4
- package/es/reducers/ui/finished-slides.d.ts +0 -7
- package/es/reducers/ui/finished-slides.js +0 -33
- package/es/reducers/ui/review-status.d.ts +0 -4
- package/es/reducers/ui/step-items.d.ts +0 -14
- package/es/reducers/ui/step-items.js +0 -74
- package/es/types/ui-progression.d.ts +0 -10
- package/es/types/views/slides.d.ts +0 -60
- package/lib/actions/data/slides.d.ts +0 -37
- package/lib/actions/data/slides.js +0 -16
- package/lib/actions/ui/finished-slides.d.ts +0 -10
- package/lib/actions/ui/finished-slides.js +0 -8
- package/lib/actions/ui/review-status.d.ts +0 -7
- package/lib/actions/ui/review-status.js +0 -7
- package/lib/actions/ui/step-items.d.ts +0 -24
- package/lib/actions/ui/step-items.js +0 -11
- package/lib/helpers/map-api-slide-to-ui.d.ts +0 -8
- package/lib/helpers/map-api-slide-to-ui.js +0 -181
- package/lib/helpers/test/fixtures/free-text.d.ts +0 -4
- package/lib/helpers/test/fixtures/free-text.js +0 -24
- package/lib/helpers/test/fixtures/qcm-drag.d.ts +0 -4
- package/lib/helpers/test/fixtures/qcm-drag.js +0 -106
- package/lib/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
- package/lib/helpers/test/fixtures/qcm-graphic.js +0 -70
- package/lib/helpers/test/fixtures/qcm.d.ts +0 -4
- package/lib/helpers/test/fixtures/select-template.d.ts +0 -4
- package/lib/helpers/test/fixtures/select-template.js +0 -88
- package/lib/helpers/test/fixtures/slider.d.ts +0 -4
- package/lib/helpers/test/fixtures/slider.js +0 -27
- package/lib/helpers/test/fixtures/text-template.d.ts +0 -4
- package/lib/reducers/ui/finished-slides.d.ts +0 -7
- package/lib/reducers/ui/finished-slides.js +0 -45
- package/lib/reducers/ui/review-status.d.ts +0 -4
- package/lib/reducers/ui/step-items.d.ts +0 -14
- package/lib/reducers/ui/step-items.js +0 -86
- package/lib/types/ui-progression.d.ts +0 -10
- package/lib/types/views/slides.d.ts +0 -60
- package/src/actions/data/slides.ts +0 -65
- package/src/actions/ui/finished-slides.ts +0 -21
- package/src/actions/ui/review-status.ts +0 -19
- package/src/actions/ui/step-items.ts +0 -45
- package/src/helpers/map-api-slide-to-ui.ts +0 -253
- package/src/helpers/test/fixtures/free-text.ts +0 -28
- package/src/helpers/test/fixtures/qcm-drag.ts +0 -110
- package/src/helpers/test/fixtures/qcm-graphic.ts +0 -74
- package/src/helpers/test/fixtures/select-template.ts +0 -92
- package/src/helpers/test/fixtures/slider.ts +0 -31
- package/src/reducers/ui/finished-slides.ts +0 -52
- package/src/reducers/ui/review-status.ts +0 -19
- package/src/reducers/ui/step-items.ts +0 -116
- package/src/types/ui-progression.ts +0 -25
- package/src/types/views/skills.ts +0 -27
- package/src/types/views/slides.ts +0 -65
- /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
- /package/es/{types/ui-progression.js → actions/api/test/fetch-slide.test.d.ts} +0 -0
- /package/es/{types/views/skills.js → actions/api/test/post-progression.test.d.ts} +0 -0
- /package/es/{types/views/slides.js → reducers/data/test/progression.test.d.ts} +0 -0
- /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/reducers/data/test/skills.test.d.ts} +0 -0
- /package/{lib/types/ui-progression.js → es/reducers/data/test/slides.test.d.ts} +0 -0
- /package/{lib/types/views/skills.js → es/reducers/data/test/token.test.d.ts} +0 -0
- /package/{lib/types/views/slides.js → es/reducers/ui/test/answers.test.d.ts} +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { concat, divide, get, getOr, head, includes, indexOf, isEmpty, map, noop, pipe, rangeStep, size, toInteger } from 'lodash/fp';
|
|
2
|
-
const qcmProps = (question) => {
|
|
3
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
4
|
-
const answers = [];
|
|
5
|
-
return {
|
|
6
|
-
type: 'qcm',
|
|
7
|
-
answers: map(choice => ({
|
|
8
|
-
title: choice.label,
|
|
9
|
-
selected: includes(choice.label, answers),
|
|
10
|
-
// TODO: EDIT_CHOICES
|
|
11
|
-
onClick: noop,
|
|
12
|
-
ariaLabel: choice.label
|
|
13
|
-
}),
|
|
14
|
-
// TODO: EDIT_CHOICES -> getChoices
|
|
15
|
-
question.content.choices)
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const qcmDragProps = (question) => {
|
|
19
|
-
// mock the answers
|
|
20
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
21
|
-
const answers = [];
|
|
22
|
-
return {
|
|
23
|
-
type: 'qcmDrag',
|
|
24
|
-
answers: map(choice => {
|
|
25
|
-
const indexInAnswer = indexOf(choice.label, answers);
|
|
26
|
-
return {
|
|
27
|
-
title: choice.label,
|
|
28
|
-
selected: indexInAnswer !== -1,
|
|
29
|
-
order: indexInAnswer,
|
|
30
|
-
// TODO: EDIT_CHOICES
|
|
31
|
-
onClick: noop
|
|
32
|
-
};
|
|
33
|
-
// TODO: EDIT_CHOICES -> getChoices
|
|
34
|
-
}, question.content.choices)
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const qcmGraphicProps = (question) => {
|
|
38
|
-
// mock the answers
|
|
39
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
40
|
-
const answers = [];
|
|
41
|
-
return {
|
|
42
|
-
type: 'qcmGraphic',
|
|
43
|
-
answers: map(choice => ({
|
|
44
|
-
title: choice.label,
|
|
45
|
-
image: get('media.src.0.url', choice),
|
|
46
|
-
selected: includes(choice.label, answers),
|
|
47
|
-
// TODO: EDIT_CHOICES
|
|
48
|
-
onClick: noop
|
|
49
|
-
}),
|
|
50
|
-
// TODO: EDIT_CHOICES -> getChoices
|
|
51
|
-
question.content.choices)
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const templateTextProps = (uiUtils) => (choice, index) => {
|
|
55
|
-
const { translate } = uiUtils;
|
|
56
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
57
|
-
const answers = [];
|
|
58
|
-
return {
|
|
59
|
-
type: 'text',
|
|
60
|
-
name: getOr('', 'name', choice),
|
|
61
|
-
placeholder: translate('Type here'),
|
|
62
|
-
value: get(index, answers),
|
|
63
|
-
// TODO: EDIT_CHOICES
|
|
64
|
-
onChange: noop
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
// const getItemText = (item: ChoiceFromAPI['items'][0]): item['text'] is string =>
|
|
68
|
-
const templateSelectProps = (uiUtils) => {
|
|
69
|
-
return (choice, index) => {
|
|
70
|
-
const { translate } = uiUtils;
|
|
71
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
72
|
-
const answers = [];
|
|
73
|
-
const answer = 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 = 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: getOr('', 'name', choice),
|
|
92
|
-
// TODO: EDIT_CHOICES
|
|
93
|
-
onChange: noop,
|
|
94
|
-
options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
const templateProps = (uiUtils) => {
|
|
99
|
-
const templateTextProps_ = templateTextProps(uiUtils);
|
|
100
|
-
const templateSelectProps_ = templateSelectProps(uiUtils);
|
|
101
|
-
return question => {
|
|
102
|
-
// TODO: EDIT_CHOICES -> getChoices
|
|
103
|
-
const choices = question.content.choices;
|
|
104
|
-
return {
|
|
105
|
-
type: 'template',
|
|
106
|
-
template: get('content.template', question),
|
|
107
|
-
answers: choices.map((choice, index) => choice.type === 'text'
|
|
108
|
-
? templateTextProps_(choice, index)
|
|
109
|
-
: templateSelectProps_(choice, index))
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const basicProps = (uiUtils) => {
|
|
114
|
-
const { translate } = uiUtils;
|
|
115
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
116
|
-
const answers = [];
|
|
117
|
-
return () => {
|
|
118
|
-
return {
|
|
119
|
-
type: 'freeText',
|
|
120
|
-
placeholder: translate('Type here'),
|
|
121
|
-
value: head(answers),
|
|
122
|
-
// TODO: EDIT_CHOICES
|
|
123
|
-
onChange: noop
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
const sliderProps = (question) => {
|
|
128
|
-
const values = rangeStep(getOr(1, 'content.step', question), getOr(Number.NaN, 'content.min', question), getOr(Number.NaN, 'content.max', question) + 1
|
|
129
|
-
// Lodash doesn't infere the type very well here
|
|
130
|
-
);
|
|
131
|
-
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
132
|
-
const answers = [];
|
|
133
|
-
const stateValue = head(answers);
|
|
134
|
-
const currentValue = toInteger(stateValue);
|
|
135
|
-
const indexValue = indexOf(currentValue, values);
|
|
136
|
-
const sliderPosition = divide(indexValue, size(values) - 1);
|
|
137
|
-
const unitLabel = get('question.content.unitLabel', question);
|
|
138
|
-
return {
|
|
139
|
-
type: 'slider',
|
|
140
|
-
placeholder: question.explanation,
|
|
141
|
-
minLabel: `${question.content.min} ${unitLabel}`,
|
|
142
|
-
maxLabel: `${question.content.max} ${unitLabel}`,
|
|
143
|
-
title: `${currentValue} ${question.content.unitLabel}`,
|
|
144
|
-
value: sliderPosition,
|
|
145
|
-
// TODO: EDIT_CHOICES
|
|
146
|
-
onChange: noop
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
export const getQuestionType = (slide) => slide.question.type;
|
|
150
|
-
export const mapApiSlideToUi = (uiUtils) => {
|
|
151
|
-
const basicProps_ = basicProps(uiUtils);
|
|
152
|
-
const templateProps_ = templateProps(uiUtils);
|
|
153
|
-
return (slide) => {
|
|
154
|
-
if (!slide) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const type = getQuestionType(slide);
|
|
158
|
-
switch (type) {
|
|
159
|
-
case 'qcm':
|
|
160
|
-
return pipe(get('question'), qcmProps)(slide);
|
|
161
|
-
case 'qcmGraphic':
|
|
162
|
-
return pipe(get('question'), qcmGraphicProps)(slide);
|
|
163
|
-
case 'qcmDrag':
|
|
164
|
-
return pipe(get('question'), qcmDragProps)(slide);
|
|
165
|
-
case 'basic':
|
|
166
|
-
return basicProps_();
|
|
167
|
-
case 'template':
|
|
168
|
-
return pipe(get('question'), templateProps_)(slide);
|
|
169
|
-
case 'slider':
|
|
170
|
-
return pipe(get('question'), sliderProps)(slide);
|
|
171
|
-
default:
|
|
172
|
-
throw new Error(`${type} is not an handled question.type`);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/fp/noop';
|
|
2
|
-
export const freeTextSlide = {
|
|
3
|
-
id: 'sli_E1Pcl-XAYbi',
|
|
4
|
-
universalRef: 'sli_E1Pcl-XAYbi',
|
|
5
|
-
question: {
|
|
6
|
-
type: 'basic',
|
|
7
|
-
header: 'sli_E1Pcl-XAYbi.header',
|
|
8
|
-
explanation: 'sli_E1Pcl-XAYbi.explanation',
|
|
9
|
-
content: {
|
|
10
|
-
label: 'sli_E1Pcl-XAYbi.label',
|
|
11
|
-
placeholder: 'sli_E1Pcl-XAYbi.placeholder',
|
|
12
|
-
id: 'sli_E1Pcl-XAYbi.choice_1'
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
clue: 'sli_E1Pcl-XAYbi.clue',
|
|
16
|
-
klf: 'sli_E1Pcl-XAYbi.klf',
|
|
17
|
-
tips: 'sli_E1Pcl-XAYbi.tips'
|
|
18
|
-
};
|
|
19
|
-
export const freeTextUISlide = {
|
|
20
|
-
type: 'freeText',
|
|
21
|
-
placeholder: 'Type here',
|
|
22
|
-
value: undefined,
|
|
23
|
-
onChange: noop
|
|
24
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/fp/noop';
|
|
2
|
-
export const qcmDragSlide = {
|
|
3
|
-
id: 'sli_419IlQQnf',
|
|
4
|
-
universalRef: 'sli_419IlQQnf',
|
|
5
|
-
question: {
|
|
6
|
-
type: 'qcmDrag',
|
|
7
|
-
header: 'sli_419IlQQnf.header',
|
|
8
|
-
explanation: 'sli_419IlQQnf.explanation',
|
|
9
|
-
content: {
|
|
10
|
-
choices: [
|
|
11
|
-
{
|
|
12
|
-
media: {
|
|
13
|
-
src: [],
|
|
14
|
-
posters: [],
|
|
15
|
-
subtitles: []
|
|
16
|
-
},
|
|
17
|
-
_id: '62b1ba3ec4f4015504212571',
|
|
18
|
-
label: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
19
|
-
value: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
20
|
-
items: []
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
media: {
|
|
24
|
-
src: [],
|
|
25
|
-
posters: [],
|
|
26
|
-
subtitles: []
|
|
27
|
-
},
|
|
28
|
-
_id: '62b1ba3ec4f4015504212572',
|
|
29
|
-
label: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
30
|
-
value: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
31
|
-
items: []
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
media: {
|
|
35
|
-
src: [],
|
|
36
|
-
posters: [],
|
|
37
|
-
subtitles: []
|
|
38
|
-
},
|
|
39
|
-
_id: '62b1ba3ec4f4015504212573',
|
|
40
|
-
label: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
41
|
-
value: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
42
|
-
items: []
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
media: {
|
|
46
|
-
src: [],
|
|
47
|
-
posters: [],
|
|
48
|
-
subtitles: []
|
|
49
|
-
},
|
|
50
|
-
_id: '62b1ba3ec4f4015504212574',
|
|
51
|
-
label: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
52
|
-
value: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
53
|
-
items: []
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
media: {
|
|
57
|
-
src: [],
|
|
58
|
-
posters: [],
|
|
59
|
-
subtitles: []
|
|
60
|
-
},
|
|
61
|
-
_id: '62b1ba3ec4f4015504212575',
|
|
62
|
-
label: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
63
|
-
value: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
64
|
-
items: []
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
klf: 'sli_419IlQQnf.klf',
|
|
70
|
-
tips: 'sli_419IlQQnf.tips'
|
|
71
|
-
};
|
|
72
|
-
export const qcmDragUISlide = {
|
|
73
|
-
type: 'qcmDrag',
|
|
74
|
-
answers: [
|
|
75
|
-
{
|
|
76
|
-
title: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
77
|
-
selected: false,
|
|
78
|
-
order: -1,
|
|
79
|
-
onClick: noop
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
title: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
83
|
-
selected: false,
|
|
84
|
-
order: -1,
|
|
85
|
-
onClick: noop
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
title: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
89
|
-
selected: false,
|
|
90
|
-
order: -1,
|
|
91
|
-
onClick: noop
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
title: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
95
|
-
selected: false,
|
|
96
|
-
order: -1,
|
|
97
|
-
onClick: noop
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
title: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
101
|
-
selected: false,
|
|
102
|
-
order: -1,
|
|
103
|
-
onClick: noop
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/fp/noop';
|
|
2
|
-
export const qcmGraphicSlide = {
|
|
3
|
-
id: 'sli_41~RSVclH',
|
|
4
|
-
universalRef: 'sli_41~RSVclH',
|
|
5
|
-
question: {
|
|
6
|
-
type: 'qcmGraphic',
|
|
7
|
-
header: 'sli_41~RSVclH.header',
|
|
8
|
-
explanation: 'sli_41~RSVclH.explanation',
|
|
9
|
-
content: {
|
|
10
|
-
choices: [
|
|
11
|
-
{
|
|
12
|
-
media: {
|
|
13
|
-
type: 'img',
|
|
14
|
-
src: [
|
|
15
|
-
{
|
|
16
|
-
_id: '5fdce726359bf4003ee66997',
|
|
17
|
-
mimeType: 'image/png',
|
|
18
|
-
url: 'med_4JVRrE5gH.mediaUrl_VkBtUV9gB'
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
posters: [],
|
|
22
|
-
subtitles: []
|
|
23
|
-
},
|
|
24
|
-
_id: '5fdce726359bf4003ee66996',
|
|
25
|
-
label: 'sli_41~RSVclH.choice_V1gN0r4qgS',
|
|
26
|
-
value: 'sli_41~RSVclH.choice_V1gN0r4qgS',
|
|
27
|
-
items: []
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
media: {
|
|
31
|
-
type: 'img',
|
|
32
|
-
src: [
|
|
33
|
-
{
|
|
34
|
-
_id: '5fdce726359bf4003ee66999',
|
|
35
|
-
mimeType: 'image/png',
|
|
36
|
-
url: 'med_Ek8gIEqxB.mediaUrl_EkcFUEclH'
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
posters: [],
|
|
40
|
-
subtitles: []
|
|
41
|
-
},
|
|
42
|
-
_id: '5fdce726359bf4003ee66998',
|
|
43
|
-
label: 'sli_41~RSVclH.choice_4JlLeLE5lS',
|
|
44
|
-
value: 'sli_41~RSVclH.choice_4JlLeLE5lS',
|
|
45
|
-
items: []
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
clue: 'sli_41~RSVclH.clue',
|
|
51
|
-
klf: 'sli_41~RSVclH.klf',
|
|
52
|
-
tips: 'sli_41~RSVclH.tips'
|
|
53
|
-
};
|
|
54
|
-
export const qcmGraphicUISlide = {
|
|
55
|
-
type: 'qcmGraphic',
|
|
56
|
-
answers: [
|
|
57
|
-
{
|
|
58
|
-
title: 'sli_41~RSVclH.choice_V1gN0r4qgS',
|
|
59
|
-
image: 'med_4JVRrE5gH.mediaUrl_VkBtUV9gB',
|
|
60
|
-
selected: false,
|
|
61
|
-
onClick: noop
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
title: 'sli_41~RSVclH.choice_4JlLeLE5lS',
|
|
65
|
-
image: 'med_Ek8gIEqxB.mediaUrl_EkcFUEclH',
|
|
66
|
-
selected: false,
|
|
67
|
-
onClick: noop
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/fp/noop';
|
|
2
|
-
export const selectTemplateSlide = {
|
|
3
|
-
id: 'sli_410xZQxrZ',
|
|
4
|
-
universalRef: 'sli_410xZQxrZ',
|
|
5
|
-
question: {
|
|
6
|
-
type: 'template',
|
|
7
|
-
header: 'sli_410xZQxrZ.header',
|
|
8
|
-
explanation: 'sli_410xZQxrZ.explanation',
|
|
9
|
-
content: {
|
|
10
|
-
template: 'sli_410xZQxrZ.template',
|
|
11
|
-
choices: [
|
|
12
|
-
{
|
|
13
|
-
media: {
|
|
14
|
-
src: [],
|
|
15
|
-
posters: [],
|
|
16
|
-
subtitles: []
|
|
17
|
-
},
|
|
18
|
-
_id: '5fdce726359bf4003ee66967',
|
|
19
|
-
type: 'select',
|
|
20
|
-
name: 'sel36665',
|
|
21
|
-
items: [
|
|
22
|
-
{
|
|
23
|
-
_id: '5fdce726359bf4003ee66968',
|
|
24
|
-
text: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
|
|
25
|
-
value: 'sli_410xZQxrZ.choice_4yeA4Z7lr~'
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
_id: '5fdce726359bf4003ee66969',
|
|
29
|
-
text: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
|
|
30
|
-
value: 'sli_410xZQxrZ.choice_VJWCN~mgB~'
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
_id: '5fdce726359bf4003ee6696a',
|
|
34
|
-
text: 'sli_410xZQxrZ.choice_VkaH~XgBb',
|
|
35
|
-
value: 'sli_410xZQxrZ.choice_VkaH~XgBb'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
_id: '5fdce726359bf4003ee6696b',
|
|
39
|
-
text: 'sli_410xZQxrZ.choice_E1uUWXeBb',
|
|
40
|
-
value: 'sli_410xZQxrZ.choice_E1uUWXeBb'
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
clue: 'sli_410xZQxrZ.clue',
|
|
48
|
-
klf: 'sli_410xZQxrZ.klf',
|
|
49
|
-
tips: 'sli_410xZQxrZ.tips'
|
|
50
|
-
};
|
|
51
|
-
export const selectTemplateUISlide = {
|
|
52
|
-
type: 'template',
|
|
53
|
-
template: 'sli_410xZQxrZ.template',
|
|
54
|
-
answers: [
|
|
55
|
-
{
|
|
56
|
-
type: 'select',
|
|
57
|
-
name: 'sel36665',
|
|
58
|
-
onChange: noop,
|
|
59
|
-
options: [
|
|
60
|
-
{ name: 'Select an answer', value: '', validOption: false, selected: true },
|
|
61
|
-
{
|
|
62
|
-
name: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
|
|
63
|
-
value: 'sli_410xZQxrZ.choice_4yeA4Z7lr~',
|
|
64
|
-
validOption: true,
|
|
65
|
-
selected: false
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
|
|
69
|
-
value: 'sli_410xZQxrZ.choice_VJWCN~mgB~',
|
|
70
|
-
validOption: true,
|
|
71
|
-
selected: false
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'sli_410xZQxrZ.choice_VkaH~XgBb',
|
|
75
|
-
value: 'sli_410xZQxrZ.choice_VkaH~XgBb',
|
|
76
|
-
validOption: true,
|
|
77
|
-
selected: false
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'sli_410xZQxrZ.choice_E1uUWXeBb',
|
|
81
|
-
value: 'sli_410xZQxrZ.choice_E1uUWXeBb',
|
|
82
|
-
validOption: true,
|
|
83
|
-
selected: false
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/fp/noop';
|
|
2
|
-
export const sliderSlide = {
|
|
3
|
-
id: 'sli_41D5AovN~',
|
|
4
|
-
universalRef: 'sli_41D5AovN~',
|
|
5
|
-
question: {
|
|
6
|
-
type: 'slider',
|
|
7
|
-
header: 'sli_41D5AovN~.header',
|
|
8
|
-
explanation: 'sli_41D5AovN~.explanation',
|
|
9
|
-
content: {
|
|
10
|
-
min: 1,
|
|
11
|
-
max: 10,
|
|
12
|
-
unitLabel: 'sli_41D5AovN~.unitLabel'
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
clue: 'sli_41D5AovN~.clue',
|
|
16
|
-
klf: 'sli_41D5AovN~.klf',
|
|
17
|
-
tips: 'sli_41D5AovN~.tips'
|
|
18
|
-
};
|
|
19
|
-
export const sliderUISlide = {
|
|
20
|
-
type: 'slider',
|
|
21
|
-
placeholder: 'sli_41D5AovN~.explanation',
|
|
22
|
-
minLabel: '1 undefined',
|
|
23
|
-
maxLabel: '10 undefined',
|
|
24
|
-
title: '0 sli_41D5AovN~.unitLabel',
|
|
25
|
-
value: -0.1111111111111111,
|
|
26
|
-
onChange: noop
|
|
27
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { UpdateFinishedSlides } from '../../actions/ui/finished-slides';
|
|
2
|
-
export declare type FinishedSlidesState = {
|
|
3
|
-
slideNumbers: number[];
|
|
4
|
-
[key: number]: true;
|
|
5
|
-
};
|
|
6
|
-
declare const reducer: (state: FinishedSlidesState | undefined, action: UpdateFinishedSlides) => FinishedSlidesState;
|
|
7
|
-
export default reducer;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import forEach from 'lodash/fp/forEach';
|
|
2
|
-
import { UPDATE_FINISHED_SLIDES } from '../../actions/ui/finished-slides';
|
|
3
|
-
import { slideNumbers } from '../../common';
|
|
4
|
-
const initialState = {
|
|
5
|
-
slideNumbers
|
|
6
|
-
};
|
|
7
|
-
const _forEach = forEach.convert({
|
|
8
|
-
cap: false
|
|
9
|
-
});
|
|
10
|
-
// -----------------------------------------------------------------------------
|
|
11
|
-
const reducer = (
|
|
12
|
-
// eslint-disable-next-line default-param-last
|
|
13
|
-
state = initialState, action) => {
|
|
14
|
-
switch (action.type) {
|
|
15
|
-
case UPDATE_FINISHED_SLIDES: {
|
|
16
|
-
const { slideNumbers: _slideNumbers, ...rest } = state;
|
|
17
|
-
const { slideNumber, value } = action.payload;
|
|
18
|
-
const _state = {
|
|
19
|
-
slideNumbers: _slideNumbers
|
|
20
|
-
};
|
|
21
|
-
_forEach((finishedSlide, index) => {
|
|
22
|
-
const previousValue = finishedSlide;
|
|
23
|
-
_state[index] = previousValue;
|
|
24
|
-
}, rest);
|
|
25
|
-
_state[slideNumber] = value;
|
|
26
|
-
return _state;
|
|
27
|
-
}
|
|
28
|
-
default:
|
|
29
|
-
return state;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
// -----------------------------------------------------------------------------
|
|
33
|
-
export default reducer;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { UpdateReviewStatus } from '../../actions/ui/review-status';
|
|
2
|
-
export declare type ReviewStatusState = 'finished' | 'ongoing';
|
|
3
|
-
declare const reducer: (state: ReviewStatusState | undefined, action: UpdateReviewStatus) => ReviewStatusState;
|
|
4
|
-
export default reducer;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IconValue } from '../../types/common';
|
|
2
|
-
import { StepItemsAction } from '../../actions/ui/step-items';
|
|
3
|
-
export declare type StepItem = {
|
|
4
|
-
current: boolean;
|
|
5
|
-
icon: IconValue;
|
|
6
|
-
value: string;
|
|
7
|
-
};
|
|
8
|
-
export declare type StepItemsState = {
|
|
9
|
-
slideNumbers: number[];
|
|
10
|
-
[key: number]: StepItem;
|
|
11
|
-
};
|
|
12
|
-
export declare const initialState: StepItemsState;
|
|
13
|
-
declare const reducer: (state: StepItemsState | undefined, action: StepItemsAction) => StepItemsState;
|
|
14
|
-
export default reducer;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/fp/get';
|
|
2
|
-
import has from 'lodash/fp/has';
|
|
3
|
-
import map from 'lodash/fp/map';
|
|
4
|
-
import { UPDATE_STEP_ITEMS_ON_NEXT, UPDATE_STEP_ITEMS_ON_VALIDATION } from '../../actions/ui/step-items';
|
|
5
|
-
import { HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK } from '../../common';
|
|
6
|
-
const getInitialState = () => {
|
|
7
|
-
const state = {
|
|
8
|
-
slideNumbers
|
|
9
|
-
};
|
|
10
|
-
// eslint-disable-next-line fp/no-loops
|
|
11
|
-
for (let index = 0; index < TOTAL_SLIDES_STACK; index++) {
|
|
12
|
-
const current = index === 0;
|
|
13
|
-
state[index] = { current, value: `${index + 1}`, icon: 'no-answer' };
|
|
14
|
-
}
|
|
15
|
-
return state;
|
|
16
|
-
};
|
|
17
|
-
export const initialState = getInitialState();
|
|
18
|
-
// -----------------------------------------------------------------------------
|
|
19
|
-
// ||-------> aux function, finds the next consecutive index
|
|
20
|
-
// to loop from 0 to HIGHEST_INDEX (4) & again to 0
|
|
21
|
-
const getNextIndex = (currentIndex) => currentIndex === HIGHEST_INDEX ? 0 : currentIndex + 1;
|
|
22
|
-
// ||-------> calculates which should be the next step to visit (as there can be already answered slides &&
|
|
23
|
-
// they have to be skipped)
|
|
24
|
-
const calculateNextStepIndex = (currentStepNumber, finishedSlides, lastVisitedIndex = -1) => {
|
|
25
|
-
// only one slide remaining, the step should stay on the same number
|
|
26
|
-
if (lastVisitedIndex === currentStepNumber) {
|
|
27
|
-
return currentStepNumber;
|
|
28
|
-
}
|
|
29
|
-
const indexToVisit = getNextIndex(lastVisitedIndex === -1 ? currentStepNumber : lastVisitedIndex);
|
|
30
|
-
// if the index is already included in the correctly answered (finished) slides, then we proceed to check for the next one
|
|
31
|
-
return has(indexToVisit, finishedSlides)
|
|
32
|
-
? calculateNextStepIndex(currentStepNumber, finishedSlides, indexToVisit)
|
|
33
|
-
: indexToVisit;
|
|
34
|
-
};
|
|
35
|
-
const recalculateStepItemsState = (state, stepNumber, stepItemToUpdateProps) => {
|
|
36
|
-
const nextIndex = get('nextIndex', stepItemToUpdateProps);
|
|
37
|
-
const _state = {
|
|
38
|
-
slideNumbers
|
|
39
|
-
};
|
|
40
|
-
// eslint-disable-next-line lodash-fp/no-unused-result
|
|
41
|
-
map(index => {
|
|
42
|
-
const previousValue = state[index];
|
|
43
|
-
if (stepNumber === index)
|
|
44
|
-
_state[stepNumber] = {
|
|
45
|
-
...previousValue,
|
|
46
|
-
...stepItemToUpdateProps
|
|
47
|
-
};
|
|
48
|
-
/* only for UPDATE_STEP_ITEMS_ON_NEXT -> */ else if (nextIndex === index) {
|
|
49
|
-
_state[index] = { ...previousValue, current: true };
|
|
50
|
-
}
|
|
51
|
-
else
|
|
52
|
-
_state[index] = previousValue;
|
|
53
|
-
}, state.slideNumbers);
|
|
54
|
-
return _state;
|
|
55
|
-
};
|
|
56
|
-
// -----------------------------------------------------------------------------
|
|
57
|
-
// eslint-disable-next-line default-param-last
|
|
58
|
-
const reducer = (state = initialState, action) => {
|
|
59
|
-
switch (action.type) {
|
|
60
|
-
case UPDATE_STEP_ITEMS_ON_VALIDATION: {
|
|
61
|
-
const { stepNumber, icon } = action.payload;
|
|
62
|
-
return recalculateStepItemsState(state, stepNumber, { icon });
|
|
63
|
-
}
|
|
64
|
-
case UPDATE_STEP_ITEMS_ON_NEXT: {
|
|
65
|
-
const { stepNumber, finishedSlides, current } = action.payload;
|
|
66
|
-
const nextIndex = !current ? calculateNextStepIndex(stepNumber, finishedSlides) : -1;
|
|
67
|
-
return recalculateStepItemsState(state, stepNumber, { current, nextIndex });
|
|
68
|
-
}
|
|
69
|
-
default:
|
|
70
|
-
return state;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
// -----------------------------------------------------------------------------
|
|
74
|
-
export default reducer;
|