@elice/material-quiz 1.220803.0
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/README.md +3 -0
- package/cjs/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/cjs/components/eb-sortable/EbDraggable.js +112 -0
- package/cjs/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/cjs/components/eb-sortable/EbDroppable.js +60 -0
- package/cjs/components/eb-sortable/EbSortable.d.ts +17 -0
- package/cjs/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.js +55 -0
- package/cjs/components/material-quiz/MaterialQuiz.js +114 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +55 -0
- package/cjs/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.js +74 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +203 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +468 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.js +191 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.js +61 -0
- package/cjs/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizText.js +181 -0
- package/cjs/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/cjs/components/material-quiz/QuizResultBadge.js +48 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.js +38 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.js +134 -0
- package/cjs/components/material-quiz/index.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +91 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +463 -0
- package/cjs/components/material-quiz-edit/context.d.ts +6 -0
- package/cjs/components/material-quiz-edit/context.js +15 -0
- package/cjs/components/material-quiz-edit/index.d.ts +2 -0
- package/cjs/components/material-quiz-edit/locales.d.ts +34 -0
- package/cjs/components/material-quiz-edit/locales.js +73 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +204 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +205 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +207 -0
- package/cjs/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionText.js +99 -0
- package/cjs/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/cjs/components/material-quiz-edit/utils/editValue.js +37 -0
- package/cjs/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/cjs/components/material-quiz-edit/utils/randomId.js +12 -0
- package/cjs/components/shared/QuestionBox.d.ts +16 -0
- package/cjs/components/shared/QuestionBox.js +111 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.js +31 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.js +36 -0
- package/cjs/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/cjs/components/shared/QuizDraggbleOption.js +191 -0
- package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
- package/cjs/components/shared/StyledMarkdown.js +14 -0
- package/cjs/components/shared/index.d.ts +7 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +188 -0
- package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +156 -0
- package/cjs/helpers/index.d.ts +50 -0
- package/cjs/helpers/index.js +86 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +27 -0
- package/es/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/es/components/eb-sortable/EbDraggable.js +105 -0
- package/es/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/es/components/eb-sortable/EbDroppable.js +53 -0
- package/es/components/eb-sortable/EbSortable.d.ts +17 -0
- package/es/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.js +50 -0
- package/es/components/material-quiz/MaterialQuiz.js +106 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +48 -0
- package/es/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.js +68 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.js +197 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +461 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.js +185 -0
- package/es/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizShimmer.js +54 -0
- package/es/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizText.js +174 -0
- package/es/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/es/components/material-quiz/QuizResultBadge.js +42 -0
- package/es/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/es/components/material-quiz/QuizSubmitStatusText.js +32 -0
- package/es/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/es/components/material-quiz/context/MaterialQuizContext.js +124 -0
- package/es/components/material-quiz/index.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +86 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.js +456 -0
- package/es/components/material-quiz-edit/context.d.ts +6 -0
- package/es/components/material-quiz-edit/context.js +6 -0
- package/es/components/material-quiz-edit/index.d.ts +2 -0
- package/es/components/material-quiz-edit/locales.d.ts +34 -0
- package/es/components/material-quiz-edit/locales.js +68 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +197 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +198 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +200 -0
- package/es/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionText.js +93 -0
- package/es/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/es/components/material-quiz-edit/utils/editValue.js +32 -0
- package/es/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/es/components/material-quiz-edit/utils/randomId.js +8 -0
- package/es/components/shared/QuestionBox.d.ts +16 -0
- package/es/components/shared/QuestionBox.js +101 -0
- package/es/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/es/components/shared/QuizDraggbleDroppedOption.js +25 -0
- package/es/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/es/components/shared/QuizDraggbleDummyOption.js +29 -0
- package/es/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/es/components/shared/QuizDraggbleOption.js +184 -0
- package/es/components/shared/StyledMarkdown.d.ts +3 -0
- package/es/components/shared/StyledMarkdown.js +8 -0
- package/es/components/shared/index.d.ts +7 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +181 -0
- package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/es/components/shared/question-radio/QuestionRadio.js +19 -0
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
- package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioOption.js +149 -0
- package/es/helpers/index.d.ts +50 -0
- package/es/helpers/index.js +78 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +10 -0
- package/package.json +75 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var apiClient = require('@elice/api-client');
|
|
6
|
+
var index = require('../../helpers/index.js');
|
|
7
|
+
require('../shared/QuizDraggbleOption.js');
|
|
8
|
+
require('../shared/QuizDraggbleDummyOption.js');
|
|
9
|
+
var QuestionRadio = require('../shared/question-radio/QuestionRadio.js');
|
|
10
|
+
var QuestionRadioOption = require('../shared/question-radio/QuestionRadioOption.js');
|
|
11
|
+
require('../shared/question-checkbox/QuestionCheckbox.js');
|
|
12
|
+
require('../shared/question-checkbox/QuestionCheckboxOption.js');
|
|
13
|
+
var QuestionBox = require('../shared/QuestionBox.js');
|
|
14
|
+
var StyledMarkdown = require('../shared/StyledMarkdown.js');
|
|
15
|
+
var MaterialQuizContext = require('./context/MaterialQuizContext.js');
|
|
16
|
+
var QuizResultBadge = require('./QuizResultBadge.js');
|
|
17
|
+
var QuizSubmitStatusText = require('./QuizSubmitStatusText.js');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
+
|
|
21
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
22
|
+
|
|
23
|
+
const MaterialQuizSelectOne = () => {
|
|
24
|
+
// context
|
|
25
|
+
const {
|
|
26
|
+
course,
|
|
27
|
+
lecture,
|
|
28
|
+
materialQuiz,
|
|
29
|
+
userId
|
|
30
|
+
} = MaterialQuizContext.useMaterialQuizState();
|
|
31
|
+
const {
|
|
32
|
+
onSubmit,
|
|
33
|
+
onNext,
|
|
34
|
+
refreshOrgMaterialQuiz
|
|
35
|
+
} = MaterialQuizContext.useMaterialQuizDispatch(); // state
|
|
36
|
+
|
|
37
|
+
const intl = reactIntl.useIntl();
|
|
38
|
+
const [selectedAnswer, setSelectedAnswer] = React__default["default"].useState();
|
|
39
|
+
const [materialQuizResponse, setMaterialQuizResponse] = React__default["default"].useState();
|
|
40
|
+
const [submitStatus, setSubmitStatus] = React__default["default"].useState('idle'); // Whether user has clicked any options
|
|
41
|
+
|
|
42
|
+
const [isActive, setIsActive] = React__default["default"].useState(false);
|
|
43
|
+
const [hasSubmitted, setHasSubmitted] = React__default["default"].useState(false); // quiz response fetcher
|
|
44
|
+
|
|
45
|
+
React__default["default"].useEffect(() => {
|
|
46
|
+
if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
const {
|
|
49
|
+
signal
|
|
50
|
+
} = controller;
|
|
51
|
+
apiClient.getOrgMaterialQuizResponseGet({
|
|
52
|
+
quizResponseId: materialQuiz.lastQuizResponseId
|
|
53
|
+
}, {
|
|
54
|
+
signal
|
|
55
|
+
}).then(response => {
|
|
56
|
+
setMaterialQuizResponse(response.quizResponse);
|
|
57
|
+
setSelectedAnswer(typeof response.quizResponse.answer === 'string' ? undefined : response.quizResponse.answer[0]);
|
|
58
|
+
}).catch(error => {
|
|
59
|
+
console.error(error);
|
|
60
|
+
});
|
|
61
|
+
return () => controller.abort();
|
|
62
|
+
}
|
|
63
|
+
}, [materialQuiz, userId]); // quiz response fetcher
|
|
64
|
+
|
|
65
|
+
React__default["default"].useEffect(() => {
|
|
66
|
+
if (userId && materialQuiz) {
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
const {
|
|
69
|
+
signal
|
|
70
|
+
} = controller;
|
|
71
|
+
apiClient.getOrgMaterialQuizResponseList({
|
|
72
|
+
materialQuizId: materialQuiz.id,
|
|
73
|
+
filterUserIds: [userId],
|
|
74
|
+
isContainOnlyLast: true,
|
|
75
|
+
isIncludeAnswer: true,
|
|
76
|
+
offset: 0,
|
|
77
|
+
count: 1
|
|
78
|
+
}, {
|
|
79
|
+
signal
|
|
80
|
+
}).then(response => {
|
|
81
|
+
const quizResponse = response.quizResponses[0];
|
|
82
|
+
setMaterialQuizResponse(quizResponse);
|
|
83
|
+
setSelectedAnswer(typeof quizResponse.answer === 'string' ? undefined : quizResponse.answer[0]);
|
|
84
|
+
}).catch(error => {
|
|
85
|
+
console.error(error);
|
|
86
|
+
});
|
|
87
|
+
return () => controller.abort();
|
|
88
|
+
}
|
|
89
|
+
}, [materialQuiz, userId]); // submit handler
|
|
90
|
+
|
|
91
|
+
const handleSubmit = async () => {
|
|
92
|
+
if (!materialQuiz) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setSubmitStatus('pending');
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const {
|
|
100
|
+
quizResponseId
|
|
101
|
+
} = await apiClient.postOrgMaterialQuizResponseAdd({
|
|
102
|
+
materialQuizId: materialQuiz.id,
|
|
103
|
+
answer: [selectedAnswer]
|
|
104
|
+
});
|
|
105
|
+
const {
|
|
106
|
+
quizResponse
|
|
107
|
+
} = await apiClient.getOrgMaterialQuizResponseGet({
|
|
108
|
+
quizResponseId
|
|
109
|
+
});
|
|
110
|
+
setIsActive(false);
|
|
111
|
+
setMaterialQuizResponse(quizResponse);
|
|
112
|
+
void refreshOrgMaterialQuiz();
|
|
113
|
+
onSubmit(true, index.getQuizResult(quizResponse));
|
|
114
|
+
setSubmitStatus('resolved');
|
|
115
|
+
setHasSubmitted(true);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(error);
|
|
118
|
+
onSubmit(false);
|
|
119
|
+
setSubmitStatus('rejected');
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return React__default["default"].createElement(QuestionBox["default"], {
|
|
124
|
+
title: intl.formatMessage({
|
|
125
|
+
id: 'materialQuiz.myAnswer'
|
|
126
|
+
}),
|
|
127
|
+
onNext: onNext,
|
|
128
|
+
isNextActive: hasSubmitted && typeof onNext === 'function',
|
|
129
|
+
submitStatus: React__default["default"].createElement(QuizSubmitStatusText, {
|
|
130
|
+
status: submitStatus
|
|
131
|
+
}),
|
|
132
|
+
submitResult: React__default["default"].createElement(QuizResultBadge, {
|
|
133
|
+
materialQuizResponse: materialQuizResponse
|
|
134
|
+
}),
|
|
135
|
+
footerActions: [{
|
|
136
|
+
border: true,
|
|
137
|
+
disabled: selectedAnswer === undefined || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
138
|
+
loading: submitStatus === 'pending',
|
|
139
|
+
tabIndex: 0,
|
|
140
|
+
transparent: false,
|
|
141
|
+
role: 'primary',
|
|
142
|
+
onClick: handleSubmit,
|
|
143
|
+
children: intl.formatMessage({
|
|
144
|
+
id: 'materialQuiz.submit'
|
|
145
|
+
})
|
|
146
|
+
}]
|
|
147
|
+
}, materialQuiz ? React__default["default"].createElement(QuestionRadio, {
|
|
148
|
+
selectedValue: selectedAnswer,
|
|
149
|
+
onSelect: index$1 => {
|
|
150
|
+
if (index.checkUserLectureTestEnded(lecture) || !!userId) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
setHasSubmitted(false);
|
|
155
|
+
setIsActive(true);
|
|
156
|
+
setSelectedAnswer(index$1);
|
|
157
|
+
},
|
|
158
|
+
disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId
|
|
159
|
+
}, materialQuiz.optionInfo ? materialQuiz.optionInfo.map((option, index$1) => {
|
|
160
|
+
var _a;
|
|
161
|
+
|
|
162
|
+
const getIsSelected = (index, materialQuizResponse) => {
|
|
163
|
+
var _a;
|
|
164
|
+
|
|
165
|
+
if (!materialQuizResponse || typeof materialQuizResponse.answer === 'string') {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return (_a = materialQuizResponse.answer.includes(index)) !== null && _a !== void 0 ? _a : false;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const status = index.getOptionStatus({
|
|
173
|
+
materialQuizResponse,
|
|
174
|
+
isSelected: getIsSelected(index$1, materialQuizResponse),
|
|
175
|
+
isActive
|
|
176
|
+
});
|
|
177
|
+
return React__default["default"].createElement(QuestionRadioOption, {
|
|
178
|
+
key: index$1,
|
|
179
|
+
value: index$1,
|
|
180
|
+
status: status,
|
|
181
|
+
isAnswer: (_a = !!userId && Array.isArray(materialQuiz.answerInfo) && materialQuiz.answerInfo.includes(index$1)) !== null && _a !== void 0 ? _a : false
|
|
182
|
+
}, (course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions) ? React__default["default"].createElement(StyledMarkdown, {
|
|
183
|
+
children: option,
|
|
184
|
+
paddingx: 0,
|
|
185
|
+
paddingy: 0,
|
|
186
|
+
dark: false
|
|
187
|
+
}) : option);
|
|
188
|
+
}) : null) : null);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
module.exports = MaterialQuizSelectOne;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var blocks = require('@elice/blocks');
|
|
5
|
+
var designTokens = require('@elice/design-tokens');
|
|
6
|
+
var styled = require('styled-components');
|
|
7
|
+
var MaterialQuizContext = require('./context/MaterialQuizContext.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
13
|
+
|
|
14
|
+
const StyledShimmer = styled__default["default"].div.withConfig({
|
|
15
|
+
componentId: "sc-10uz5tw-0"
|
|
16
|
+
})(["display:flex;flex-direction:column;border-radius:", ";overflow:hidden;width:100%;"], ({
|
|
17
|
+
vertical
|
|
18
|
+
}) => vertical ? '0' : '8px');
|
|
19
|
+
const StyledShimmerHeader = styled__default["default"].div.withConfig({
|
|
20
|
+
componentId: "sc-10uz5tw-1"
|
|
21
|
+
})(["display:flex;justify-content:space-between;background-color:", ";padding:1rem 1.5rem;height:3.5rem;"], designTokens.base.color.navy6);
|
|
22
|
+
const StyledShimmerBody = styled__default["default"].div.withConfig({
|
|
23
|
+
componentId: "sc-10uz5tw-2"
|
|
24
|
+
})(["padding:1.5rem;background-color:", ";overflow-y:auto;height:100%;"], designTokens.base.color.navy7);
|
|
25
|
+
|
|
26
|
+
const MaterialQuizShimmer = () => {
|
|
27
|
+
const {
|
|
28
|
+
vertical
|
|
29
|
+
} = MaterialQuizContext.useMaterialQuizState();
|
|
30
|
+
return React__default["default"].createElement(StyledShimmer, {
|
|
31
|
+
vertical: vertical
|
|
32
|
+
}, React__default["default"].createElement(StyledShimmerHeader, null), React__default["default"].createElement(StyledShimmerBody, null, React__default["default"].createElement(blocks.Shimmer, {
|
|
33
|
+
dark: true,
|
|
34
|
+
borderRadius: '4px',
|
|
35
|
+
width: "80%",
|
|
36
|
+
height: '40px'
|
|
37
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
38
|
+
height: 1
|
|
39
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
40
|
+
dark: true,
|
|
41
|
+
borderRadius: '4px',
|
|
42
|
+
width: "100%",
|
|
43
|
+
height: '40px'
|
|
44
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
45
|
+
height: 1
|
|
46
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
47
|
+
dark: true,
|
|
48
|
+
borderRadius: '4px',
|
|
49
|
+
width: "100%",
|
|
50
|
+
height: '40px'
|
|
51
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
52
|
+
height: 1
|
|
53
|
+
}), React__default["default"].createElement(blocks.Shimmer, {
|
|
54
|
+
dark: true,
|
|
55
|
+
borderRadius: '4px',
|
|
56
|
+
width: "100%",
|
|
57
|
+
height: '40px'
|
|
58
|
+
})));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = MaterialQuizShimmer;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var apiClient = require('@elice/api-client');
|
|
6
|
+
var blocks = require('@elice/blocks');
|
|
7
|
+
var designTokens = require('@elice/design-tokens');
|
|
8
|
+
var styled = require('styled-components');
|
|
9
|
+
var index = require('../../helpers/index.js');
|
|
10
|
+
var QuestionBox = require('../shared/QuestionBox.js');
|
|
11
|
+
var MaterialQuizContext = require('./context/MaterialQuizContext.js');
|
|
12
|
+
var QuizResultBadge = require('./QuizResultBadge.js');
|
|
13
|
+
var QuizSubmitStatusText = require('./QuizSubmitStatusText.js');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
19
|
+
|
|
20
|
+
const StyledTextarea = styled__default["default"].textarea.withConfig({
|
|
21
|
+
componentId: "sc-186cnpj-0"
|
|
22
|
+
})(["min-height:12rem;width:100%;padding:1rem 1.375rem;font-size:1rem;color:", ";border-radius:4px;resize:vertical;line-height:1.5rem;outline:none;background-color:", ";&::placeholder{color:", ";}&:hover{cursor:", ";}"], designTokens.base.color.navy2, designTokens.base.color.navy5, designTokens.base.color.navy2, ({
|
|
23
|
+
disabled
|
|
24
|
+
}) => disabled ? 'not-allowed' : 'text');
|
|
25
|
+
const StyledLabel = styled__default["default"].label.withConfig({
|
|
26
|
+
componentId: "sc-186cnpj-1"
|
|
27
|
+
})(["font-size:0.875rem;margin-bottom:0.5rem;color:", ";"], designTokens.base.color.navy1);
|
|
28
|
+
|
|
29
|
+
const MaterialQuizText = () => {
|
|
30
|
+
// context
|
|
31
|
+
const {
|
|
32
|
+
lecture,
|
|
33
|
+
materialQuiz,
|
|
34
|
+
userId
|
|
35
|
+
} = MaterialQuizContext.useMaterialQuizState();
|
|
36
|
+
const {
|
|
37
|
+
onSubmit,
|
|
38
|
+
onNext,
|
|
39
|
+
refreshOrgMaterialQuiz
|
|
40
|
+
} = MaterialQuizContext.useMaterialQuizDispatch(); // state
|
|
41
|
+
|
|
42
|
+
const intl = reactIntl.useIntl();
|
|
43
|
+
const [materialQuizResponse, setMaterialQuizResponse] = React__default["default"].useState();
|
|
44
|
+
const [submitStatus, setSubmitStatus] = React__default["default"].useState('idle');
|
|
45
|
+
const [answer, setAnswer] = React__default["default"].useState('');
|
|
46
|
+
const [hasSubmitted, setHasSubmitted] = React__default["default"].useState(false); // quiz response fetcher
|
|
47
|
+
|
|
48
|
+
React__default["default"].useEffect(() => {
|
|
49
|
+
if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
const {
|
|
52
|
+
signal
|
|
53
|
+
} = controller;
|
|
54
|
+
apiClient.getOrgMaterialQuizResponseGet({
|
|
55
|
+
quizResponseId: materialQuiz.lastQuizResponseId
|
|
56
|
+
}, {
|
|
57
|
+
signal
|
|
58
|
+
}).then(response => {
|
|
59
|
+
setMaterialQuizResponse(response.quizResponse);
|
|
60
|
+
setAnswer(response.quizResponse.answer);
|
|
61
|
+
}).catch(error => {
|
|
62
|
+
console.error(error);
|
|
63
|
+
});
|
|
64
|
+
return () => controller.abort();
|
|
65
|
+
}
|
|
66
|
+
}, [materialQuiz, userId]); // quiz response fetcher
|
|
67
|
+
|
|
68
|
+
React__default["default"].useEffect(() => {
|
|
69
|
+
if (userId && materialQuiz) {
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
const {
|
|
72
|
+
signal
|
|
73
|
+
} = controller;
|
|
74
|
+
apiClient.getOrgMaterialQuizResponseList({
|
|
75
|
+
materialQuizId: materialQuiz.id,
|
|
76
|
+
filterUserIds: [userId],
|
|
77
|
+
isContainOnlyLast: true,
|
|
78
|
+
isIncludeAnswer: true,
|
|
79
|
+
offset: 0,
|
|
80
|
+
count: 1
|
|
81
|
+
}, {
|
|
82
|
+
signal
|
|
83
|
+
}).then(response => {
|
|
84
|
+
const quizResponse = response.quizResponses[0];
|
|
85
|
+
setMaterialQuizResponse(quizResponse);
|
|
86
|
+
setAnswer(typeof (quizResponse === null || quizResponse === void 0 ? void 0 : quizResponse.answer) === 'string' ? quizResponse.answer : '');
|
|
87
|
+
}).catch(error => {
|
|
88
|
+
console.error(error);
|
|
89
|
+
});
|
|
90
|
+
return () => controller.abort();
|
|
91
|
+
}
|
|
92
|
+
}, [materialQuiz, userId]); // submit handler
|
|
93
|
+
|
|
94
|
+
const handleSubmit = async () => {
|
|
95
|
+
if (!materialQuiz) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setSubmitStatus('pending');
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const {
|
|
103
|
+
quizResponseId
|
|
104
|
+
} = await apiClient.postOrgMaterialQuizResponseAdd({
|
|
105
|
+
materialQuizId: materialQuiz.id,
|
|
106
|
+
answer: JSON.stringify(answer)
|
|
107
|
+
});
|
|
108
|
+
const {
|
|
109
|
+
quizResponse
|
|
110
|
+
} = await apiClient.getOrgMaterialQuizResponseGet({
|
|
111
|
+
quizResponseId
|
|
112
|
+
});
|
|
113
|
+
setHasSubmitted(true);
|
|
114
|
+
setMaterialQuizResponse(quizResponse);
|
|
115
|
+
void refreshOrgMaterialQuiz();
|
|
116
|
+
onSubmit(true, index.getQuizResult(quizResponse));
|
|
117
|
+
setSubmitStatus('resolved');
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(error);
|
|
120
|
+
onSubmit(false);
|
|
121
|
+
setSubmitStatus('rejected');
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const commonProps = {
|
|
126
|
+
type: 'text',
|
|
127
|
+
autoFocus: answer.length === 0,
|
|
128
|
+
disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
129
|
+
placeholder: (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.answerHint) || intl.formatMessage({
|
|
130
|
+
id: 'materialQuiz.text.placeholder'
|
|
131
|
+
}),
|
|
132
|
+
value: answer,
|
|
133
|
+
onChange: e => {
|
|
134
|
+
setHasSubmitted(false);
|
|
135
|
+
setAnswer(e.target.value);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return React__default["default"].createElement(QuestionBox["default"], {
|
|
139
|
+
onNext: onNext,
|
|
140
|
+
submitResult: React__default["default"].createElement(QuizResultBadge, {
|
|
141
|
+
materialQuizResponse: materialQuizResponse
|
|
142
|
+
}),
|
|
143
|
+
submitStatus: React__default["default"].createElement(QuizSubmitStatusText, {
|
|
144
|
+
status: submitStatus
|
|
145
|
+
}),
|
|
146
|
+
isNextActive: hasSubmitted && typeof onNext === 'function',
|
|
147
|
+
footerActions: [{
|
|
148
|
+
border: true,
|
|
149
|
+
children: intl.formatMessage({
|
|
150
|
+
id: 'materialQuiz.submit'
|
|
151
|
+
}),
|
|
152
|
+
disabled: answer.length === 0 || index.checkUserLectureTestEnded(lecture) || !!userId,
|
|
153
|
+
loading: submitStatus === 'pending',
|
|
154
|
+
tabIndex: 0,
|
|
155
|
+
transparent: false,
|
|
156
|
+
role: 'primary',
|
|
157
|
+
onClick: handleSubmit
|
|
158
|
+
}]
|
|
159
|
+
}, React__default["default"].createElement(blocks.Flex, {
|
|
160
|
+
column: true
|
|
161
|
+
}, userId ? React__default["default"].createElement(StyledLabel, {
|
|
162
|
+
htmlFor: "quiz-text-answer"
|
|
163
|
+
}, intl.formatMessage({
|
|
164
|
+
id: 'materialQuiz.submittedAnswer'
|
|
165
|
+
})) : null, React__default["default"].createElement(StyledTextarea, Object.assign({
|
|
166
|
+
id: "quiz-text-answer"
|
|
167
|
+
}, commonProps))), userId ? React__default["default"].createElement(blocks.Flex, {
|
|
168
|
+
column: true,
|
|
169
|
+
margintop: "1rem"
|
|
170
|
+
}, React__default["default"].createElement(StyledLabel, {
|
|
171
|
+
htmlFor: "quiz-text-submitted-answer"
|
|
172
|
+
}, intl.formatMessage({
|
|
173
|
+
id: 'materialQuiz.answer'
|
|
174
|
+
})), React__default["default"].createElement(StyledTextarea, {
|
|
175
|
+
id: "quiz-text-submitted-answer",
|
|
176
|
+
disabled: true,
|
|
177
|
+
value: typeof (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.answerInfo) === 'string' ? materialQuiz.answerInfo : ''
|
|
178
|
+
})) : null);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
module.exports = MaterialQuizText;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GetOrgMaterialQuizResponseGetResponses } from '@elice/types';
|
|
3
|
+
interface QuizResultStatusProps {
|
|
4
|
+
materialQuizResponse?: GetOrgMaterialQuizResponseGetResponses['quizResponse'];
|
|
5
|
+
}
|
|
6
|
+
declare const QuizResultBadge: React.FC<QuizResultStatusProps>;
|
|
7
|
+
export default QuizResultBadge;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var blocks = require('@elice/blocks');
|
|
6
|
+
var index = require('../../helpers/index.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
11
|
+
|
|
12
|
+
const QuizResultBadge = ({
|
|
13
|
+
materialQuizResponse
|
|
14
|
+
}) => {
|
|
15
|
+
const intl = reactIntl.useIntl();
|
|
16
|
+
const status = React__default["default"].useMemo(() => index.getQuizResultStatus(materialQuizResponse), [materialQuizResponse]);
|
|
17
|
+
|
|
18
|
+
switch (status) {
|
|
19
|
+
case index.QuizResultStatus.Correct:
|
|
20
|
+
return React__default["default"].createElement(blocks.BadgeNext, {
|
|
21
|
+
type: "quiet",
|
|
22
|
+
role: "green"
|
|
23
|
+
}, intl.formatMessage({
|
|
24
|
+
id: 'materialQuiz.resultStatus.correct'
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
case index.QuizResultStatus.Wrong:
|
|
28
|
+
return React__default["default"].createElement(blocks.BadgeNext, {
|
|
29
|
+
type: "quiet",
|
|
30
|
+
role: "red"
|
|
31
|
+
}, intl.formatMessage({
|
|
32
|
+
id: 'materialQuiz.resultStatus.wrong'
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
case index.QuizResultStatus.Submitted:
|
|
36
|
+
return React__default["default"].createElement(blocks.BadgeNext, {
|
|
37
|
+
type: "quiet",
|
|
38
|
+
role: "primary"
|
|
39
|
+
}, intl.formatMessage({
|
|
40
|
+
id: 'materialQuiz.resultStatus.submitted'
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
default:
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = QuizResultBadge;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { APIStatus } from '@elice/material-shared-types';
|
|
3
|
+
interface QuizSubmitStatusTextProps {
|
|
4
|
+
status: APIStatus;
|
|
5
|
+
}
|
|
6
|
+
declare const QuizSubmitStatusText: React.FC<QuizSubmitStatusTextProps>;
|
|
7
|
+
export default QuizSubmitStatusText;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactIntl = require('react-intl');
|
|
5
|
+
var blocks = require('@elice/blocks');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
+
|
|
11
|
+
const QuizSubmitStatusText = ({
|
|
12
|
+
status
|
|
13
|
+
}) => {
|
|
14
|
+
const intl = reactIntl.useIntl();
|
|
15
|
+
|
|
16
|
+
switch (status) {
|
|
17
|
+
case 'resolved':
|
|
18
|
+
return React__default["default"].createElement(blocks.StatusText, {
|
|
19
|
+
role: "success",
|
|
20
|
+
size: "small"
|
|
21
|
+
}, intl.formatMessage({
|
|
22
|
+
id: 'materialQuiz.submitStatus.success'
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
case 'rejected':
|
|
26
|
+
return React__default["default"].createElement(blocks.StatusText, {
|
|
27
|
+
role: "danger",
|
|
28
|
+
size: "small"
|
|
29
|
+
}, intl.formatMessage({
|
|
30
|
+
id: 'materialQuiz.submitStatus.failure'
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
default:
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = QuizSubmitStatusText;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { APIStatus } from '@elice/material-shared-types';
|
|
3
|
+
import type { GetOrgCourseGetResponses, GetOrgLectureGetResponses, GetOrgMaterialQuizGetResponses } from '@elice/types';
|
|
4
|
+
export interface State {
|
|
5
|
+
course?: GetOrgCourseGetResponses['course'];
|
|
6
|
+
lecture?: GetOrgLectureGetResponses['lecture'];
|
|
7
|
+
materialQuiz?: GetOrgMaterialQuizGetResponses['materialQuiz'];
|
|
8
|
+
vertical: boolean;
|
|
9
|
+
userId?: number;
|
|
10
|
+
initStatus: APIStatus;
|
|
11
|
+
}
|
|
12
|
+
export declare type MaterialQuizProps = {
|
|
13
|
+
materialQuizId: number;
|
|
14
|
+
userId?: number;
|
|
15
|
+
locale?: string;
|
|
16
|
+
onSubmit?: (isSucceeded: boolean, isCorrect?: boolean) => void;
|
|
17
|
+
onNext?: () => void;
|
|
18
|
+
};
|
|
19
|
+
interface MaterialQuizProviderProps extends Omit<MaterialQuizProps, 'locale'> {
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
interface DispatchContextType {
|
|
23
|
+
onSubmit: (isSucceeded: boolean, isCorrect?: boolean) => void;
|
|
24
|
+
refreshOrgMaterialQuiz: (signal?: AbortSignal | undefined) => Promise<void>;
|
|
25
|
+
setVertical: React.Dispatch<React.SetStateAction<boolean>>;
|
|
26
|
+
onNext?: () => void;
|
|
27
|
+
}
|
|
28
|
+
declare function MaterialQuizProvider({ materialQuizId, userId, onSubmit, onNext, children, }: MaterialQuizProviderProps): JSX.Element;
|
|
29
|
+
declare function useMaterialQuizState(): State;
|
|
30
|
+
declare function useMaterialQuizDispatch(): DispatchContextType;
|
|
31
|
+
export { MaterialQuizProvider, useMaterialQuizState, useMaterialQuizDispatch };
|