catchup-library-web 2.0.7 → 2.0.8

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 (27) hide show
  1. package/dist/index.d.mts +22 -22
  2. package/dist/index.d.ts +22 -22
  3. package/dist/index.js +285 -471
  4. package/dist/index.mjs +285 -471
  5. package/package.json +1 -1
  6. package/src/components/activities/ActivityPreviewByAnswerData.tsx +118 -121
  7. package/src/components/activities/ActivityPreviewByData.tsx +10 -10
  8. package/src/components/activities/DropdownActivityContent.tsx +9 -35
  9. package/src/components/activities/FillInTheBlanksActivityContent.tsx +9 -34
  10. package/src/components/activities/GroupingActivityContent.tsx +4 -8
  11. package/src/components/activities/MCMAActivityContent.tsx +8 -8
  12. package/src/components/activities/MCSAActivityContent.tsx +8 -8
  13. package/src/components/activities/MatchingActivityContent.tsx +4 -8
  14. package/src/components/activities/OpenEndedActivityContent.tsx +4 -8
  15. package/src/components/activities/OrderingActivityContent.tsx +4 -8
  16. package/src/components/activities/TrueFalseActivityContent.tsx +4 -12
  17. package/src/components/activities/material-contents/DropdownActivityMaterialContent.tsx +9 -19
  18. package/src/components/activities/material-contents/FillInTheBlanksActivityMaterialContent.tsx +9 -24
  19. package/src/components/activities/material-contents/GroupingActivityMaterialContent.tsx +7 -18
  20. package/src/components/activities/material-contents/MCMAActivityMaterialContent.tsx +2 -10
  21. package/src/components/activities/material-contents/MCSAActivityMaterialContent.tsx +2 -10
  22. package/src/components/activities/material-contents/MatchingActivityMaterialContent.tsx +7 -17
  23. package/src/components/activities/material-contents/OpenEndedActivityMaterialContent.tsx +2 -21
  24. package/src/components/activities/material-contents/OrderingActivityMaterialContent.tsx +4 -16
  25. package/src/components/activities/material-contents/TrueFalseActivityMaterialContent.tsx +4 -27
  26. package/src/properties/ActivityProperties.ts +21 -20
  27. package/src/utilization/CatchtivityUtilization.ts +49 -84
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,192 +20,193 @@ import {
20
20
  import { IActivityPreviewByAnswerDataProps } from "../../properties/ActivityProperties";
21
21
  import ActivityEmptyContent from "./empty-contents/ActivityEmptyContent";
22
22
 
23
+ const ACTIVITY_TEMPLATE_LIST = [
24
+ { type: "ORDERING", materialMap: "orderingMaterialMap" },
25
+ { type: "DROPDOWN", materialMap: "dropdownMaterialMap" },
26
+ { type: "MCSA", materialMap: "MCSAMaterialMap" },
27
+ { type: "MCMA", materialMap: "MCMAMaterialMap" },
28
+ { type: "MATCHING", materialMap: "matchingMaterialMap" },
29
+ { type: "GROUPING", materialMap: "groupingMaterialMap" },
30
+ {
31
+ type: "FILL_IN_THE_BLANKS",
32
+ materialMap: "fillInTheBlanksMaterialMap",
33
+ },
34
+ { type: "OPEN_ENDED", materialMap: "openEndedMaterialMap" },
35
+ { type: "TRUE_FALSE", materialMap: "trueFalseMaterialMap" },
36
+ ];
37
+
23
38
  const ActivityPreviewByAnswerData = ({
24
39
  data,
40
+ answerType = null,
25
41
  showType = true,
26
42
  showDescription = true,
27
- lockedType = null,
28
- typeOptionList = [],
43
+ lockedTypeList = [],
29
44
  showSolution = false,
30
45
  showEvaluationRubric = false,
31
46
  showDifficulty = true,
32
47
  isFullScreen = false,
33
48
  showCorrectAnswer = false,
34
49
  }: IActivityPreviewByAnswerDataProps) => {
35
- const [key, setKey] = useState(new Date().getTime());
36
50
  const [selectedType, setSelectedType] = useState<string | null>(null);
37
51
  const [optionList, setOptionList] = useState<any[]>([]);
38
- interface AnswerItem {
39
- type: string;
40
- isEmpty?: boolean;
41
- answerMap?: any;
42
- [key: string]: any;
43
- }
44
-
45
- interface Answer {
46
- data: AnswerItem[];
47
- }
48
-
49
- const [answer, setAnswer] = useState<Answer>({ data: [] });
52
+ const [answerMapMap, setAnswerMapMap] = useState<any>({});
53
+ const [activityTemplateTypeList, setActivityTemplateTypeList] = useState<
54
+ any[]
55
+ >([]);
50
56
 
51
57
  useEffect(() => {
52
58
  if (!data) return;
53
- setKey(new Date().getTime());
54
- }, [data]);
55
-
56
- const checkAnswerMapExists = (type: string): AnswerItem | null => {
57
- if (data && data.answerMap && Array.isArray(data.answerMap)) {
58
- const foundAnswer = data.answerMap.find(
59
- (answer: any) => answer.type === type
59
+ let currentActivityTemplateMapList: any[] = JSON.parse(
60
+ JSON.stringify(ACTIVITY_TEMPLATE_LIST)
61
+ );
62
+ if (lockedTypeList.length > 0) {
63
+ currentActivityTemplateMapList = currentActivityTemplateMapList.filter(
64
+ (activityTemplateMap) =>
65
+ lockedTypeList.includes(activityTemplateMap.type)
60
66
  );
61
- return foundAnswer || null;
62
67
  }
63
- return null;
64
- };
68
+ const currentActivityTemplateTypeList = [];
69
+ for (const activityTemplateMap of currentActivityTemplateMapList) {
70
+ if (data[activityTemplateMap.materialMap]) {
71
+ currentActivityTemplateTypeList.push(activityTemplateMap);
72
+ }
73
+ }
74
+ setActivityTemplateTypeList(currentActivityTemplateMapList);
75
+ }, [data, answerType, lockedTypeList]);
65
76
 
66
77
  useEffect(() => {
67
- if (!data) return;
68
-
69
- const constructAnswerBasedOnData = () => {
70
- const newAnswer: Answer = { data: [] };
71
-
72
- const activityTypes = [
73
- { type: "ORDERING", materialMap: "orderingMaterialMap" },
74
- { type: "DROPDOWN", materialMap: "dropdownMaterialMap" },
75
- { type: "MCSA", materialMap: "MCSAMaterialMap" },
76
- { type: "MCMA", materialMap: "MCMAMaterialMap" },
77
- { type: "MATCHING", materialMap: "matchingMaterialMap" },
78
- { type: "GROUPING", materialMap: "groupingMaterialMap" },
79
- {
80
- type: "FILL_IN_THE_BLANKS",
81
- materialMap: "fillInTheBlanksMaterialMap",
82
- },
83
- { type: "OPEN_ENDED", materialMap: "openEndedMaterialMap" },
84
- { type: "TRUE_FALSE", materialMap: "trueFalseMaterialMap" },
85
- ];
86
-
87
- activityTypes.forEach(({ type, materialMap }) => {
88
- if (data[materialMap]) {
89
- const foundAnswer = checkAnswerMapExists(type);
90
- const answerItem: AnswerItem =
91
- foundAnswer ||
92
- constructActivityAnswerMap(
93
- { type },
94
- JSON.parse(JSON.stringify(data))
95
- );
96
- newAnswer.data.push(answerItem);
97
- }
98
- });
99
-
100
- setAnswer(newAnswer);
101
-
102
- // Set initial selected type
103
- if (newAnswer.data.length > 0) {
104
- if (
105
- lockedType &&
106
- newAnswer.data.find((item: AnswerItem) => item.type === lockedType)
107
- ) {
108
- setSelectedType(lockedType);
109
- } else {
110
- setSelectedType(newAnswer.data[0].type);
111
- }
78
+ if (activityTemplateTypeList.length === 0) return;
79
+ const currentOptionList = [];
80
+ for (const activityTemplateType of activityTemplateTypeList) {
81
+ const currentTypeOption: any = {
82
+ id: activityTemplateType.type,
83
+ value: i18n.t(activityTemplateType.type),
84
+ };
85
+ if (showDifficulty) {
86
+ currentTypeOption.subText = i18n.t(
87
+ retrieveDifficultyByActivityTypeFromData(
88
+ activityTemplateType.type,
89
+ data
90
+ )
91
+ );
112
92
  }
113
- };
114
-
115
- constructAnswerBasedOnData();
116
- }, [data, lockedType]);
93
+ currentOptionList.push(currentTypeOption);
94
+ }
95
+ setOptionList(currentOptionList);
96
+ }, [activityTemplateTypeList, showDifficulty]);
117
97
 
118
98
  useEffect(() => {
119
- if (!data || !answer.data.length) return;
99
+ if (optionList.length === 0) return;
100
+ setSelectedType(optionList[0].id);
101
+ }, [optionList]);
120
102
 
121
- let currentTypeOptionList =
122
- typeOptionList ||
123
- answer.data.map((item) => ({
124
- id: item.type,
125
- text: i18n.t(item.type),
126
- }));
127
-
128
- if (lockedType) {
129
- currentTypeOptionList = currentTypeOptionList.filter(
130
- (typeOption: any) => typeOption.id === lockedType
131
- );
132
- }
133
-
134
- if (showDifficulty) {
135
- setOptionList(
136
- currentTypeOptionList.map((typeOption: any) => ({
137
- ...typeOption,
138
- subText: i18n.t(
139
- retrieveDifficultyByActivityTypeFromData(typeOption.id, data)
140
- ),
141
- }))
142
- );
143
- } else {
144
- setOptionList(currentTypeOptionList);
103
+ useEffect(() => {
104
+ if (activityTemplateTypeList.length === 0) return;
105
+ const currentAnswerMapMap: any = {};
106
+ for (const activityTemplateMap of activityTemplateTypeList) {
107
+ if (answerType === activityTemplateMap.type) {
108
+ currentAnswerMapMap[activityTemplateMap.type] = data.answerMap;
109
+ } else {
110
+ currentAnswerMapMap[activityTemplateMap.type] =
111
+ constructActivityAnswerMap(
112
+ { type: activityTemplateMap.type },
113
+ JSON.parse(JSON.stringify(data))
114
+ );
115
+ }
145
116
  }
146
- }, [data, answer.data, lockedType, typeOptionList, showDifficulty]);
117
+ setAnswerMapMap(currentAnswerMapMap);
118
+ }, [activityTemplateTypeList]);
147
119
 
