@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.
Files changed (160) hide show
  1. package/README.md +3 -0
  2. package/cjs/components/eb-sortable/EbDraggable.d.ts +18 -0
  3. package/cjs/components/eb-sortable/EbDraggable.js +112 -0
  4. package/cjs/components/eb-sortable/EbDroppable.d.ts +13 -0
  5. package/cjs/components/eb-sortable/EbDroppable.js +60 -0
  6. package/cjs/components/eb-sortable/EbSortable.d.ts +17 -0
  7. package/cjs/components/material-quiz/MaterialQuiz.d.ts +4 -0
  8. package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
  9. package/cjs/components/material-quiz/MaterialQuiz.i18n.js +55 -0
  10. package/cjs/components/material-quiz/MaterialQuiz.js +114 -0
  11. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
  12. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +55 -0
  13. package/cjs/components/material-quiz/MaterialQuizError.d.ts +3 -0
  14. package/cjs/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
  15. package/cjs/components/material-quiz/MaterialQuizInfo.js +74 -0
  16. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
  17. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +203 -0
  18. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
  19. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +468 -0
  20. package/cjs/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
  21. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +191 -0
  22. package/cjs/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
  23. package/cjs/components/material-quiz/MaterialQuizShimmer.js +61 -0
  24. package/cjs/components/material-quiz/MaterialQuizText.d.ts +3 -0
  25. package/cjs/components/material-quiz/MaterialQuizText.js +181 -0
  26. package/cjs/components/material-quiz/QuizResultBadge.d.ts +7 -0
  27. package/cjs/components/material-quiz/QuizResultBadge.js +48 -0
  28. package/cjs/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
  29. package/cjs/components/material-quiz/QuizSubmitStatusText.js +38 -0
  30. package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
  31. package/cjs/components/material-quiz/context/MaterialQuizContext.js +134 -0
  32. package/cjs/components/material-quiz/index.d.ts +3 -0
  33. package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
  34. package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +91 -0
  35. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
  36. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +463 -0
  37. package/cjs/components/material-quiz-edit/context.d.ts +6 -0
  38. package/cjs/components/material-quiz-edit/context.js +15 -0
  39. package/cjs/components/material-quiz-edit/index.d.ts +2 -0
  40. package/cjs/components/material-quiz-edit/locales.d.ts +34 -0
  41. package/cjs/components/material-quiz-edit/locales.js +73 -0
  42. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
  43. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +204 -0
  44. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
  45. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +205 -0
  46. package/cjs/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
  47. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +207 -0
  48. package/cjs/components/material-quiz-edit/options/OptionText.d.ts +3 -0
  49. package/cjs/components/material-quiz-edit/options/OptionText.js +99 -0
  50. package/cjs/components/material-quiz-edit/utils/editValue.d.ts +15 -0
  51. package/cjs/components/material-quiz-edit/utils/editValue.js +37 -0
  52. package/cjs/components/material-quiz-edit/utils/randomId.d.ts +4 -0
  53. package/cjs/components/material-quiz-edit/utils/randomId.js +12 -0
  54. package/cjs/components/shared/QuestionBox.d.ts +16 -0
  55. package/cjs/components/shared/QuestionBox.js +111 -0
  56. package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
  57. package/cjs/components/shared/QuizDraggbleDroppedOption.js +31 -0
  58. package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
  59. package/cjs/components/shared/QuizDraggbleDummyOption.js +36 -0
  60. package/cjs/components/shared/QuizDraggbleOption.d.ts +14 -0
  61. package/cjs/components/shared/QuizDraggbleOption.js +191 -0
  62. package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
  63. package/cjs/components/shared/StyledMarkdown.js +14 -0
  64. package/cjs/components/shared/index.d.ts +7 -0
  65. package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
  66. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
  67. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
  68. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
  69. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
  70. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +188 -0
  71. package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
  72. package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
  73. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
  74. package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
  75. package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
  76. package/cjs/components/shared/question-radio/QuestionRadioOption.js +156 -0
  77. package/cjs/helpers/index.d.ts +50 -0
  78. package/cjs/helpers/index.js +86 -0
  79. package/cjs/index.d.ts +3 -0
  80. package/cjs/index.js +27 -0
  81. package/es/components/eb-sortable/EbDraggable.d.ts +18 -0
  82. package/es/components/eb-sortable/EbDraggable.js +105 -0
  83. package/es/components/eb-sortable/EbDroppable.d.ts +13 -0
  84. package/es/components/eb-sortable/EbDroppable.js +53 -0
  85. package/es/components/eb-sortable/EbSortable.d.ts +17 -0
  86. package/es/components/material-quiz/MaterialQuiz.d.ts +4 -0
  87. package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
  88. package/es/components/material-quiz/MaterialQuiz.i18n.js +50 -0
  89. package/es/components/material-quiz/MaterialQuiz.js +106 -0
  90. package/es/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
  91. package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +48 -0
  92. package/es/components/material-quiz/MaterialQuizError.d.ts +3 -0
  93. package/es/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
  94. package/es/components/material-quiz/MaterialQuizInfo.js +68 -0
  95. package/es/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
  96. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +197 -0
  97. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
  98. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +461 -0
  99. package/es/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
  100. package/es/components/material-quiz/MaterialQuizSelectOne.js +185 -0
  101. package/es/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
  102. package/es/components/material-quiz/MaterialQuizShimmer.js +54 -0
  103. package/es/components/material-quiz/MaterialQuizText.d.ts +3 -0
  104. package/es/components/material-quiz/MaterialQuizText.js +174 -0
  105. package/es/components/material-quiz/QuizResultBadge.d.ts +7 -0
  106. package/es/components/material-quiz/QuizResultBadge.js +42 -0
  107. package/es/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
  108. package/es/components/material-quiz/QuizSubmitStatusText.js +32 -0
  109. package/es/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
  110. package/es/components/material-quiz/context/MaterialQuizContext.js +124 -0
  111. package/es/components/material-quiz/index.d.ts +3 -0
  112. package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
  113. package/es/components/material-quiz-edit/MaterialQuizEdit.js +86 -0
  114. package/es/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
  115. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +456 -0
  116. package/es/components/material-quiz-edit/context.d.ts +6 -0
  117. package/es/components/material-quiz-edit/context.js +6 -0
  118. package/es/components/material-quiz-edit/index.d.ts +2 -0
  119. package/es/components/material-quiz-edit/locales.d.ts +34 -0
  120. package/es/components/material-quiz-edit/locales.js +68 -0
  121. package/es/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
  122. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +197 -0
  123. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
  124. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +198 -0
  125. package/es/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
  126. package/es/components/material-quiz-edit/options/OptionSelectOne.js +200 -0
  127. package/es/components/material-quiz-edit/options/OptionText.d.ts +3 -0
  128. package/es/components/material-quiz-edit/options/OptionText.js +93 -0
  129. package/es/components/material-quiz-edit/utils/editValue.d.ts +15 -0
  130. package/es/components/material-quiz-edit/utils/editValue.js +32 -0
  131. package/es/components/material-quiz-edit/utils/randomId.d.ts +4 -0
  132. package/es/components/material-quiz-edit/utils/randomId.js +8 -0
  133. package/es/components/shared/QuestionBox.d.ts +16 -0
  134. package/es/components/shared/QuestionBox.js +101 -0
  135. package/es/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
  136. package/es/components/shared/QuizDraggbleDroppedOption.js +25 -0
  137. package/es/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
  138. package/es/components/shared/QuizDraggbleDummyOption.js +29 -0
  139. package/es/components/shared/QuizDraggbleOption.d.ts +14 -0
  140. package/es/components/shared/QuizDraggbleOption.js +184 -0
  141. package/es/components/shared/StyledMarkdown.d.ts +3 -0
  142. package/es/components/shared/StyledMarkdown.js +8 -0
  143. package/es/components/shared/index.d.ts +7 -0
  144. package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
  145. package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
  146. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
  147. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
  148. package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
  149. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +181 -0
  150. package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
  151. package/es/components/shared/question-radio/QuestionRadio.js +19 -0
  152. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
  153. package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
  154. package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
  155. package/es/components/shared/question-radio/QuestionRadioOption.js +149 -0
  156. package/es/helpers/index.d.ts +50 -0
  157. package/es/helpers/index.js +78 -0
  158. package/es/index.d.ts +3 -0
  159. package/es/index.js +10 -0
  160. package/package.json +75 -0
