Made it so, in the FillBlanks, it automatically goes to the next one

This commit is contained in:
Tiago Ribeiro
2023-09-20 09:57:28 +01:00
parent 0ca2649040
commit 9a45f53062

View File

@@ -81,6 +81,7 @@ export default function FillBlanks({
const [isDrawerShowing, setIsDrawerShowing] = useState(false); const [isDrawerShowing, setIsDrawerShowing] = useState(false);
const hasExamEnded = useExamStore((state) => state.hasExamEnded); const hasExamEnded = useExamStore((state) => state.hasExamEnded);
const allBlanks = Array.from(text.match(/({{\d+}})/g) || []).map((x) => x.replaceAll("{", "").replaceAll("}", ""));
useEffect(() => { useEffect(() => {
setTimeout(() => setIsDrawerShowing(!!currentBlankId), 100); setTimeout(() => setIsDrawerShowing(!!currentBlankId), 100);
@@ -138,6 +139,10 @@ export default function FillBlanks({
onCancel={() => setCurrentBlankId(undefined)} onCancel={() => setCurrentBlankId(undefined)}
onAnswer={(solution: string) => { onAnswer={(solution: string) => {
setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]); setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]);
if (allBlanks.findIndex((x) => x === currentBlankId) + 1 < allBlanks.length) {
setCurrentBlankId(allBlanks[allBlanks.findIndex((x) => x === currentBlankId) + 1]);
return;
}
setCurrentBlankId(undefined); setCurrentBlankId(undefined);
}} }}
/> />