148
120
  const RenderSelectedActivityContent = () => {
121
+ if (!selectedType) return null;
122
+
149
123
  const commonProps = {
150
- answer,
124
+ answerMap: answerMapMap[selectedType],
151
125
  data,
152
126
  canAnswerQuestion: () => true,
153
- // changeAnswer: (newAnswer: Answer) =>
154
- // setAnswer(JSON.parse(JSON.stringify(newAnswer))),
155
127
  changeAnswer: () => {},
156
128
  isPreview: true,
157
129
  showCorrectAnswer,
158
130
  isFullScreen,
159
131
  };
160
132
 
133
+ const isEmpty = answerMapMap[selectedType].isEmpty;
134
+
161
135
  switch (selectedType) {
162
136
  case "ORDERING":
163
137
  return data.orderingBodyMap && data.orderingMaterialMap ? (
164
- <OrderingActivityContent {...commonProps} />
138
+ <>
139
+ {isEmpty && <ActivityEmptyContent />}
140
+ <OrderingActivityContent {...commonProps} />
141
+ </>
165
142
  ) : null;
166
143
 
167
144
  case "DROPDOWN":
168
145
  return data.dropdownBodyMap && data.dropdownMaterialMap ? (
169
- <DropdownActivityContent {...commonProps} />
146
+ <>
147
+ {isEmpty && <ActivityEmptyContent />}
148
+ <DropdownActivityContent {...commonProps} />
149
+ </>
170
150
  ) : null;
171
151
 
172
152
  case "MCSA":
173
153
  return data.MCSABodyMap && data.MCSAMaterialMap ? (
174
- <MCSAActivityContent {...commonProps} />
154
+ <>
155
+ {isEmpty && <ActivityEmptyContent />}
156
+ <MCSAActivityContent {...commonProps} />
157
+ </>
175
158
  ) : null;
176
159
 
177
160
  case "MCMA":
178
161
  return data.MCMABodyMap && data.MCMAMaterialMap ? (
179
- <MCMAActivityContent {...commonProps} />
162
+ <>
163
+ {isEmpty && <ActivityEmptyContent />}
164
+ <MCMAActivityContent {...commonProps} />
165
+ </>
180
166
  ) : null;
181
167
 
182
168
  case "MATCHING":
183
169
  return data.matchingBodyMap && data.matchingMaterialMap ? (
184
- <MatchingActivityContent {...commonProps} />
170
+ <>
171
+ {isEmpty && <ActivityEmptyContent />}
172
+ <MatchingActivityContent {...commonProps} />
173
+ </>
185
174
  ) : null;
186
175
 
187
176
  case "GROUPING":
188
177
  return data.groupingBodyMap && data.groupingMaterialMap ? (
189
- <GroupingActivityContent {...commonProps} />
178
+ <>
179
+ {isEmpty && <ActivityEmptyContent />}
180
+ <GroupingActivityContent {...commonProps} />
181
+ </>
190
182
  ) : null;
191
183
 
192
184
  case "FILL_IN_THE_BLANKS":
193
185
  return data.fillInTheBlanksBodyMap &&
194
186
  data.fillInTheBlanksMaterialMap ? (
195
- <FillInTheBlanksActivityContent {...commonProps} />
187
+ <>
188
+ {isEmpty && <ActivityEmptyContent />}
189
+ <FillInTheBlanksActivityContent {...commonProps} />
190
+ </>
196
191
  ) : null;
197
192
 
198
193
  case "OPEN_ENDED":
199
194
  return data.openEndedBodyMap ? (
200
- <OpenEndedActivityContent
201
- {...commonProps}
202
- showMaterialContent={true}
203
- />
195
+ <>
196
+ {isEmpty && <ActivityEmptyContent />}
197
+ <OpenEndedActivityContent
198
+ {...commonProps}
199
+ showMaterialContent={true}
200
+ />
201
+ </>
204
202
  ) : null;
205
203
 
206
204
  case "TRUE_FALSE":
207
205
  return data.trueFalseBodyMap && data.trueFalseMaterialMap ? (
208
- <TrueFalseActivityContent {...commonProps} />
206
+ <>
207
+ {isEmpty && <ActivityEmptyContent />}
208
+ <TrueFalseActivityContent {...commonProps} />
209
+ </>
209
210
  ) : null;
210
211
 
211
212
  default:
@@ -216,7 +217,7 @@ const ActivityPreviewByAnswerData = ({
216
217
  if (!data) return null;
217
218
 
218
219
  return (
219
- <div key={key}>
220
+ <div>
220
221
  {showType && optionList.length > 0 ? (
221
222
  <>
222
223
  <div className="mb-4">
@@ -241,11 +242,7 @@ const ActivityPreviewByAnswerData = ({
241
242
  ) : null}
242
243
 
243
244
  <div className="flex flex-col my-2 w-full p-5">
244
- {answer?.data[0]?.isEmpty ? <ActivityEmptyContent /> : null}
245
-
246
- {selectedType ? (
247
- <div key={selectedType}>{RenderSelectedActivityContent()}</div>
248
- ) : null}
245
+ {RenderSelectedActivityContent()}
249
246
  </div>
250
247
 
251
248
  {selectedType && showSolution ? (
@@ -80,7 +80,7 @@ const ActivityPreviewByData = ({
80
80
  }, [data, lockedType, typeOptionList, showDifficulty]);
81
81
 
82
82
  if (!data) return;
83
- const answer = constructAnswerBasedOnData(data);
83
+ const answerMap = constructAnswerBasedOnData(data);
84
84
 
85
85
  return (
86
86
  <div key={key}>
@@ -112,7 +112,7 @@ const ActivityPreviewByData = ({
112
112
  data["orderingBodyMap"] != null &&
113
113
  data["orderingMaterialMap"] != null ? (
114
114
  <OrderingActivityContent
115
- answer={answer}
115
+ answerMap={answerMap}
116
116
  changeAnswer={() => {}}
117
117
  canAnswerQuestion={() => {
118
118
  return true;
@@ -126,7 +126,7 @@ const ActivityPreviewByData = ({
126
126
  data["dropdownBodyMap"] != null &&
127
127
  data["dropdownMaterialMap"] != null ? (
128
128
  <DropdownActivityContent
129
- answer={answer}
129
+ answerMap={answerMap}
130
130
  changeAnswer={() => {}}
131
131
  canAnswerQuestion={() => {
132
132
  return true;
@@ -140,7 +140,7 @@ const ActivityPreviewByData = ({
140
140
  data["MCSABodyMap"] != null &&
141
141
  data["MCSAMaterialMap"] != null ? (
142
142
  <MCSAActivityContent
143
- answer={answer}
143
+ answerMap={answerMap}
144
144
  changeAnswer={() => {}}
145
145
  canAnswerQuestion={() => {
146
146
  return true;
@@ -154,7 +154,7 @@ const ActivityPreviewByData = ({
154
154
  data["MCMABodyMap"] != null &&
155
155
  data["MCMAMaterialMap"] != null ? (
156
156
  <MCMAActivityContent
157
- answer={answer}
157
+ answerMap={answerMap}
158
158
  changeAnswer={() => {}}
159
159
  canAnswerQuestion={() => {
160
160
  return true;
@@ -168,7 +168,7 @@ const ActivityPreviewByData = ({
168
168
  data["matchingBodyMap"] != null &&
169
169
  data["matchingMaterialMap"] != null ? (
170
170
  <MatchingActivityContent
171
- answer={answer}
171
+ answerMap={answerMap}
172
172
  changeAnswer={() => {}}
173
173
  canAnswerQuestion={() => {
174
174
  return true;
@@ -181,7 +181,7 @@ const ActivityPreviewByData = ({
181
181
  data["groupingBodyMap"] != null &&
182
182
  data["groupingMaterialMap"] != null ? (
183
183
  <GroupingActivityContent
184
- answer={answer}
184
+ answerMap={answerMap}
185
185
  changeAnswer={() => {}}
186
186
  canAnswerQuestion={() => {
187
187
  return true;
@@ -194,7 +194,7 @@ const ActivityPreviewByData = ({
194
194
  data["fillInTheBlanksBodyMap"] != null &&
195
195
  data["fillInTheBlanksMaterialMap"] != null ? (
196
196
  <FillInTheBlanksActivityContent
197
- answer={answer}
197
+ answerMap={answerMap}
198
198
  changeAnswer={() => {}}
199
199
  canAnswerQuestion={() => {
200
200
  return true;
@@ -207,7 +207,7 @@ const ActivityPreviewByData = ({
207
207
  ) : selectedType === "OPEN_ENDED" &&
208
208
  data["openEndedBodyMap"] != null ? (
209
209
  <OpenEndedActivityContent
210
- answer={answer}
210
+ answerMap={answerMap}
211
211
  canAnswerQuestion={() => false}
212
212
  changeAnswer={() => {}}
213
213
  showMaterialContent={true}
@@ -219,7 +219,7 @@ const ActivityPreviewByData = ({
219
219
  data["trueFalseBodyMap"] != null &&
220
220
  data["trueFalseMaterialMap"] != null ? (
221
221
  <TrueFalseActivityContent
222
- answer={answer}
222
+ answerMap={answerMap}
223
223
  changeAnswer={() => {}}
224
224
  canAnswerQuestion={() => {
225
225
  return true;
@@ -11,7 +11,7 @@ import DropdownActivityMaterialContent from "./material-contents/DropdownActivit
11
11
  import { useState, useEffect } from "react";
12
12
 
13
13
  const DropdownActivityContent = ({
14
- answer,
14
+ answerMap,
15
15
  data,
16
16
  canAnswerQuestion,
17
17
  changeAnswer,
@@ -22,47 +22,21 @@ const DropdownActivityContent = ({
22
22
  const contentMap = parseContentMapFromData(data);
23
23
  const dropdownBodyMap = parseBodyMapFromData(data, "DROPDOWN");
24
24
  const dropdownMaterialMap = parseMaterialMapFromData(data, "DROPDOWN");
25
-
26
- const [currentAnswerMap, setCurrentAnswerMap] = useState(() => {
27
- return retrieveCurrentAnswerMap();
28
- });
29
-
30
- function retrieveCurrentAnswerMap() {
31
- let foundIndex = answer.data.findIndex(
32
- (answerData: any) => answerData.type === "DROPDOWN"
33
- );
34
- return answer.data[foundIndex].answerMap;
35
- }
25
+ const [currentAnswerMap, setCurrentAnswerMap] = useState(answerMap);
36
26
 
37
27
  useEffect(() => {
38
- setCurrentAnswerMap(retrieveCurrentAnswerMap());
39
- }, [answer]);
28
+ setCurrentAnswerMap(answerMap);
29
+ }, [answerMap]);
40
30
 
41
31
  const handleDropdownAnswerOnChange = (
42
- answerObj: any,
32
+ answerMap: any,
43
33
  key: any,
44
34
  value: string
45
35
  ) => {
46
36
  if (isPreview) return;
47
- const newAnswer = {
48
- ...answerObj,
49
- data: answerObj.data.map((item: any) => {
50
- if (item.type === "DROPDOWN") {
51
- return {
52
- ...item,
53
- answerMap: {
54
- ...item.answerMap,
55
- [key]: value,
56
- },
57
- };
58
- }
59
- return item;
60
- }),
61
- };
62
-
63
- const newAnswerMap = { ...currentAnswerMap, [key]: value };
64
- setCurrentAnswerMap(newAnswerMap);
65
- changeAnswer(newAnswer);
37
+ answerMap = { ...currentAnswerMap, [key]: value };
38
+ setCurrentAnswerMap(answerMap);
39
+ changeAnswer(answerMap);
66
40
  };
67
41
 
68
42
  return (
@@ -84,7 +58,7 @@ const DropdownActivityContent = ({
84
58
  <div className={`${isFullScreen ? "w-full" : "w-full md:flex-1"}`}>
85
59
  <DropdownActivityMaterialContent
86
60
  uniqueValue={JSON.stringify(data.contentMap)}
87
- answer={answer}
61
+ answerMap={answerMap}
88
62
  materialMap={dropdownMaterialMap}
89
63
  contentMap={contentMap}
90
64
  checkCanAnswerQuestion={canAnswerQuestion}
@@ -11,7 +11,7 @@ import VerticalDividerLine from "../dividers/VerticalDividerLine";
11
11
  import { useState, useEffect } from "react";
12
12
 
13
13
  const FillInTheBlanksActivityContent = ({
14
- answer,
14
+ answerMap,
15
15
  data,
16
16
  canAnswerQuestion,
17
17
  changeAnswer,
@@ -32,20 +32,11 @@ const FillInTheBlanksActivityContent = ({
32
32
  ? JSON.parse(data.fillInTheBlanksIncorrectList)
33
33
  : [];
34
34
 
35
- const [currentAnswerMap, setCurrentAnswerMap] = useState(() => {
36
- return retrieveCurrentAnswerMap();
37
- });
38
-
39
- function retrieveCurrentAnswerMap() {
40
- let foundIndex = answer.data.findIndex(
41
- (answerData: any) => answerData.type === "FILL_IN_THE_BLANKS"
42
- );
43
- return answer.data[foundIndex].answerMap;
44
- }
35
+ const [currentAnswerMap, setCurrentAnswerMap] = useState(answerMap);
45
36
 
46
37
  useEffect(() => {
47
- setCurrentAnswerMap(retrieveCurrentAnswerMap());
48
- }, [answer]);
38
+ setCurrentAnswerMap(answerMap);
39
+ }, [answerMap]);
49
40
 
50
41
  const constructAnswerOptionList = () => {
51
42
  const optionList: any = [];
@@ -67,30 +58,14 @@ const FillInTheBlanksActivityContent = ({
67
58
  };
68
59
 
69
60
  const handleFillInTheBlanksAnswerOnChange = (
70
- answerObj: any,
61
+ answerMap: any,
71
62
  key: any,
72
63
  value: string | null
73
64
  ) => {
74
65
  if (isPreview) return;
75
- const newAnswer = {
76
- ...answerObj,
77
- data: answerObj.data.map((item: any) => {
78
- if (item.type === "FILL_IN_THE_BLANKS") {
79
- return {
80
- ...item,
81
- answerMap: {
82
- ...item.answerMap,
83
- [key]: value,
84
- },
85
- };
86
- }
87
- return item;
88
- }),
89
- };
90
-
91
- const newAnswerMap = { ...currentAnswerMap, [key]: value };
92
- setCurrentAnswerMap(newAnswerMap);
93
- changeAnswer(newAnswer);
66
+ answerMap = { ...currentAnswerMap, [key]: value };
67
+ setCurrentAnswerMap(answerMap);
68
+ changeAnswer(answerMap);
94
69
  };
95
70
 
96
71
  return (
@@ -112,7 +87,7 @@ const FillInTheBlanksActivityContent = ({
112
87
  <div className={`${isFullScreen ? "w-full" : "w-full md:flex-1"}`}>
113
88
  <FillInTheBlanksActivityMaterialContent
114
89
  uniqueValue={JSON.stringify(data.contentMap)}
115
- answer={answer}
90
+ answerMap={answerMap}
116
91
  optionList={constructAnswerOptionList()}
117
92
  materialMap={fillInTheBlanksMaterialMap}
118
93
  contentMap={contentMap}
@@ -9,7 +9,7 @@ import ActivityBodyContent from "./body-contents/ActivityBodyContent";
9
9
  import GroupingActivityMaterialContent from "./material-contents/GroupingActivityMaterialContent";
10
10
 
11
11
  const GroupingActivityContent = ({
12
- answer,
12
+ answerMap,
13
13
  data,
14
14
  canAnswerQuestion,
15
15
  changeAnswer,
@@ -21,22 +21,18 @@ const GroupingActivityContent = ({
21
21
  const groupingMaterialMap = parseMaterialMapFromData(data, "GROUPING");
22
22
 
23
23
  const handleGroupingAnswerOnChange = (
24
- answer: any,
24
+ answerMap: any,
25
25
  key: any,
26
26
  value: string | null,
27
27
  index: number | null
28
28
  ) => {
29
29
  if (isPreview) return;
30
- let foundIndex = answer.data.findIndex(
31
- (answerData: any) => answerData.type === "GROUPING"
32
- );
33
- const answerMap = answer.data[foundIndex].answerMap;
34
30
  if (value) {
35
31
  answerMap[key].push(value);
36
32
  } else {
37
33
  answerMap[key].splice(index, 1);
38
34
  }
39
- changeAnswer(answer);
35
+ changeAnswer(answerMap);
40
36
  };
41
37
 
42
38
  return (
@@ -48,7 +44,7 @@ const GroupingActivityContent = ({
48
44
  <DividerLine />
49
45
  <GroupingActivityMaterialContent
50
46
  uniqueValue={JSON.stringify(data.contentMap)}
51
- answer={answer}
47
+ answerMap={answerMap}
52
48
  materialMap={groupingMaterialMap}
53
49
  contentMap={contentMap}
54
50
  checkCanAnswerQuestion={canAnswerQuestion}
@@ -10,7 +10,7 @@ import DividerLine from "../dividers/DividerLine";
10
10
  import VerticalDividerLine from "../dividers/VerticalDividerLine";
11
11
 
12
12
  const MCMAActivityContent = ({
13
- answer,
13
+ answerMap,
14
14
  data,
15
15
  canAnswerQuestion,
16
16
  changeAnswer,
@@ -21,12 +21,12 @@ const MCMAActivityContent = ({
21
21
  const MCMABodyMap = parseBodyMapFromData(data, "MCMA");
22
22
  const MCMAMaterialMap = parseMaterialMapFromData(data, "MCMA");
23
23
 
24
- const handleMCMAAnswerOnChange = (answer: any, key: any, value: string) => {
24
+ const handleMCMAAnswerOnChange = (
25
+ answerMap: any,
26
+ key: any,
27
+ value: string
28
+ ) => {
25
29
  if (isPreview) return;
26
- let foundIndex = answer.data.findIndex(
27
- (answerData: any) => answerData.type === "MCMA"
28
- );
29
- const answerMap = answer.data[foundIndex].answerMap;
30
30
  const foundSubIndex = answerMap[key].findIndex(
31
31
  (answerMaterialKey: string) => answerMaterialKey === value
32
32
  );
@@ -35,7 +35,7 @@ const MCMAActivityContent = ({
35
35
  } else {
36
36
  answerMap[key].splice(foundSubIndex, 1);
37
37
  }
38
- changeAnswer(answer);
38
+ changeAnswer(answerMap);
39
39
  };
40
40
 
41
41
  return (
@@ -52,7 +52,7 @@ const MCMAActivityContent = ({
52
52
  <div className={`${isFullScreen ? "w-full" : "w-full md:flex-1"}`}>
53
53
  <MCMAActivityMaterialContent
54
54
  uniqueValue={JSON.stringify(data.contentMap)}
55
- answer={answer}
55
+ answerMap={answerMap}
56
56
  materialMap={MCMAMaterialMap}
57
57
  contentMap={contentMap}
58
58
  checkCanAnswerQuestion={canAnswerQuestion}