@elice/material-quiz 1.221129.0 → 1.221209.0-quiz.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.
Files changed (69) hide show
  1. package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +6 -0
  2. package/cjs/components/material-quiz/MaterialQuiz.i18n.js +14 -2
  3. package/cjs/components/material-quiz/MaterialQuiz.js +7 -1
  4. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +13 -8
  5. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +48 -25
  6. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +13 -9
  7. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.d.ts +3 -0
  8. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +296 -0
  9. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.d.ts +3 -0
  10. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +162 -0
  11. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.d.ts +3 -0
  12. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +143 -0
  13. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.d.ts +8 -0
  14. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +80 -0
  15. package/cjs/components/material-quiz/material-quiz-group/context/context.d.ts +22 -0
  16. package/cjs/components/material-quiz/material-quiz-group/context/context.js +11 -0
  17. package/cjs/components/material-quiz/material-quiz-group/index.d.ts +1 -0
  18. package/cjs/components/material-quiz/material-quiz-group/index.js +7 -0
  19. package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +2 -2
  20. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +60 -8
  21. package/cjs/components/material-quiz-edit/locales.d.ts +12 -0
  22. package/cjs/components/material-quiz-edit/locales.js +26 -2
  23. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +4 -3
  24. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +4 -3
  25. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +4 -3
  26. package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.d.ts +3 -0
  27. package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +25 -0
  28. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.d.ts +3 -0
  29. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +311 -0
  30. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.d.ts +3 -0
  31. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +222 -0
  32. package/cjs/components/material-quiz-edit/utils/editValue.d.ts +8 -3
  33. package/cjs/components/material-quiz-edit/utils/editValue.js +19 -4
  34. package/cjs/helpers/index.d.ts +2 -3
  35. package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +6 -0
  36. package/es/components/material-quiz/MaterialQuiz.i18n.js +14 -2
  37. package/es/components/material-quiz/MaterialQuiz.js +7 -1
  38. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +13 -8
  39. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +48 -25
  40. package/es/components/material-quiz/MaterialQuizSelectOne.js +13 -9
  41. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.d.ts +3 -0
  42. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +289 -0
  43. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.d.ts +3 -0
  44. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +155 -0
  45. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.d.ts +3 -0
  46. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +136 -0
  47. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.d.ts +8 -0
  48. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +73 -0
  49. package/es/components/material-quiz/material-quiz-group/context/context.d.ts +22 -0
  50. package/es/components/material-quiz/material-quiz-group/context/context.js +5 -0
  51. package/es/components/material-quiz/material-quiz-group/index.d.ts +1 -0
  52. package/es/components/material-quiz/material-quiz-group/index.js +1 -0
  53. package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +2 -2
  54. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +60 -8
  55. package/es/components/material-quiz-edit/locales.d.ts +12 -0
  56. package/es/components/material-quiz-edit/locales.js +26 -2
  57. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +4 -3
  58. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +4 -3
  59. package/es/components/material-quiz-edit/options/OptionSelectOne.js +4 -3
  60. package/es/components/material-quiz-edit/options/options-group/OptionGroup.d.ts +3 -0
  61. package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +19 -0
  62. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.d.ts +3 -0
  63. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +304 -0
  64. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.d.ts +3 -0
  65. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +215 -0
  66. package/es/components/material-quiz-edit/utils/editValue.d.ts +8 -3
  67. package/es/components/material-quiz-edit/utils/editValue.js +19 -4
  68. package/es/helpers/index.d.ts +2 -3
  69. package/package.json +8 -6
@@ -21,5 +21,11 @@ export declare const en: {
21
21
  'materialQuiz.text.correct': string;
22
22
  'materialQuiz.text.wrong': string;
23
23
  'materialQuiz.order.answerEmpty': string;
24
+ 'materialQuiz.bottomSheet.title': string;
25
+ 'materialQuiz.bottomSheet.optionEmpty': string;
26
+ 'materialQuiz.dropzone.desktop.answerEmpty': string;
27
+ 'materialQuiz.dropzone.mobile.answerEmpty': string;
28
+ 'materialQuiz.dropzone.optionEmpty': string;
29
+ 'materialQuiz.dropzone.optionReset': string;
24
30
  };