@@ -0,0 +1,203 @@
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
+ require('../shared/question-radio/QuestionRadio.js');
10
+ require('../shared/question-radio/QuestionRadioOption.js');
11
+ var QuestionCheckbox = require('../shared/question-checkbox/QuestionCheckbox.js');
12
+ var QuestionCheckboxOption = 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 MaterialQuizSelectMultiple = () => {
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); // when user submitted answers and not get the result yet, update selected options (for example, test quiz)
57
+ // when is is a survey type quiz
58
+
59
+ if (!index.shouldResetOptions({
60
+ materialQuizResponse: response.quizResponse
61
+ })) {
62
+ setSelectedAnswer(response.quizResponse.answer);
63
+ }
64
+
65
+ setSelectedAnswer(response.quizResponse.answer);
66
+ }).catch(error => {
67
+ console.error(error);
68
+ });
69
+ return () => controller.abort();
70
+ }
71
+ }, [materialQuiz, userId]); // quiz response fetcher
72
+
73
+ React__default["default"].useEffect(() => {
74
+ if (userId && materialQuiz) {
75
+ const controller = new AbortController();
76
+ const {
77
+ signal
78
+ } = controller;
79
+ apiClient.getOrgMaterialQuizResponseList({
80
+ materialQuizId: materialQuiz.id,
81
+ filterUserIds: [userId],
82
+ isContainOnlyLast: true,
83
+ isIncludeAnswer: true,
84
+ offset: 0,
85
+ count: 1
86
+ }, {
87
+ signal
88
+ }).then(response => {
89
+ const quizResponse = response.quizResponses[0];
90
+ setMaterialQuizResponse(quizResponse);
91
+
92
+ if (Array.isArray(quizResponse.answer)) {
93
+ setSelectedAnswer(quizResponse.answer);
94
+ }
95
+ }).catch(error => {
96
+ console.error(error);
97
+ });
98
+ return () => controller.abort();
99
+ }
100
+ }, [materialQuiz, userId]); // submit handler
101
+
102
+ const handleSubmit = async () => {
103
+ if (!materialQuiz) {
104
+ return;
105
+ }
106
+
107
+ setSubmitStatus('pending');
108
+
109
+ try {
110
+ const {
111
+ quizResponseId
112
+ } = await apiClient.postOrgMaterialQuizResponseAdd({
113
+ materialQuizId: materialQuiz.id,
114
+ answer: selectedAnswer
115
+ });
116
+ const {
117
+ quizResponse
118
+ } = await apiClient.getOrgMaterialQuizResponseGet({
119
+ quizResponseId
120
+ });
121
+ setIsActive(false);
122
+ setMaterialQuizResponse(quizResponse);
123
+ void refreshOrgMaterialQuiz();
124
+ onSubmit(true, index.getQuizResult(quizResponse));
125
+ setSubmitStatus('resolved');
126
+ setHasSubmitted(true);
127
+ } catch (error) {
128
+ console.error(error);
129
+ onSubmit(false);
130
+ setSubmitStatus('rejected');
131
+ }
132
+ };
133
+
134
+ return React__default["default"].createElement(QuestionBox["default"], {
135
+ title: intl.formatMessage({
136
+ id: 'materialQuiz.myAnswer'
137
+ }),
138
+ onNext: onNext,
139
+ isNextActive: hasSubmitted && typeof onNext === 'function',
140
+ submitResult: React__default["default"].createElement(QuizResultBadge, {
141
+ materialQuizResponse: materialQuizResponse
142
+ }),
143
+ submitStatus: React__default["default"].createElement(QuizSubmitStatusText, {
144
+ status: submitStatus
145
+ }),
146
+ footerActions: [{
147
+ border: true,
148
+ disabled: selectedAnswer.length === 0 || index.checkUserLectureTestEnded(lecture) || !!userId,
149
+ loading: submitStatus === 'pending',
150
+ tabIndex: 0,
151
+ transparent: false,
152
+ role: 'primary',
153
+ onClick: handleSubmit,
154
+ children: intl.formatMessage({
155
+ id: 'materialQuiz.submit'
156
+ })
157
+ }]
158
+ }, React__default["default"].createElement(QuestionCheckbox, {
159
+ onSelect: index$1 => {
160
+ if (index.checkUserLectureTestEnded(lecture) || !!userId) {
161
+ return;
162
+ }
163
+
164
+ setHasSubmitted(false);
165
+ setIsActive(true);
166
+ setSelectedAnswer(prevState => {
167
+ const newState = prevState.includes(index$1) ? prevState.filter(ident => ident !== index$1) : [...prevState, index$1];
168
+ return newState;
169
+ });
170
+ },
171
+ selectedOptions: selectedAnswer,
172
+ disabled: submitStatus === 'pending' || index.checkUserLectureTestEnded(lecture) || !!userId
173
+ }, (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.optionInfo) ? materialQuiz.optionInfo.map((option, index$1) => {
174
+ const getIsSelected = (index, materialQuizResponse) => {
175
+ var _a;
176
+
177
+ if (!materialQuizResponse || typeof materialQuizResponse.answer === 'string') {
178
+ return false;
179
+ }
180
+
181
+ return (_a = materialQuizResponse.answer.includes(index)) !== null && _a !== void 0 ? _a : false;
182
+ };
183
+
184
+ const status = index.getOptionStatus({
185
+ materialQuizResponse,
186
+ isSelected: getIsSelected(index$1, materialQuizResponse),
187
+ isActive
188
+ });
189
+ return React__default["default"].createElement(QuestionCheckboxOption, {
190
+ key: index$1,
191
+ value: index$1,
192
+ status: status,
193
+ isAnswer: !!userId && Array.isArray(materialQuiz.answerInfo) && materialQuiz.answerInfo.includes(index$1)
194
+ }, (course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions) ? React__default["default"].createElement(StyledMarkdown, {
195
+ children: option,
196
+ paddingx: 0,
197
+ paddingy: 0,
198
+ dark: false
199
+ }) : option);
200
+ }) : null));
201
+ };
202
+
203
+ module.exports = MaterialQuizSelectMultiple;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const MaterialQuizSelectMultipleOrder: React.FC;
3
+ export default MaterialQuizSelectMultipleOrder;
@@ -0,0 +1,468 @@
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 icons = require('@elice/icons');
9
+ var styled = require('styled-components');
10
+ var index = require('../../helpers/index.js');
11
+ var EbDroppable = require('../eb-sortable/EbDroppable.js');
12
+ var QuestionBox = require('../shared/QuestionBox.js');
13
+ var QuizDraggbleDroppedOption = require('../shared/QuizDraggbleDroppedOption.js');
14
+ var QuizDraggbleDummyOption = require('../shared/QuizDraggbleDummyOption.js');
15
+ var QuizDraggbleOption = require('../shared/QuizDraggbleOption.js');
16
+ var MaterialQuizContext = require('./context/MaterialQuizContext.js');
17
+ var QuizResultBadge = require('./QuizResultBadge.js');
18
+ var QuizSubmitStatusText = require('./QuizSubmitStatusText.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 styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
24
+
25
+ const StyledVerticalDivider = styled__default["default"].div.withConfig({
26
+ componentId: "sc-10067nt-0"
27
+ })(["display:flex;flex-direction:column;align-items:center;justify-content:center;flex:none !important;padding:1rem;", ""], ({
28
+ vertical
29
+ }) => {
30
+ return vertical ? `
31
+ display: none;
32
+ ` : '';
33
+ });
34
+ const StyledHorizontalDivider = styled__default["default"].hr.withConfig({
35
+ componentId: "sc-10067nt-1"
36
+ })(["display:none;", ""], ({
37
+ vertical
38
+ }) => {
39
+ return vertical ? `
40
+ display: block;
41
+ margin: 1rem 0;
42
+ width: 100%;
43
+ border: solid 1px ${designTokens.base.color.navy5};
44
+ ` : '';
45
+ });
46
+ const StyledQuizOptionsDropZone = styled__default["default"](EbDroppable).withConfig({
47
+ componentId: "sc-10067nt-2"
48
+ })(["display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";& > div{margin-bottom:1rem;}&.ui-droppable-hover{outline:1px dashed ", ";}"], designTokens.base.color.navy6, designTokens.base.color.gray4);
49
+ const StyledQuizAnswersDropZone = styled__default["default"].div.withConfig({
50
+ componentId: "sc-10067nt-3"
51
+ })(["position:relative;display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";& > div{margin-bottom:1rem;}"], designTokens.base.color.navy6);
52
+ const StyledOptionBox = styled__default["default"].div.withConfig({
53
+ componentId: "sc-10067nt-4"
54
+ })(["display:flex;", ""], ({
55
+ vertical
56
+ }) => {
57
+ return vertical ? `
58
+ flex-direction: column;
59
+ ` : '';
60
+ });
61
+
62
+ const MaterialQuizSelectMultipleOrder = () => {
63
+ // context
64
+ const {
65
+ lecture,
66
+ materialQuiz,
67
+ userId,
68
+ vertical,
69
+ course
70
+ } = MaterialQuizContext.useMaterialQuizState();
71
+ const {
72
+ onSubmit,
73
+ onNext,
74
+ refreshOrgMaterialQuiz
75
+ } = MaterialQuizContext.useMaterialQuizDispatch(); // state
76
+
77
+ const intl = reactIntl.useIntl();
78
+ const [materialQuizResponse, setMaterialQuizResponse] = React__default["default"].useState();
79
+ const [submitStatus, setSubmitStatus] = React__default["default"].useState('idle');
80
+ const [isActive, setIsActive] = React__default["default"].useState(false);
81
+ const [optionList, setOptionList] = React__default["default"].useState([]);
82
+ const [answerList, setAnswerList] = React__default["default"].useState([]);
83
+ const [correctAnswerList, setCorrectAnswerList] = React__default["default"].useState([]);
84
+ const [hasSubmitted, setHasSubmitted] = React__default["default"].useState(false); // ref
85
+
86
+ const optionBoxRef = React__default["default"].useRef(null); // to make jquery touchable
87
+
88
+ React__default["default"].useEffect(() => {
89
+ const optionBoxElement = optionBoxRef.current;
90
+
91
+ if (!optionBoxElement) {
92
+ return;
93
+ }
94
+ /**
95
+ * Lightweight script to convert touch handlers to mouse handlers
96
+ * credit: http://stackoverflow.com/a/6141093
97
+ */
98
+
99
+
100
+ function touchHandler(event) {
101
+ const touches = event.changedTouches;
102
+ const first = touches[0];
103
+ let type = '';
104
+
105
+ switch (event.type) {
106
+ case 'touchstart':
107
+ type = 'mousedown';
108
+ break;
109
+
110
+ case 'touchmove':
111
+ type = 'mousemove';
112
+ break;
113
+
114
+ case 'touchend':
115
+ type = 'mouseup';
116
+ break;
117
+
118
+ default:
119
+ return;
120
+ } // initMouseEvent(type, canBubble, cancelable, view, clickCount,
121
+ // screenX, screenY, clientX, clientY, ctrlKey,
122
+ // altKey, shiftKey, metaKey, button, relatedTarget);
123
+
124
+
125
+ const simulatedEvent = document.createEvent('MouseEvent');
126
+ simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0
127
+ /*left*/
128
+ , null);
129
+ first.target.dispatchEvent(simulatedEvent);
130
+ event.preventDefault();
131
+ }
132
+
133
+ optionBoxElement.addEventListener('touchstart', touchHandler, true);
134
+ optionBoxElement.addEventListener('touchmove', touchHandler, true);
135
+ optionBoxElement.addEventListener('touchend', touchHandler, true);
136
+ optionBoxElement.addEventListener('touchcancel', touchHandler, true);
137
+ return () => {
138
+ optionBoxElement.removeEventListener('touchstart', touchHandler, true);
139
+ optionBoxElement.removeEventListener('touchmove', touchHandler, true);
140
+ optionBoxElement.removeEventListener('touchend', touchHandler, true);
141
+ optionBoxElement.removeEventListener('touchcancel', touchHandler, true);
142
+ };
143
+ }, []); // quiz response fetcher
144
+
145
+ React__default["default"].useEffect(() => {
146
+ var _a, _b;
147
+
148
+ if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
149
+ const controller = new AbortController();
150
+ const {
151
+ signal
152
+ } = controller;
153
+ apiClient.getOrgMaterialQuizResponseGet({
154
+ quizResponseId: materialQuiz.lastQuizResponseId
155
+ }, {
156
+ signal
157
+ }).then(response => {
158
+ setMaterialQuizResponse(response.quizResponse);
159
+ const answer = response.quizResponse.answer; // user submitted
160
+
161
+ const optionInfo = materialQuiz.optionInfo; // options
162
+
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
+ }));
171
+ setAnswerList(answerList);
172
+ setOptionList(optionList);
173
+ }).catch(error => {
174
+ console.error(error);
175
+ });
176
+ return () => controller.abort();
177
+ } 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
+ }))) || []);
182
+ setAnswerList(Array.from({
183
+ length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
184
+ }, () => ({
185
+ order: null,
186
+ value: null
187
+ })));
188
+ }
189
+ }, [materialQuiz, userId]); // quiz response fetcher
190
+
191
+ React__default["default"].useEffect(() => {
192
+ if (userId && materialQuiz) {
193
+ const controller = new AbortController();
194
+ const {
195
+ signal
196
+ } = controller;
197
+ apiClient.getOrgMaterialQuizResponseList({
198
+ materialQuizId: materialQuiz.id,
199
+ filterUserIds: [userId],
200
+ isContainOnlyLast: true,
201
+ isIncludeAnswer: true,
202
+ offset: 0,
203
+ count: 1
204
+ }, {
205
+ signal
206
+ }).then(response => {
207
+ var _a, _b, _c;
208
+
209
+ const quizResponse = response.quizResponses[0];
210
+ setMaterialQuizResponse(quizResponse);
211
+ const answer = (_a = quizResponse === null || quizResponse === void 0 ? void 0 : quizResponse.answer) !== null && _a !== void 0 ? _a : []; // user submitted
212
+
213
+ const optionInfo = materialQuiz.optionInfo; // options
214
+
215
+ const correctAnswerList = Array.isArray(materialQuiz.answerInfo) ? (_c = (_b = materialQuiz.answerInfo) === null || _b === void 0 ? void 0 : _b.map(answerInfo => {
216
+ var _a, _b;
217
+
218
+ return {
219
+ order: answerInfo,
220
+ value: (_b = (_a = materialQuiz.optionInfo) === null || _a === void 0 ? void 0 : _a[answerInfo]) !== null && _b !== void 0 ? _b : ''
221
+ };
222
+ })) !== 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
+ }));
231
+ setCorrectAnswerList(correctAnswerList);
232
+ setAnswerList(answerList);
233
+ setOptionList(optionList);
234
+ }).catch(error => {
235
+ console.error(error);
236
+ });
237
+ return () => controller.abort();
238
+ }
239
+ }, [materialQuiz, userId]); // submit handler
240
+
241
+ const handleSubmit = async () => {
242
+ if (!materialQuiz) {
243
+ return;
244
+ }
245
+
246
+ setSubmitStatus('pending');
247
+
248
+ try {
249
+ const {
250
+ quizResponseId
251
+ } = await apiClient.postOrgMaterialQuizResponseAdd({
252
+ materialQuizId: materialQuiz.id,
253
+ answer: answerList.map(answer => answer.order)
254
+ });
255
+ const {
256
+ quizResponse
257
+ } = await apiClient.getOrgMaterialQuizResponseGet({
258
+ quizResponseId
259
+ });
260
+ setIsActive(false);
261
+ setHasSubmitted(true);
262
+ setMaterialQuizResponse(quizResponse);
263
+ void refreshOrgMaterialQuiz();
264
+ onSubmit(true, index.getQuizResult(quizResponse));
265
+ setSubmitStatus('resolved');
266
+ } catch (error) {
267
+ console.error(error);
268
+ onSubmit(false);
269
+ setSubmitStatus('rejected');
270
+ }
271
+ };
272
+
273
+ const renderQuizDragOption = () => {
274
+ return React__default["default"].createElement(StyledQuizOptionsDropZone, {
275
+ disabled: !!userId,
276
+ accept: ".quiz-answer",
277
+ onDrop: (event, ui) => {
278
+ if (index.checkUserLectureTestEnded(lecture)) {
279
+ return;
280
+ }
281
+
282
+ setIsActive(true);
283
+ setHasSubmitted(false);
284
+ const targetId = Number(ui.draggable[0].id);
285
+ setOptionList(prevOptionList => {
286
+ return [...prevOptionList, answerList.find(answer => answer.order === targetId)].sort((a, b) => a.order - b.order);
287
+ });
288
+ setAnswerList(prevAnswerList => {
289
+ const removingIndex = prevAnswerList.findIndex(answer => answer.order === targetId);
290
+ return prevAnswerList.map((answer, answerIndex) => {
291
+ if (answerIndex === removingIndex) {
292
+ return {
293
+ order: null,
294
+ value: null
295
+ };
296
+ } else {
297
+ return answer;
298
+ }
299
+ });
300
+ });
301
+ }
302
+ }, optionList.map((option, index) => {
303
+ return React__default["default"].createElement(QuizDraggbleOption, {
304
+ disabled: !!userId,
305
+ key: option.order,
306
+ id: option.order.toString(),
307
+ className: "quiz-option",
308
+ content: option.value,
309
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
310
+ });
311
+ }), optionList.length === 0 && !userId ? React__default["default"].createElement(blocks.Flex, {
312
+ align: "center",
313
+ justify: "center",
314
+ style: {
315
+ minWidth: '200px',
316
+ height: '100%'
317
+ }
318
+ }, React__default["default"].createElement(blocks.Text, {
319
+ size: "tiny",
320
+ role: "white"
321
+ }, intl.formatMessage({
322
+ id: 'materialQuiz.order.answerEmpty'
323
+ }))) : null);
324
+ };
325
+
326
+ const renderQuizDragAnswers = () => {
327
+ return React__default["default"].createElement(StyledQuizAnswersDropZone, null, answerList.map((option, index$1) => {
328
+ const getRole = () => {
329
+ if (isActive) {
330
+ return 'default';
331
+ }
332
+
333
+ const status = index.getQuizResultStatus(materialQuizResponse);
334
+
335
+ switch (status) {
336
+ case index.QuizResultStatus.Correct:
337
+ return 'correct';
338
+
339
+ case index.QuizResultStatus.Wrong:
340
+ return 'wrong';
341
+
342
+ default:
343
+ return 'default';
344
+ }
345
+ };
346
+
347
+ if (option.value === null) {
348
+ return React__default["default"].createElement(QuizDraggbleDummyOption, {
349
+ key: index$1,
350
+ indexOrder: index$1 + 1,
351
+ onDrop: (event, ui) => {
352
+ if (index.checkUserLectureTestEnded(lecture)) {
353
+ return;
354
+ }
355
+
356
+ setIsActive(true);
357
+ setHasSubmitted(false); // from answerList to answerList
358
+
359
+ if (ui.draggable[0].classList.contains('quiz-answer')) {
360
+ const targetOptionId = Number(ui.draggable[0].id);
361
+ setAnswerList(prevAnswerList => {
362
+ const newState = [...prevAnswerList];
363
+ const from = newState.find(prevAnswer => prevAnswer.order === targetOptionId);
364
+ const fromIndex = newState.findIndex(prevAnswer => prevAnswer.order === targetOptionId);
365
+ const to = newState[index$1];
366
+ newState[index$1] = from;
367
+ newState[fromIndex] = to;
368
+ return newState;
369
+ });
370
+ } // from option-list to answerList-list
371
+ else {
372
+ const targetOptionId = Number(ui.draggable[0].id);
373
+ setOptionList(prevOptions => {
374
+ return prevOptions.filter(prevOption => prevOption.order !== targetOptionId);
375
+ });
376
+ setAnswerList(prevAnswerList => {
377
+ return prevAnswerList.map((prevAnswer, prevAnswerIndex) => {
378
+ var _a, _b;
379
+
380
+ if (index$1 === prevAnswerIndex) {
381
+ return {
382
+ order: targetOptionId,
383
+ value: (_b = (_a = optionList.find(option => option.order === targetOptionId)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''
384
+ };
385
+ } else {
386
+ return prevAnswer;
387
+ }
388
+ });
389
+ });
390
+ }
391
+ }
392
+ });
393
+ } else {
394
+ return React__default["default"].createElement(QuizDraggbleDroppedOption, {
395
+ key: index$1,
396
+ id: option.order.toString(),
397
+ content: option.value,
398
+ role: getRole(),
399
+ disabled: !!userId,
400
+ indexOrder: index$1 + 1,
401
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
402
+ });
403
+ }
404
+ }));
405
+ };
406
+
407
+ return React__default["default"].createElement(QuestionBox["default"], {
408
+ title: intl.formatMessage({
409
+ id: 'materialQuiz.myAnswer'
410
+ }),
411
+ onNext: onNext,
412
+ isNextActive: hasSubmitted && typeof onNext === 'function',
413
+ submitStatus: React__default["default"].createElement(QuizSubmitStatusText, {
414
+ status: submitStatus
415
+ }),
416
+ submitResult: React__default["default"].createElement(QuizResultBadge, {
417
+ materialQuizResponse: materialQuizResponse
418
+ }),
419
+ footerActions: [{
420
+ border: true,
421
+ disabled: (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== answerList.filter(answer => answer.order !== null).length || !!userId,
422
+ loading: submitStatus === 'pending',
423
+ tabIndex: 0,
424
+ transparent: false,
425
+ role: 'primary',
426
+ onClick: handleSubmit,
427
+ children: intl.formatMessage({
428
+ id: 'materialQuiz.submit'
429
+ })
430
+ }]
431
+ }, React__default["default"].createElement(StyledOptionBox, {
432
+ ref: optionBoxRef,
433
+ vertical: vertical
434
+ }, renderQuizDragOption(), React__default["default"].createElement(StyledVerticalDivider, {
435
+ vertical: vertical
436
+ }, React__default["default"].createElement(blocks.Icon, {
437
+ size: "elephant",
438
+ icon: icons.eilSortItem,
439
+ rotate: 90,
440
+ style: {
441
+ color: designTokens.base.color.navy3
442
+ }
443
+ })), React__default["default"].createElement(StyledHorizontalDivider, {
444
+ vertical: vertical
445
+ }), renderQuizDragAnswers()), !!userId ? React__default["default"].createElement(blocks.Flex, {
446
+ margintop: "1rem",
447
+ column: true
448
+ }, React__default["default"].createElement(StyledQuizOptionsDropZone, null, React__default["default"].createElement(blocks.Text, {
449
+ role: "white",
450
+ size: "small"
451
+ }, intl.formatMessage({
452
+ id: 'materialQuiz.answer'
453
+ })), correctAnswerList.map((correctAnswer, index) => {
454
+ var _a;
455
+
456
+ return React__default["default"].createElement(QuizDraggbleDroppedOption, {
457
+ key: correctAnswer.order,
458
+ id: (_a = correctAnswer.order) === null || _a === void 0 ? void 0 : _a.toString(),
459
+ content: correctAnswer.value,
460
+ disabled: true,
461
+ role: "correct",
462
+ indexOrder: index + 1,
463
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
464
+ });
465
+ }))) : null);
466
+ };
467
+
468
+ module.exports = MaterialQuizSelectMultipleOrder;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const MaterialQuizSelectOne: React.FC;
3
+ export default MaterialQuizSelectOne;