Solved a bug in WriteBlanks where it wasn't saving the user's answer

This commit is contained in:
Tiago Ribeiro
2023-06-20 22:21:50 +01:00
parent 3a7c29de56
commit 7beb1c84e7

View File

@@ -12,6 +12,7 @@ import Button from "../Low/Button";
function Blank({ function Blank({
id, id,
maxWords, maxWords,
userSolution,
showSolutions = false, showSolutions = false,
setUserSolution, setUserSolution,
}: { }: {
@@ -20,9 +21,9 @@ function Blank({
userSolution?: string; userSolution?: string;
maxWords: number; maxWords: number;
showSolutions?: boolean; showSolutions?: boolean;
setUserSolution?: (solution: string) => void; setUserSolution: (solution: string) => void;
}) { }) {
const [userInput, setUserInput] = useState(""); const [userInput, setUserInput] = useState(userSolution || "");
useEffect(() => { useEffect(() => {
const words = userInput.split(" ").filter((x) => x !== ""); const words = userInput.split(" ").filter((x) => x !== "");
@@ -37,6 +38,7 @@ function Blank({
className={clsx("input border rounded-xl px-2 py-1 bg-white text-blue-400 border-blue-400 my-2")} className={clsx("input border rounded-xl px-2 py-1 bg-white text-blue-400 border-blue-400 my-2")}
placeholder={id} placeholder={id}
onChange={(e) => setUserInput(e.target.value)} onChange={(e) => setUserInput(e.target.value)}
onBlur={() => setUserSolution(userInput)}
value={userInput} value={userInput}
contentEditable={showSolutions} contentEditable={showSolutions}
/> />