diff --git a/src/components/Exercises/WriteBlanks.tsx b/src/components/Exercises/WriteBlanks.tsx index 3351687f..5763e5b9 100644 --- a/src/components/Exercises/WriteBlanks.tsx +++ b/src/components/Exercises/WriteBlanks.tsx @@ -35,7 +35,7 @@ function Blank({ return ( setUserInput(e.target.value)} onBlur={() => setUserSolution(userInput)} diff --git a/src/components/Solutions/WriteBlanks.tsx b/src/components/Solutions/WriteBlanks.tsx index 825fa3c9..fb1bc890 100644 --- a/src/components/Solutions/WriteBlanks.tsx +++ b/src/components/Solutions/WriteBlanks.tsx @@ -3,10 +3,11 @@ import {WriteBlanksExercise} from "@/interfaces/exam"; import {mdiArrowLeft, mdiArrowRight} from "@mdi/js"; import Icon from "@mdi/react"; import clsx from "clsx"; -import {useEffect, useState} from "react"; +import {Fragment, useEffect, useState} from "react"; import reactStringReplace from "react-string-replace"; import {CommonProps} from "."; import {toast} from "react-toastify"; +import Button from "../Low/Button"; function Blank({ id, @@ -17,7 +18,7 @@ function Blank({ setUserSolution, }: { id: string; - solutions?: string[]; + solutions: string[]; userSolution?: string; maxWords: number; disabled?: boolean; @@ -34,22 +35,35 @@ function Blank({ } }, [maxWords, userInput, setUserSolution]); + const isUserSolutionCorrect = () => userSolution && solutions.map((x) => x.trim().toLowerCase()).includes(userSolution.trim().toLowerCase()); + const getSolutionStyling = () => { - if (solutions && userSolution) { - if (solutions.map((x) => x.trim().toLowerCase()).includes(userSolution.trim().toLowerCase())) return "text-green-500 border-green-500"; + if (!userSolution) { + return "bg-mti-blue-ultralight text-mti-blue-light"; } - return "text-red-500 border-red-500"; + return "bg-mti-green-ultralight text-mti-green-light"; }; return ( - setUserInput(e.target.value)} - value={!solutions ? userInput : solutions.join(" / ")} - contentEditable={disabled} - /> + + {userSolution && !isUserSolutionCorrect() && ( + setUserInput(e.target.value)} + value={userSolution} + contentEditable={disabled} + /> + )} + setUserInput(e.target.value)} + value={!solutions ? userInput : solutions.join(" / ")} + contentEditable={disabled} + /> + ); } @@ -65,7 +79,7 @@ export default function WriteBlanksSolutions({ }: WriteBlanksExercise & CommonProps) { const renderLines = (line: string) => { return ( - + {reactStringReplace(line, /({{\d+}})/g, (match) => { const id = match.replaceAll(/[\{\}]/g, ""); const userSolution = userSolutions.find((x) => x.id === id); @@ -79,31 +93,33 @@ export default function WriteBlanksSolutions({ return ( <> -
- {prompt} - - {text.split("\\n").map((line) => ( - <> +
+ + {prompt.split("\\n").map((line, index) => ( + + {line} +
+
+ ))} +
+ + {text.split("\\n").map((line, index) => ( +

{renderLines(line)}
- +

))}
-
- - + + +
);