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({
id,
maxWords,
userSolution,
showSolutions = false,
setUserSolution,
}: {
@@ -20,9 +21,9 @@ function Blank({
userSolution?: string;
maxWords: number;
showSolutions?: boolean;
setUserSolution?: (solution: string) => void;
setUserSolution: (solution: string) => void;
}) {
const [userInput, setUserInput] = useState("");
const [userInput, setUserInput] = useState(userSolution || "");
useEffect(() => {
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")}
placeholder={id}
onChange={(e) => setUserInput(e.target.value)}
onBlur={() => setUserSolution(userInput)}
value={userInput}
contentEditable={showSolutions}
/>