catchup-library-web 2.1.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "2.1.5",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,8 +1,4 @@
1
1
  import { useEffect, useState } from "react";
2
- import {
3
- constructAnswerBasedOnData,
4
- retrieveDifficultyByActivityTypeFromData,
5
- } from "../../utilization/CatchtivityUtilization";
6
2
  import DropdownActivityContent from "./DropdownActivityContent";
7
3
  import FillInTheBlanksActivityContent from "./FillInTheBlanksActivityContent";
8
4
  import GroupingActivityContent from "./GroupingActivityContent";
@@ -13,80 +9,215 @@ import OpenEndedActivityContent from "./OpenEndedActivityContent";
13
9
  import OrderingActivityContent from "./OrderingActivityContent";
14
10
  import SelectionBox from "../boxes/SelectionBox";
15
11
  import TrueFalseActivityContent from "./TrueFalseActivityContent";
16
- import { IActivityPreviewByDataProps } from "../../properties/ActivityProperties";
17
12
  import ActivitySolutionContent from "./solution-contents/ActivitySolutionContent";
18
- import i18n from "../../language/i18n";
19
13
  import ActivityEvaluationRubricContent from "./evaluation-rubric-contents/ActivityEvaluationRubricContent";
20
14
  import DividerLine from "../dividers/DividerLine";
15
+ import i18n from "../../language/i18n";
16
+ import {
17
+ constructActivityAnswerMap,
18
+ retrieveDifficultyByActivityTypeFromData,
19
+ } from "../../utilization/CatchtivityUtilization";
20
+ import { IActivityPreviewByDataProps } from "../../properties/ActivityProperties";
21
+ import ActivityEmptyContent from "./empty-contents/ActivityEmptyContent";
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
+ ];
21
37
 