25
31
  export declare const ko: typeof en;
@@ -24,7 +24,13 @@ const en = {
24
24
  'materialQuiz.text.placeholder': 'please fill the answer',
25
25
  'materialQuiz.text.correct': `that's correct!`,
26
26
  'materialQuiz.text.wrong': `that's wrong. try it again!`,
27
- 'materialQuiz.order.answerEmpty': 'You could move the options back here'
27
+ 'materialQuiz.order.answerEmpty': 'You could move the options back here',
28
+ 'materialQuiz.bottomSheet.title': 'Answer',
29
+ 'materialQuiz.bottomSheet.optionEmpty': 'All views have been placed in the group.',
30
+ 'materialQuiz.dropzone.desktop.answerEmpty': 'Drag the view into the area.',
31
+ 'materialQuiz.dropzone.mobile.answerEmpty': 'Click here to add a view.',
32
+ 'materialQuiz.dropzone.optionEmpty': 'Option',
33
+ 'materialQuiz.dropzone.optionReset': 'Answer Reset'
28
34
  };
29
35
  const ko = {
30
36
  'materialQuiz.error': '퀴즈를 불러오는데 실패했습니다.\n잠시 후 다시 시도해주세요.',
@@ -48,7 +54,13 @@ const ko = {
48
54
  'materialQuiz.text.placeholder': '답을 입력하세요.',
49
55
  'materialQuiz.text.correct': '정답입니다.',
50
56
  'materialQuiz.text.wrong': '오답입니다. 다시 답안을 제출해보세요.',
51
- 'materialQuiz.order.answerEmpty': '항목을 다시 이곳으로 옮길 수 있습니다.'
57
+ 'materialQuiz.order.answerEmpty': '항목을 다시 이곳으로 옮길 수 있습니다.',
58
+ 'materialQuiz.bottomSheet.title': '답안',
59
+ 'materialQuiz.bottomSheet.optionEmpty': '모든 보기를 그룹에 배치하였습니다.',
60
+ 'materialQuiz.dropzone.desktop.answerEmpty': '보기를 영역에 끌어 넣어주세요.',
61
+ 'materialQuiz.dropzone.mobile.answerEmpty': '이곳을 클릭하여 보기를 넣어주세요.',
62
+ 'materialQuiz.dropzone.optionEmpty': '보기',
63
+ 'materialQuiz.dropzone.optionReset': '답안 초기화'
52
64
  };
53
65
 
54
66
  exports.en = en;
@@ -22,6 +22,7 @@ const AsyncMaterialQuizSelectMultiple = React__default["default"].lazy(() => Pro
22
22
  const AsyncMaterialQuizSelectMultipleOrder = React__default["default"].lazy(() => Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./MaterialQuizSelectMultipleOrder.js')); }));
23
23
  const AsyncMaterialQuizText = React__default["default"].lazy(() => Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./MaterialQuizText.js')); }));
24
24
  const AsyncMaterialQuizSelectOne = React__default["default"].lazy(() => Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./MaterialQuizSelectOne.js')); }));
25
+ const AsyncMaterialQuizGroup = React__default["default"].lazy(() => Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./material-quiz-group/index.js')); }));
25
26
  const StyledMaterialQuizInfo = styled__default["default"].div.withConfig({
26
27
  componentId: "sc-1eyn8fb-0"
27
28
  })([""]);
@@ -55,6 +56,7 @@ const MaterialQuiz = () => {
55
56
  const [ref, {
56
57
  width
57
58
  }] = reactUse.useMeasure();
59
+ const isQuizGroupType = Boolean((materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.optionType) === types.enums.QuizOptionType.Group);
58
60
  React__default["default"].useEffect(() => {
59
61
  if (width > 0) {
60
62
  setVertical(width <= designTokens.base.screen.medium);
@@ -79,6 +81,10 @@ const MaterialQuiz = () => {
79
81
  Component = React__default["default"].createElement(AsyncMaterialQuizSelectMultipleOrder, null);
80
82
  break;
81
83
 
84
+ case types.enums.QuizOptionType.Group:
85
+ Component = React__default["default"].createElement(AsyncMaterialQuizGroup, null);
86
+ break;
87
+
82
88
  default:
83
89
  Component = React__default["default"].createElement(MaterialQuizShimmer, null);
84
90
  break;
@@ -89,7 +95,7 @@ const MaterialQuiz = () => {
89
95
  }, React__default["default"].createElement(StyledMaterialQuizWrapper, {
90
96
  ref: ref,
91
97
  vertical: vertical
92
- }, React__default["default"].createElement(StyledMaterialQuizInfo, null, React__default["default"].createElement(MaterialQuizInfo, null)), React__default["default"].createElement(StyledMaterialQuizContent, null, Component)));
98
+ }, isQuizGroupType ? null : React__default["default"].createElement(StyledMaterialQuizInfo, null, React__default["default"].createElement(MaterialQuizInfo, null)), React__default["default"].createElement(StyledMaterialQuizContent, null, Component)));
93
99
  };
94
100
 
95
101
  const MaterialQuizContainer = ({
@@ -87,10 +87,11 @@ const MaterialQuizSelectMultiple = () => {
87
87
  signal
88
88
  }).then(response => {
89
89
  const quizResponse = response.quizResponses[0];
90
+ const quizResponseAnswer = quizResponse.answer;
90
91
  setMaterialQuizResponse(quizResponse);
91
92
 
92
- if (Array.isArray(quizResponse.answer)) {
93
- setSelectedAnswer(quizResponse.answer);
93
+ if (Array.isArray(quizResponseAnswer)) {
94
+ setSelectedAnswer(quizResponseAnswer);
94
95
  }
95
96
  }).catch(error => {
96
97
  console.error(error);
@@ -170,15 +171,18 @@ const MaterialQuizSelectMultiple = () => {
170
171
  },
171
172
  selectedOptions: selectedAnswer,
172
173
  disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId
173
- }, (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.optionInfo) ? materialQuiz.optionInfo.map((option, index$1) => {
174
+ }, (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) ? materialQuiz.options.map((option, index$1) => {
175
+ var _a;
176
+
174
177
  const getIsSelected = (index, materialQuizResponse) => {
175
178
  var _a;
176
179
 
177
- if (!materialQuizResponse || typeof materialQuizResponse.answer === 'string') {
180
+ if (!materialQuizResponse) {
178
181
  return false;
179
182
  }
180
183
 
181
- return (_a = materialQuizResponse.answer.includes(index)) !== null && _a !== void 0 ? _a : false;
184
+ const materialQuizResponseAnswer = materialQuizResponse.answer;
185
+ return (_a = materialQuizResponseAnswer.includes(index)) !== null && _a !== void 0 ? _a : false;
182
186
  };
183
187
 
184
188
  const status = index.getOptionStatus({
@@ -186,17 +190,18 @@ const MaterialQuizSelectMultiple = () => {
186
190
  isSelected: getIsSelected(index$1, materialQuizResponse),
187
191
  isActive
188
192
  });
193
+ const materialQuizAnswerInfo = materialQuiz.answerInfo;
189
194
  return React__default["default"].createElement(QuestionCheckboxOption, {
190
195
  key: index$1,
191
196
  value: index$1,
192
197
  status: status,
193
- isAnswer: !!userId && Array.isArray(materialQuiz.answerInfo) && materialQuiz.answerInfo.includes(index$1)
198
+ isAnswer: !!userId && Array.isArray(materialQuizAnswerInfo) && materialQuizAnswerInfo.includes(index$1)
194
199
  }, (course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions) ? React__default["default"].createElement(StyledMarkdown, {
195
- children: option,
200
+ children: (_a = option === null || option === void 0 ? void 0 : option.text) !== null && _a !== void 0 ? _a : '',
196
201
  paddingx: 0,
197
202
  paddingy: 0,
198
203
  dark: false
199
- }) : option);
204
+ }) : option === null || option === void 0 ? void 0 : option.text);
200
205
  }) : null));
201
206
  };
202
207
 
@@ -155,19 +155,29 @@ const MaterialQuizSelectMultipleOrder = () => {
155
155
  }, {
156
156
  signal
157
157
  }).then(response => {
158
+ var _a;
159
+
158
160
  setMaterialQuizResponse(response.quizResponse);
159
161
  const answer = response.quizResponse.answer; // user submitted
160
162
 
161
- const optionInfo = materialQuiz.optionInfo; // options
163
+ const options = (_a = materialQuiz.options) !== null && _a !== void 0 ? _a : []; // options
164
+
165
+ const answerList = answer.map(answer => {
166
+ var _a, _b;
162
167
 
163
- const answerList = answer.map(answer => ({
164
- order: answer,
165
- value: optionInfo[answer]
166
- }), []);
167
- const optionList = optionInfo.filter((item, index) => !answer.includes(index)).map(option => ({
168
- order: optionInfo.findIndex(optionInfo => optionInfo === option),
169
- value: option
170
- }));
168
+ return {
169
+ order: answer,
170
+ value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ''
171
+ };
172
+ }, []);
173
+ const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
174
+ var _a;
175
+
176
+ return {
177
+ order: options.findIndex(optionInfo => optionInfo === option),
178
+ value: (_a = option === null || option === void 0 ? void 0 : option.text) !== null && _a !== void 0 ? _a : ''
179
+ };
180
+ });
171
181
  setAnswerList(answerList);
172
182
  setOptionList(optionList);
173
183
  }).catch(error => {
@@ -175,10 +185,14 @@ const MaterialQuizSelectMultipleOrder = () => {
175
185
  });
176
186
  return () => controller.abort();
177
187
  } else {
178
- setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.optionInfo) === null || _a === void 0 ? void 0 : _a.map((option, index) => ({
179
- order: index,
180
- value: option
181
- }))) || []);
188
+ setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map((option, index) => {
189
+ var _a;
190
+
191
+ return {
192
+ order: index,
193
+ value: (_a = option === null || option === void 0 ? void 0 : option.text) !== null && _a !== void 0 ? _a : ''
194
+ };
195
+ })) || []);
182
196
  setAnswerList(Array.from({
183
197
  length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
184
198
  }, () => ({
@@ -210,24 +224,33 @@ const MaterialQuizSelectMultipleOrder = () => {
210
224
  setMaterialQuizResponse(quizResponse);
211
225
  const answer = (_a = quizResponse === null || quizResponse === void 0 ? void 0 : quizResponse.answer) !== null && _a !== void 0 ? _a : []; // user submitted
212
226
 
213
- const optionInfo = materialQuiz.optionInfo; // options
227
+ const options = (_b = materialQuiz.options) !== null && _b !== void 0 ? _b : []; // options
214
228
 
215
- const correctAnswerList = Array.isArray(materialQuiz.answerInfo) ? (_c = (_b = materialQuiz.answerInfo) === null || _b === void 0 ? void 0 : _b.map(answerInfo => {
216
- var _a, _b;
229
+ const materialQuizAnswerInfo = materialQuiz.answerInfo;
230
+ const correctAnswerList = Array.isArray(materialQuizAnswerInfo) ? (_c = materialQuizAnswerInfo === null || materialQuizAnswerInfo === void 0 ? void 0 : materialQuizAnswerInfo.map(answerInfo => {
231
+ var _a, _b, _c;
217
232
 
218
233
  return {
219
234
  order: answerInfo,
220
- value: (_b = (_a = materialQuiz.optionInfo) === null || _a === void 0 ? void 0 : _a[answerInfo]) !== null && _b !== void 0 ? _b : ''
235
+ value: (_c = (_b = (_a = materialQuiz.options) === null || _a === void 0 ? void 0 : _a[answerInfo]) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : ''
221
236
  };
222
237
  })) !== null && _c !== void 0 ? _c : [] : [];
223
- const answerList = answer.map(answer => ({
224
- order: answer,
225
- value: optionInfo[answer]
226
- }), []);
227
- const optionList = optionInfo.filter((item, index) => !answer.includes(index)).map(option => ({
228
- order: optionInfo.findIndex(optionInfo => optionInfo === option),
229
- value: option
230
- }));
238
+ const answerList = answer.map(answer => {
239
+ var _a, _b;
240
+
241
+ return {
242
+ order: answer,
243
+ value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : ''
244
+ };
245
+ }, []);
246
+ const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
247
+ var _a;
248
+
249
+ return {
250
+ order: options.findIndex(optionInfo => optionInfo === option),
251
+ value: (_a = option === null || option === void 0 ? void 0 : option.text) !== null && _a !== void 0 ? _a : ''
252
+ };
253
+ });
231
254
  setCorrectAnswerList(correctAnswerList);
232
255
  setAnswerList(answerList);
233
256
  setOptionList(optionList);
@@ -53,8 +53,9 @@ const MaterialQuizSelectOne = () => {
53
53
  }, {
54
54
  signal
55
55
  }).then(response => {
56
+ const quizResponseAnswer = response.quizResponse.answer;
56
57
  setMaterialQuizResponse(response.quizResponse);
57
- setSelectedAnswer(typeof response.quizResponse.answer === 'string' ? undefined : response.quizResponse.answer[0]);
58
+ setSelectedAnswer(typeof response.quizResponse.answer === 'string' ? undefined : quizResponseAnswer[0]);
58
59
  }).catch(error => {
59
60
  console.error(error);
60
61
  });
@@ -79,8 +80,9 @@ const MaterialQuizSelectOne = () => {
79
80
  signal
80
81
  }).then(response => {
81
82
  const quizResponse = response.quizResponses[0];
83
+ const quizResponseAnswer = quizResponse.answer;
82
84
  setMaterialQuizResponse(quizResponse);
83
- setSelectedAnswer(typeof quizResponse.answer === 'string' ? undefined : quizResponse.answer[0]);
85
+ setSelectedAnswer(typeof quizResponse.answer === 'string' ? undefined : quizResponseAnswer[0]);
84
86
  }).catch(error => {
85
87
  console.error(error);
86
88
  });
@@ -156,17 +158,18 @@ const MaterialQuizSelectOne = () => {
156
158
  setSelectedAnswer(index$1);
157
159
  },
158
160
  disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId
159
- }, materialQuiz.optionInfo ? materialQuiz.optionInfo.map((option, index$1) => {
160
- var _a;
161
+ }, materialQuiz.options ? materialQuiz.options.map((option, index$1) => {
162
+ var _a, _b;
161
163
 
162
164
  const getIsSelected = (index, materialQuizResponse) => {
163
165
  var _a;
164
166
 
165
- if (!materialQuizResponse || typeof materialQuizResponse.answer === 'string') {
167
+ if (!materialQuizResponse) {
166
168
  return false;
167
169
  }
168
170
 
169
- return (_a = materialQuizResponse.answer.includes(index)) !== null && _a !== void 0 ? _a : false;
171
+ const materialQuizResponseAnswer = materialQuizResponse.answer;
172
+ return (_a = materialQuizResponseAnswer.includes(index)) !== null && _a !== void 0 ? _a : false;
170
173
  };
171
174
 
172
175
  const status = index.getOptionStatus({
@@ -174,17 +177,18 @@ const MaterialQuizSelectOne = () => {
174
177
  isSelected: getIsSelected(index$1, materialQuizResponse),
175
178
  isActive
176
179
  });
180
+ const materialQuizAnswerInfo = materialQuiz.answerInfo;
177
181
  return React__default["default"].createElement(QuestionRadioOption, {
178
182
  key: index$1,
179
183
  value: index$1,
180
184
  status: status,
181
- isAnswer: (_a = !!userId && Array.isArray(materialQuiz.answerInfo) && materialQuiz.answerInfo.includes(index$1)) !== null && _a !== void 0 ? _a : false
185
+ isAnswer: (_a = !!userId && Array.isArray(materialQuizAnswerInfo) && materialQuizAnswerInfo.includes(index$1)) !== null && _a !== void 0 ? _a : false
182
186
  }, (course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions) ? React__default["default"].createElement(StyledMarkdown, {
183
- children: option,
187
+ children: (_b = option === null || option === void 0 ? void 0 : option.text) !== null && _b !== void 0 ? _b : '',
184
188
  paddingx: 0,
185
189
  paddingy: 0,
186
190
  dark: false
187
- }) : option);
191
+ }) : option === null || option === void 0 ? void 0 : option.text);
188
192
  }) : null) : null);
189
193
  };
190
194
 
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const MaterialQuizGroup: React.FC;
3
+ export default MaterialQuizGroup;
@@ -0,0 +1,296 @@
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 markdown = require('@elice/markdown');
9
+ var lodashEs = require('lodash-es');
10
+ var flattenDeep = require('lodash-es/flattenDeep');
11
+ var index = require('../../../helpers/index.js');
12
+ var QuestionBox = require('../../shared/QuestionBox.js');
13
+ var MaterialQuizContext = require('../context/MaterialQuizContext.js');
14
+ var QuizResultBadge = require('../QuizResultBadge.js');
15
+ var QuizSubmitStatusText = require('../QuizSubmitStatusText.js');
16
+ var context = require('./context/context.js');
17
+ var MaterialQuizGroupDesktop = require('./MaterialQuizGroupDesktop.js');
18
+ var MaterialQuizGroupMobile = require('./MaterialQuizGroupMobile.js');
19
+
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
22
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
23
+ var flattenDeep__default = /*#__PURE__*/_interopDefaultLegacy(flattenDeep);
24
+
25
+ const MaterialQuizGroup = () => {
26
+ const intl = reactIntl.useIntl(); // context
27
+
28
+ const {
29
+ materialQuiz,
30
+ userId,
31
+ vertical
32
+ } = MaterialQuizContext.useMaterialQuizState();
33
+ const {
34
+ onSubmit,
35
+ onNext,
36
+ refreshOrgMaterialQuiz
37
+ } = MaterialQuizContext.useMaterialQuizDispatch();
38
+ const [groupList, setGroupList] = React__default["default"].useState([]);
39
+ const [optionList, setOptionList] = React__default["default"].useState([]);
40
+ const [currentAnswerList, setCurrentAnswerList] = React__default["default"].useState([]);
41
+ const [currentOptionList, setCurrentOptionList] = React__default["default"].useState([]);
42
+ const [materialQuizResponse, setMaterialQuizResponse] = React__default["default"].useState();
43
+ const [submitStatus, setSubmitStatus] = React__default["default"].useState('idle');
44
+ const [hasSubmitted, setHasSubmitted] = React__default["default"].useState(false);
45
+ /**
46
+ *
47
+ */
48
+
49
+ const getCurrentAnswer = (answerInfo, materialOptionList, materialGroupList) => {
50
+ if (answerInfo.length) {
51
+ const userAnswerList = answerInfo.map(answers => answers.map(answer => ({
52
+ order: answer,
53
+ options: materialOptionList[answer]
54
+ })));
55
+
56
+ if (answerInfo.length !== materialGroupList.length) {
57
+ const deficientAnswerList = new Array(materialGroupList.length - answerInfo.length).fill([]);
58
+ return [...userAnswerList, ...deficientAnswerList];
59
+ }
60
+
61
+ return userAnswerList;
62
+ } else {
63
+ return new Array(materialGroupList.length).fill([]);
64
+ }
65
+ };
66
+ /**
67
+ *
68
+ */
69
+
70
+
71
+ const initQuizGroupInfo = React__default["default"].useCallback(answerInfo => {
72
+ var _a, _b;
73
+
74
+ if (!materialQuiz) {
75
+ return;
76
+ }
77
+
78
+ const materialOptionList = (_a = materialQuiz.options) !== null && _a !== void 0 ? _a : []; // options
79
+
80
+ const materialGroupList = (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.groups) !== null && _b !== void 0 ? _b : []; // groups
81
+
82
+ const flattenAnswerList = flattenDeep__default["default"](answerInfo);
83
+ const userAnswerList = getCurrentAnswer(answerInfo, materialOptionList, materialGroupList);
84
+ const userOptionList = materialOptionList.filter((_, index) => !flattenAnswerList.includes(index)).map(option => {
85
+ const order = materialOptionList.findIndex(optionInfo => optionInfo === option);
86
+ return {
87
+ order,
88
+ options: materialOptionList[order]
89
+ };
90
+ });
91
+ const optionList = materialOptionList.map((option, index) => ({
92
+ order: materialOptionList.findIndex(optionInfo => optionInfo === option),
93
+ options: materialOptionList[index]
94
+ }));
95
+ setGroupList(materialGroupList);
96
+ setOptionList(optionList);
97
+ setCurrentAnswerList(userAnswerList);
98
+ setCurrentOptionList(userOptionList);
99
+ }, [materialQuiz]);
100
+ /**
101
+ * submit handler
102
+ */
103
+
104
+ const handleSubmit = async () => {
105
+ if (!materialQuiz) {
106
+ return;
107
+ }
108
+
109
+ setSubmitStatus('pending');
110
+
111
+ try {
112
+ const {
113
+ quizResponseId
114
+ } = await apiClient.postOrgMaterialQuizResponseAdd({
115
+ materialQuizId: materialQuiz.id,
116
+ answer: currentAnswerList.map(answers => answers.map(answer => answer.order))
117
+ });
118
+ const {
119
+ quizResponse
120
+ } = await apiClient.getOrgMaterialQuizResponseGet({
121
+ quizResponseId
122
+ });
123
+ setMaterialQuizResponse(quizResponse);
124
+ void refreshOrgMaterialQuiz();
125
+ setHasSubmitted(true);
126
+ onSubmit(true, index.getQuizResult(quizResponse));
127
+ setSubmitStatus('resolved');
128
+ } catch (error) {
129
+ console.error(error);
130
+ onSubmit(false);
131
+ setSubmitStatus('rejected');
132
+ }
133
+ };
134
+ /**
135
+ *
136
+ */
137
+
138
+
139
+ const handleAnswerReset = () => {
140
+ const cloneAnswerList = lodashEs.cloneDeep(currentAnswerList);
141
+ const emptyAnswerList = cloneAnswerList.map(() => []);
142
+ setCurrentAnswerList(emptyAnswerList);
143
+ setCurrentOptionList(optionList);
144
+ };
145
+ /**
146
+ *
147
+ */
148
+
149
+
150
+ const updateCurrentAnswer = (targetId, dropzoneIndex) => {
151
+ const selectedUserOption = currentOptionList.find(option => option.order === targetId);
152
+ const selectedAnswerOption = optionList.find(option => option.order === targetId);
153
+
154
+ if (selectedUserOption) {
155
+ setCurrentOptionList(prevOptionList => prevOptionList.filter(option => option.order !== selectedUserOption.order));
156
+ }
157
+
158
+ if (!selectedAnswerOption) {
159
+ return;
160
+ }
161
+
162
+ setCurrentAnswerList(prevAnswerList => {
163
+ const cloneAnswerList = lodashEs.cloneDeep(prevAnswerList);
164
+ const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer.order !== targetId));
165
+ answerList[dropzoneIndex] = [...answerList[dropzoneIndex], selectedAnswerOption];
166
+ return answerList;
167
+ });
168
+ setHasSubmitted(false);
169
+ };
170
+ /**
171
+ *
172
+ */
173
+
174
+
175
+ const updateCurrentOption = targetId => {
176
+ var _a;
177
+
178
+ const pastTargetZoneIndex = currentAnswerList.findIndex(answer => answer === null || answer === void 0 ? void 0 : answer.find(item => item.order === targetId));
179
+ const selectedOption = (_a = currentAnswerList[pastTargetZoneIndex]) === null || _a === void 0 ? void 0 : _a.find(answer => answer.order === targetId);
180
+
181
+ if (!selectedOption) {
182
+ return;
183
+ }
184
+
185
+ setCurrentAnswerList(prevAnswerList => {
186
+ const filteredAnswerList = prevAnswerList[pastTargetZoneIndex].filter(answer => answer.order !== selectedOption.order);
187
+ prevAnswerList[pastTargetZoneIndex] = filteredAnswerList;
188
+ return [...prevAnswerList];
189
+ });
190
+ setCurrentOptionList(prevOptionList => [...prevOptionList, ...[selectedOption]]);
191
+ }; //
192
+ //
193
+ // quiz response fetcher
194
+
195
+
196
+ React__default["default"].useEffect(() => {
197
+ if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
198
+ const controller = new AbortController();
199
+ const {
200
+ signal
201
+ } = controller;
202
+ apiClient.getOrgMaterialQuizResponseGet({
203
+ quizResponseId: materialQuiz.lastQuizResponseId
204
+ }, {
205
+ signal
206
+ }).then(response => {
207
+ const answerInfo = response.quizResponse.answer;
208
+ initQuizGroupInfo(answerInfo);
209
+ setMaterialQuizResponse(response.quizResponse);
210
+ }).catch(error => {
211
+ console.error(error);
212
+ });
213
+ return () => controller.abort();
214
+ } else {
215
+ const answerInfo = [];
216
+ initQuizGroupInfo(answerInfo);
217
+ }
218
+ }, [initQuizGroupInfo, materialQuiz, userId]);
219
+ /**
220
+ *
221
+ */
222
+
223
+ const renderQuizInfo = () => {
224
+ if (!materialQuiz) {
225
+ return null;
226
+ }
227
+
228
+ return React__default["default"].createElement(blocks.Flex, {
229
+ marginbottom: "1.5rem",
230
+ column: true
231
+ }, React__default["default"].createElement(blocks.Flex, null, React__default["default"].createElement(blocks.Text, {
232
+ bold: true,
233
+ size: "large",
234
+ customStyles: {
235
+ color: designTokens.base.color.primary3,
236
+ marginRight: '0.5rem'
237
+ }
238
+ }, 'Q.'), React__default["default"].createElement(blocks.Text, {
239
+ bold: true,
240
+ role: "white",
241
+ size: "large",
242
+ wordBreak: "break-word"
243
+ }, materialQuiz.questionTitle)), materialQuiz.questionDescription ? React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.Vspace, {
244
+ height: 1
245
+ }), React__default["default"].createElement(markdown.MarkdownSSR, {
246
+ children: materialQuiz.questionDescription,
247
+ dark: true,
248
+ paddingx: 0,
249
+ paddingy: 0
250
+ })) : null);
251
+ }; //
252
+ //
253
+ //
254
+
255
+
256
+ return React__default["default"].createElement(context.Provider, {
257
+ value: {
258
+ groupList,
259
+ optionList,
260
+ currentOptionList,
261
+ currentAnswerList,
262
+ onUpdateAnswer: setCurrentAnswerList,
263
+ onUpdateOption: setCurrentOptionList,
264
+ onUpdateHasSubmitted: setHasSubmitted,
265
+ updateCurrentAnswer,
266
+ updateCurrentOption,
267
+ handleAnswerReset
268
+ }
269
+ }, React__default["default"].createElement(QuestionBox["default"], {
270
+ title: materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.title,
271
+ onNext: onNext,
272
+ isNextActive: hasSubmitted && typeof onNext === 'function',
273
+ submitStatus: React__default["default"].createElement(QuizSubmitStatusText, {
274
+ status: submitStatus
275
+ }),
276
+ submitResult: React__default["default"].createElement(QuizResultBadge, {
277
+ materialQuizResponse: materialQuizResponse
278
+ }),
279
+ footerActions: [{
280
+ border: true,
281
+ disabled: !flattenDeep__default["default"](currentAnswerList).length || !!userId,
282
+ loading: submitStatus === 'pending',
283
+ tabIndex: 0,
284
+ transparent: false,
285
+ role: 'primary',
286
+ onClick: handleSubmit,
287
+ children: intl.formatMessage({
288
+ id: 'materialQuiz.submit'
289
+ })
290
+ }]
291
+ }, renderQuizInfo(), vertical ? React__default["default"].createElement(MaterialQuizGroupMobile, null) : React__default["default"].createElement(MaterialQuizGroupDesktop, null)));
292
+ };
293
+
294
+ var MaterialQuizGroup$1 = MaterialQuizGroup;
295
+
296
+ module.exports = MaterialQuizGroup$1;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const MaterialQuizGroupDesktop: React.FC;
3
+ export default MaterialQuizGroupDesktop;