catchup-library-web 1.5.2 → 1.5.4

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.
@@ -7,75 +7,78 @@ const ActivitySolutionContent = ({
7
7
  activityTemplateType,
8
8
  data,
9
9
  }: IActivitySolutionProps) => {
10
- if (!activityTemplateType) return;
10
+ if (!activityTemplateType) return null;
11
11
 
12
- let solutionMapString = "";
13
- if (activityTemplateType === "ORDERING") {
14
- if (data["orderingSolutionMap"])
15
- solutionMapString = data["orderingSolutionMap"];
16
- } else if (activityTemplateType === "DROPDOWN") {
17
- if (data["dropdownSolutionMap"])
18
- solutionMapString = data["dropdownSolutionMap"];
19
- } else if (activityTemplateType === "MCSA") {
20
- if (data["MCSASolutionMap"]) solutionMapString = data["MCSASolutionMap"];
21
- } else if (activityTemplateType === "MCMA") {
22
- if (data["MCMASolutionMap"]) solutionMapString = data["MCMASolutionMap"];
23
- } else if (activityTemplateType === "MATCHING") {
24
- if (data["matchingSolutionMap"])
25
- solutionMapString = data["matchingSolutionMap"];
26
- } else if (activityTemplateType === "GROUPING") {
27
- if (data["groupingSolutionMap"])
28
- solutionMapString = data["groupingSolutionMap"];
29
- } else if (activityTemplateType === "FILL_IN_THE_BLANKS") {
30
- if (data["fillInTheBlanksSolutionMap"])
31
- solutionMapString = data["fillInTheBlanksSolutionMap"];
32
- } else if (activityTemplateType === "OPEN_ENDED") {
33
- if (data["openEndedSolutionMap"])
34
- solutionMapString = data["openEndedSolutionMap"];
35
- } else if (activityTemplateType === "TRUE_FALSE") {
36
- if (data["trueFalseSolutionMap"])
37
- solutionMapString = data["trueFalseSolutionMap"];
12
+ // Map activity types to their corresponding solution map keys
13
+ const solutionMapKeys: any = {
14
+ ORDERING: "orderingSolutionMap",
15
+ DROPDOWN: "dropdownSolutionMap",
16
+ MCSA: "MCSASolutionMap",
17
+ MCMA: "MCMASolutionMap",
18
+ MATCHING: "matchingSolutionMap",
19
+ GROUPING: "groupingSolutionMap",
20
+ FILL_IN_THE_BLANKS: "fillInTheBlanksSolutionMap",
21
+ OPEN_ENDED: "openEndedSolutionMap",
22
+ TRUE_FALSE: "trueFalseSolutionMap",
23
+ };
24
+
25
+ const solutionMapKey = solutionMapKeys[activityTemplateType];
26
+
27
+ if (!solutionMapKey) return null;
28
+
29
+ const solutionMapString = data[solutionMapKey];
30
+
31
+ if (!solutionMapString || !solutionMapString.includes("[ONAYLI CEVAP]"))
32
+ return null;
33
+
34
+ let solutionMap;
35
+ try {
36
+ solutionMap = JSON.parse(solutionMapString);
37
+ } catch (error) {
38
+ console.error("Error parsing solution map:", error);
39
+ return null;
38
40
  }
39
- if (!solutionMapString.includes("[ONAYLI CEVAP]")) return;
40
- const solutionMap = JSON.parse(solutionMapString);
41
- if (!solutionMap) return;
42
41
 
43
- if (Object.keys(solutionMap).length === 0) return;
42
+ if (!solutionMap || Object.keys(solutionMap).length === 0) return null;
43
+
44
44
  return (
45
45
  <div className="mx-2">
46
46
  <div className="p-4 border-catchup-blue border-2 rounded-catchup-xlarge">
47
47
  <p className="text-xl font-bold text-center mb-3">
48
48
  {i18n.t("solution")}
49
49
  </p>
50
- {Object.keys(solutionMap).map((key, index) => {
51
- const currentItem = JSON.parse(solutionMap[key]);
50
+ {Object.keys(solutionMap).map((key) => {
51
+ let currentItem;
52
+ try {
53
+ currentItem = JSON.parse(solutionMap[key]);
54
+ } catch (error) {
55
+ console.error(`Error parsing solution item at key ${key}:`, error);
56
+ return null;
57
+ }
58
+
52
59
  const { value } = currentItem;
60
+
53
61
  return (
54
- <p className="my-3">
55
- <span
56
- key={`${key}_${index}`}
57
- className="text-xl whitespace-pre-wrap"
58
- >
59
- {constructInputWithSpecialExpressionList(value).map(
60
- (inputPart, index) => (
61
- <span
62
- key={index}
63
- className={`${inputPart.isBold ? "font-bold" : ""} ${
64
- inputPart.isUnderline ? "underline" : ""
65
- }`}
66
- >
67
- {inputPart.isEquation ? (
68
- <span className="text-2xl">
69
- <InlineMath math={inputPart.value} />
70
- </span>
71
- ) : (
72
- inputPart.value
73
- )}
74
- </span>
75
- )
76
- )}
77
- </span>
78
- </p>
62
+ <div key={key} className="my-3 text-xl">
63
+ {constructInputWithSpecialExpressionList(value).map(
64
+ (inputPart, partIndex) => (
65
+ <span
66
+ key={`${key}_part_${partIndex}`}
67
+ className={`${inputPart.isBold ? "font-bold" : ""} ${
68
+ inputPart.isUnderline ? "underline" : ""
69
+ }`}
70
+ >
71
+ {inputPart.isEquation ? (
72
+ <span className="text-2xl">
73
+ <InlineMath math={inputPart.value} />
74
+ </span>
75
+ ) : (
76
+ inputPart.value
77
+ )}
78
+ </span>
79
+ )
80
+ )}
81
+ </div>
79
82
  );
80
83
  })}
81
84
  </div>