Solved a few bugs on the WriteBlanks module
This commit is contained in:
@@ -93,8 +93,8 @@ export default function FillBlanks({
|
||||
|
||||
const calculateScore = () => {
|
||||
const total = text.match(/({{\d+}})/g)?.length || 0;
|
||||
const correct = answers.filter((x) => solutions.find((y) => x.id === y.id)?.solution === x.solution.toLowerCase() || false).length;
|
||||
const missing = total - answers.filter((x) => solutions.find((y) => x.id === y.id)).length;
|
||||
const correct = answers.filter((x) => solutions.find((y) => x.id === y.id.toString())?.solution === x.solution.toLowerCase() || false).length;
|
||||
const missing = total - answers.filter((x) => solutions.find((y) => x.id === y.id.toString())).length;
|
||||
|
||||
return {total, correct, missing};
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ export default function MatchSentences({id, options, type, prompt, sentences, us
|
||||
|
||||
const calculateScore = () => {
|
||||
const total = sentences.length;
|
||||
const correct = answers.filter((x) => sentences.find((y) => y.id === x.question)?.solution === x.option || false).length;
|
||||
const missing = total - answers.filter((x) => sentences.find((y) => y.id === x.question)).length;
|
||||
const correct = answers.filter((x) => sentences.find((y) => y.id.toString() === x.question)?.solution === x.option || false).length;
|
||||
const missing = total - answers.filter((x) => sentences.find((y) => y.id.toString() === x.question)).length;
|
||||
|
||||
return {total, correct, missing};
|
||||
};
|
||||
|
||||
@@ -20,26 +20,26 @@ function Question({
|
||||
{variant === "image" &&
|
||||
options.map((option) => (
|
||||
<div
|
||||
key={option.id}
|
||||
onClick={() => (onSelectOption ? onSelectOption(option.id) : null)}
|
||||
key={option.id.toString()}
|
||||
onClick={() => (onSelectOption ? onSelectOption(option.id.toString()) : null)}
|
||||
className={clsx(
|
||||
"flex flex-col items-center border border-mti-gray-platinum p-4 px-8 rounded-xl gap-4 cursor-pointer bg-white relative",
|
||||
userSolution === option.id && "border-mti-purple-light",
|
||||
userSolution === option.id.toString() && "border-mti-purple-light",
|
||||
)}>
|
||||
<span className={clsx("text-sm", userSolution !== option.id && "opacity-50")}>{option.id}</span>
|
||||
<img src={option.src!} alt={`Option ${option.id}`} />
|
||||
<span className={clsx("text-sm", userSolution !== option.id.toString() && "opacity-50")}>{option.id.toString()}</span>
|
||||
<img src={option.src!} alt={`Option ${option.id.toString()}`} />
|
||||
</div>
|
||||
))}
|
||||
{variant === "text" &&
|
||||
options.map((option) => (
|
||||
<div
|
||||
key={option.id}
|
||||
onClick={() => (onSelectOption ? onSelectOption(option.id) : null)}
|
||||
key={option.id.toString()}
|
||||
onClick={() => (onSelectOption ? onSelectOption(option.id.toString()) : null)}
|
||||
className={clsx(
|
||||
"flex border p-4 rounded-xl gap-2 cursor-pointer bg-white text-sm",
|
||||
userSolution === option.id && "border-mti-purple-light",
|
||||
userSolution === option.id.toString() && "border-mti-purple-light",
|
||||
)}>
|
||||
<span className="font-semibold">{option.id}.</span>
|
||||
<span className="font-semibold">{option.id.toString()}.</span>
|
||||
<span>{option.text}</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -66,8 +66,8 @@ export default function MultipleChoice({id, prompt, type, questions, userSolutio
|
||||
|
||||
const calculateScore = () => {
|
||||
const total = questions.length;
|
||||
const correct = answers.filter((x) => questions.find((y) => y.id === x.question)?.solution === x.option || false).length;
|
||||
const missing = total - answers.filter((x) => questions.find((y) => y.id === x.question)).length;
|
||||
const correct = answers.filter((x) => questions.find((y) => y.id.toString() === x.question)?.solution === x.option || false).length;
|
||||
const missing = total - answers.filter((x) => questions.find((y) => y.id.toString() === x.question)).length;
|
||||
|
||||
return {total, correct, missing};
|
||||
};
|
||||
|
||||
@@ -16,8 +16,8 @@ export default function TrueFalse({id, type, prompt, questions, userSolutions, o
|
||||
|
||||
const calculateScore = () => {
|
||||
const total = questions.length || 0;
|
||||
const correct = answers.filter((x) => questions.find((y) => x.id === y.id)?.solution === x.solution.toLowerCase() || false).length;
|
||||
const missing = total - answers.filter((x) => questions.find((y) => x.id === y.id)).length;
|
||||
const correct = answers.filter((x) => questions.find((y) => x.id === y.id.toString())?.solution === x.solution.toLowerCase() || false).length;
|
||||
const missing = total - answers.filter((x) => questions.find((y) => x.id === y.id.toString())).length;
|
||||
|
||||
return {total, correct, missing};
|
||||
};
|
||||
@@ -61,26 +61,26 @@ export default function TrueFalse({id, type, prompt, questions, userSolutions, o
|
||||
<span className="text-sm w-full leading-6">You can click a selected option again to deselect it.</span>
|
||||
<div className="bg-mti-gray-smoke rounded-xl px-5 py-6 flex flex-col gap-8">
|
||||
{questions.map((question, index) => (
|
||||
<div key={question.id} className="flex flex-col gap-4">
|
||||
<div key={question.id.toString()} className="flex flex-col gap-4">
|
||||
<span>
|
||||
{index + 1}. {question.prompt}
|
||||
</span>
|
||||
<div className="flex gap-4">
|
||||
<Button
|
||||
variant={answers.find((x) => x.id === question.id)?.solution === "true" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("true", question.id)}
|
||||
variant={answers.find((x) => x.id === question.id.toString())?.solution === "true" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("true", question.id.toString())}
|
||||
className="!py-2">
|
||||
True
|
||||
</Button>
|
||||
<Button
|
||||
variant={answers.find((x) => x.id === question.id)?.solution === "false" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("false", question.id)}
|
||||
variant={answers.find((x) => x.id === question.id.toString())?.solution === "false" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("false", question.id.toString())}
|
||||
className="!py-2">
|
||||
False
|
||||
</Button>
|
||||
<Button
|
||||
variant={answers.find((x) => x.id === question.id)?.solution === "not_given" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("not_given", question.id)}
|
||||
variant={answers.find((x) => x.id === question.id.toString())?.solution === "not_given" ? "solid" : "outline"}
|
||||
onClick={() => toggleAnswer("not_given", question.id.toString())}
|
||||
className="!py-2">
|
||||
Not Given
|
||||
</Button>
|
||||
|
||||
@@ -61,7 +61,7 @@ export default function WriteBlanks({id, prompt, type, maxWords, solutions, user
|
||||
const correct = answers.filter(
|
||||
(x) =>
|
||||
solutions
|
||||
.find((y) => x.id === y.id)
|
||||
.find((y) => x.id === y.id.toString())
|
||||
?.solution.map((y) => y.toLowerCase())
|
||||
.includes(x.solution.toLowerCase()) || false,
|
||||
).length;
|
||||
|
||||
Reference in New Issue
Block a user