22
38
  const ActivityPreviewByData = ({
23
39
  data,
24
- showType,
25
- showDescription,
26
- lockedType,
27
- typeOptionList,
28
- showSolution,
29
- showEvaluationRubric,
30
- showDifficulty,
31
- isFullScreen,
40
+ answerType = null,
41
+ showType = true,
42
+ showDescription = true,
43
+ typeList = [],
44
+ showSolution = false,
45
+ showEvaluationRubric = false,
46
+ showDifficulty = true,
47
+ isFullScreen = false,
48
+ showCorrectAnswer = false,
32
49
  }: IActivityPreviewByDataProps) => {
33
- const [key, setKey] = useState(new Date().getTime());
34
50
  const [selectedType, setSelectedType] = useState<string | null>(null);
35
51
  const [optionList, setOptionList] = useState<any[]>([]);
52
+ const [answerMapMap, setAnswerMapMap] = useState<any>({});
53
+ const [activityTemplateTypeList, setActivityTemplateTypeList] = useState<
54
+ any[]
55
+ >([]);
36
56
 
37
57
  useEffect(() => {
38
58
  if (!data) return;
39
- setKey(new Date().getTime());
40
- }, [data]);
41
-
42
- useEffect(() => {
43
- if (!typeOptionList) return;
44
- if (typeOptionList.length === 0) return;
45
- let foundTypeOption;
46
- if (lockedType) {
47
- foundTypeOption = typeOptionList.find(
48
- (typeOption) => typeOption.id === lockedType
59
+ let currentActivityTemplateMapList: any[] = JSON.parse(
60
+ JSON.stringify(ACTIVITY_TEMPLATE_LIST)
61
+ );
62
+ if (typeList.length > 0) {
63
+ currentActivityTemplateMapList = currentActivityTemplateMapList.filter(
64
+ (activityTemplateMap) => typeList.includes(activityTemplateMap.type)
49
65
  );
50
66
  }
51
- if (foundTypeOption) {
52
- setSelectedType(foundTypeOption.id);
53
- } else {
54
- setSelectedType(typeOptionList[0].id);
67
+ const currentActivityTemplateTypeList = [];
68
+ for (const activityTemplateMap of currentActivityTemplateMapList) {
69
+ if (data[activityTemplateMap.materialMap]) {
70
+ currentActivityTemplateTypeList.push(activityTemplateMap);
71
+ }
55
72
  }
56
- }, [typeOptionList, lockedType]);
73
+ setActivityTemplateTypeList(currentActivityTemplateMapList);
74
+ }, [data, answerType, typeList]);
57
75
 
58
76
  useEffect(() => {
59
- if (!data) return;
60
- if (!typeOptionList) return;
61
- if (typeOptionList.length === 0) return;
62
- let currentTypeOptionList = JSON.parse(JSON.stringify(typeOptionList));
63
- if (lockedType) {
64
- currentTypeOptionList = currentTypeOptionList.filter(
65
- (typeOption: any) => typeOption.id === lockedType
66
- );
77
+ if (activityTemplateTypeList.length === 0) return;
78
+ const currentOptionList = [];
79
+ for (const activityTemplateType of activityTemplateTypeList) {
80
+ const currentTypeOption: any = {
81
+ id: activityTemplateType.type,
82
+ value: i18n.t(activityTemplateType.type),
83
+ };
84
+ if (showDifficulty) {
85
+ currentTypeOption.subText = i18n.t(
86
+ retrieveDifficultyByActivityTypeFromData(
87
+ activityTemplateType.type,
88
+ data
89
+ )
90
+ );
91
+ }
92
+ currentOptionList.push(currentTypeOption);
67
93
  }
68
- if (showDifficulty) {
69
- setOptionList(
70
- currentTypeOptionList.map((typeOption: any) => ({
71
- ...typeOption,
72
- subText: i18n.t(
73
- retrieveDifficultyByActivityTypeFromData(typeOption.id, data)
74
- ),
75
- }))
76
- );
77
- } else {
78
- setOptionList(currentTypeOptionList);
94
+ setOptionList(currentOptionList);
95
+ }, [activityTemplateTypeList, showDifficulty]);
96
+
97
+ useEffect(() => {
98
+ if (optionList.length === 0) return;
99
+ setSelectedType(optionList[0].id);
100
+ }, [optionList]);
101
+
102
+ useEffect(() => {
103
+ if (activityTemplateTypeList.length === 0) return;
104
+ const currentAnswerMapMap: any = {};
105
+ for (const activityTemplateMap of activityTemplateTypeList) {
106
+ if (answerType === activityTemplateMap.type) {
107
+ currentAnswerMapMap[activityTemplateMap.type] = data.answerMap;
108
+ } else {
109
+ currentAnswerMapMap[activityTemplateMap.type] =
110
+ constructActivityAnswerMap(
111
+ activityTemplateMap.type,
112
+ JSON.parse(JSON.stringify(data))
113
+ );
114
+ }
115
+ }
116
+ setAnswerMapMap(currentAnswerMapMap);
117
+ }, [activityTemplateTypeList]);
118
+
119
+ const RenderSelectedActivityContent = () => {
120
+ if (!selectedType) return null;
121
+
122
+ const commonProps = {
123
+ answerMap: answerMapMap[selectedType],
124
+ data,
125
+ canAnswerQuestion: () => true,
126
+ changeAnswer: () => {},
127
+ isPreview: true,
128
+ showCorrectAnswer,
129
+ isFullScreen,
130
+ };
131
+
132
+ const isEmpty = answerMapMap[selectedType].isEmpty;
133
+
134
+ switch (selectedType) {
135
+ case "ORDERING":
136
+ return data.orderingBodyMap && data.orderingMaterialMap ? (
137
+ <>
138
+ {isEmpty && <ActivityEmptyContent />}
139
+ <OrderingActivityContent {...commonProps} />
140
+ </>
141
+ ) : null;
142
+
143
+ case "DROPDOWN":
144
+ return data.dropdownBodyMap && data.dropdownMaterialMap ? (
145
+ <>
146
+ {isEmpty && <ActivityEmptyContent />}
147
+ <DropdownActivityContent {...commonProps} />
148
+ </>
149
+ ) : null;
150
+
151
+ case "MCSA":
152
+ return data.MCSABodyMap && data.MCSAMaterialMap ? (
153
+ <>
154
+ {isEmpty && <ActivityEmptyContent />}
155
+ <MCSAActivityContent {...commonProps} />
156
+ </>
157
+ ) : null;
158
+
159
+ case "MCMA":
160
+ return data.MCMABodyMap && data.MCMAMaterialMap ? (
161
+ <>
162
+ {isEmpty && <ActivityEmptyContent />}
163
+ <MCMAActivityContent {...commonProps} />
164
+ </>
165
+ ) : null;
166
+
167
+ case "MATCHING":
168
+ return data.matchingBodyMap && data.matchingMaterialMap ? (
169
+ <>
170
+ {isEmpty && <ActivityEmptyContent />}
171
+ <MatchingActivityContent {...commonProps} />
172
+ </>
173
+ ) : null;
174
+
175
+ case "GROUPING":
176
+ return data.groupingBodyMap && data.groupingMaterialMap ? (
177
+ <>
178
+ {isEmpty && <ActivityEmptyContent />}
179
+ <GroupingActivityContent {...commonProps} />
180
+ </>
181
+ ) : null;
182
+
183
+ case "FILL_IN_THE_BLANKS":
184
+ return data.fillInTheBlanksBodyMap &&
185
+ data.fillInTheBlanksMaterialMap ? (
186
+ <>
187
+ {isEmpty && <ActivityEmptyContent />}
188
+ <FillInTheBlanksActivityContent {...commonProps} />
189
+ </>
190
+ ) : null;
191
+
192
+ case "OPEN_ENDED":
193
+ return data.openEndedBodyMap ? (
194
+ <>
195
+ {isEmpty && <ActivityEmptyContent />}
196
+ <OpenEndedActivityContent
197
+ {...commonProps}
198
+ showMaterialContent={true}
199
+ />
200
+ </>
201
+ ) : null;
202
+
203
+ case "TRUE_FALSE":
204
+ return data.trueFalseBodyMap && data.trueFalseMaterialMap ? (
205
+ <>
206
+ {isEmpty && <ActivityEmptyContent />}
207
+ <TrueFalseActivityContent {...commonProps} />
208
+ </>
209
+ ) : null;
210
+
211
+ default:
212
+ return null;
79
213
  }
80
- }, [data, lockedType, typeOptionList, showDifficulty]);
214
+ };
81
215
 
82
- if (!data) return;
83
- if (!selectedType) return;
84
- const answerMap = constructAnswerBasedOnData(selectedType, data);
85
- console.log("answer map: ", answerMap);
216
+ if (!data) return null;
86
217
 
87
218
  return (
88
- <div key={key}>
89
- {showType ? (
219
+ <div>
220
+ {showType && optionList.length > 0 ? (
90
221
  <>
91
222
  <div className="mb-4">
92
223
  {showDescription ? (
@@ -108,130 +239,12 @@ const ActivityPreviewByData = ({
108
239
  <DividerLine />
109
240
  </>
110
241
  ) : null}
111
- <div key={selectedType} className="">
112
- {selectedType === "ORDERING" &&
113
- data["orderingBodyMap"] != null &&
114
- data["orderingMaterialMap"] != null ? (
115
- <OrderingActivityContent
116
- answerMap={answerMap}
117
- changeAnswer={() => {}}
118
- canAnswerQuestion={() => {
119
- return true;
120
- }}
121
- data={data}
122
- isPreview={true}
123
- showCorrectAnswer={true}
124
- />
125
- ) : selectedType === "DROPDOWN" &&
126
- data["dropdownBodyMap"] != null &&
127
- data["dropdownMaterialMap"] != null ? (
128
- <DropdownActivityContent
129
- answerMap={answerMap}
130
- changeAnswer={() => {}}
131
- canAnswerQuestion={() => {
132
- return true;
133
- }}
134
- data={data}
135
- isPreview={true}
136
- showCorrectAnswer={true}
137
- isFullScreen={isFullScreen}
138
- />
139
- ) : selectedType === "MCSA" &&
140
- data["MCSABodyMap"] != null &&
141
- data["MCSAMaterialMap"] != null ? (
142
- <MCSAActivityContent
143
- answerMap={answerMap}
144
- changeAnswer={() => {}}
145
- canAnswerQuestion={() => {
146
- return true;
147
- }}
148
- data={data}
149
- isPreview={true}
150
- showCorrectAnswer={true}
151
- isFullScreen={isFullScreen}
152
- />
153
- ) : selectedType === "MCMA" &&
154
- data["MCMABodyMap"] != null &&
155
- data["MCMAMaterialMap"] != null ? (
156
- <MCMAActivityContent
157
- answerMap={answerMap}
158
- changeAnswer={() => {}}
159
- canAnswerQuestion={() => {
160
- return true;
161
- }}
162
- data={data}
163
- isPreview={true}
164
- showCorrectAnswer={true}
165
- isFullScreen={isFullScreen}
166
- />
167
- ) : selectedType === "MATCHING" &&
168
- data["matchingBodyMap"] != null &&
169
- data["matchingMaterialMap"] != null ? (
170
- <MatchingActivityContent
171
- answerMap={answerMap}
172
- changeAnswer={() => {}}
173
- canAnswerQuestion={() => {
174
- return true;
175
- }}
176
- data={data}
177
- isPreview={true}
178
- showCorrectAnswer={true}
179
- />
180
- ) : selectedType === "GROUPING" &&
181
- data["groupingBodyMap"] != null &&
182
- data["groupingMaterialMap"] != null ? (
183
- <GroupingActivityContent
184
- answerMap={answerMap}
185
- changeAnswer={() => {}}
186
- canAnswerQuestion={() => {
187
- return true;
188
- }}
189
- data={data}
190
- isPreview={true}
191
- showCorrectAnswer={true}
192
- />
193
- ) : selectedType === "FILL_IN_THE_BLANKS" &&
194
- data["fillInTheBlanksBodyMap"] != null &&
195
- data["fillInTheBlanksMaterialMap"] != null ? (
196
- <FillInTheBlanksActivityContent
197
- answerMap={answerMap}
198
- changeAnswer={() => {}}
199
- canAnswerQuestion={() => {
200
- return true;
201
- }}
202
- data={data}
203
- isPreview={true}
204
- showCorrectAnswer={true}
205
- isFullScreen={isFullScreen}
206
- />
207
- ) : selectedType === "OPEN_ENDED" &&
208
- data["openEndedBodyMap"] != null ? (
209
- <OpenEndedActivityContent
210
- answerMap={answerMap}
211
- canAnswerQuestion={() => false}
212
- changeAnswer={() => {}}
213
- showMaterialContent={true}
214
- data={data}
215
- isPreview={true}
216
- isFullScreen={isFullScreen}
217
- />
218
- ) : selectedType === "TRUE_FALSE" &&
219
- data["trueFalseBodyMap"] != null &&
220
- data["trueFalseMaterialMap"] != null ? (
221
- <TrueFalseActivityContent
222
- answerMap={answerMap}
223
- changeAnswer={() => {}}
224
- canAnswerQuestion={() => {
225
- return true;
226
- }}
227
- data={data}
228
- isPreview={true}
229
- showCorrectAnswer={true}
230
- isFullScreen={isFullScreen}
231
- />
232
- ) : null}
242
+
243
+ <div className="flex flex-col my-2 w-full p-5">
244
+ {RenderSelectedActivityContent()}
233
245
  </div>
234
- {showSolution ? (
246
+
247
+ {selectedType && showSolution ? (
235
248
  <div className="my-4">
236
249
  <ActivitySolutionContent
237
250
  activityTemplateType={selectedType}
@@ -239,7 +252,8 @@ const ActivityPreviewByData = ({
239
252
  />
240
253
  </div>
241
254
  ) : null}
242
- {showEvaluationRubric ? (
255
+
256
+ {selectedType && showEvaluationRubric ? (
243
257
  <div className="my-4">
244
258
  <ActivityEvaluationRubricContent
245
259
  activityTemplateType={selectedType}
package/src/index.ts CHANGED
@@ -35,7 +35,6 @@ export { default as TrueFalseActivityContent } from "./components/activities/Tru
35
35
  export { default as ActivitySolutionContent } from "./components/activities/solution-contents/ActivitySolutionContent";
36
36
  export { default as ActivityEvaluationRubricContent } from "./components/activities/evaluation-rubric-contents/ActivityEvaluationRubricContent";
37
37
  export { default as ActivityPreviewByData } from "./components/activities/ActivityPreviewByData";
38
- export { default as ActivityPreviewByAnswerData } from "./components/activities/ActivityPreviewByAnswerData";
39
38
 
40
39
  export { default as StatusError } from "./components/errors/StatusError";
41
40
 
@@ -218,18 +218,6 @@ export interface IActivitySolutionProps {
218
218
  }
219
219
 
220
220
  export interface IActivityPreviewByDataProps {
221
- data: any;
222
- showType: boolean;
223
- showDescription: boolean;
224
- lockedType: string;
225
- typeOptionList: any[];
226
- showDifficulty: boolean;
227
- showSolution: boolean;
228
- showEvaluationRubric: boolean;
229
- isFullScreen: boolean;
230
- }
231
-
232
- export interface IActivityPreviewByAnswerDataProps {
233
221
  data: any;
234
222
  answerType?: string | null;
235
223
  showType?: boolean;