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