diff --git a/src/components/Exercises/FillBlanks.tsx b/src/components/Exercises/FillBlanks.tsx index c67c2320..8cea0a9f 100644 --- a/src/components/Exercises/FillBlanks.tsx +++ b/src/components/Exercises/FillBlanks.tsx @@ -1,4 +1,5 @@ import {FillBlanksExercise} from "@/interfaces/exam"; +import useExamStore from "@/stores/examStore"; import clsx from "clsx"; import {Fragment, useEffect, useState} from "react"; import reactStringReplace from "react-string-replace"; @@ -79,10 +80,17 @@ export default function FillBlanks({ const [currentBlankId, setCurrentBlankId] = useState(); const [isDrawerShowing, setIsDrawerShowing] = useState(false); + const hasExamEnded = useExamStore((state) => state.hasExamEnded); + useEffect(() => { setTimeout(() => setIsDrawerShowing(!!currentBlankId), 100); }, [currentBlankId]); + useEffect(() => { + if (hasExamEnded) onNext({exercise: id, solutions: answers, score: calculateScore(), type}); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [hasExamEnded]); + 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; diff --git a/src/components/Exercises/MatchSentences.tsx b/src/components/Exercises/MatchSentences.tsx index a94b0063..731b3722 100644 --- a/src/components/Exercises/MatchSentences.tsx +++ b/src/components/Exercises/MatchSentences.tsx @@ -3,16 +3,19 @@ import {MatchSentencesExercise} from "@/interfaces/exam"; import {mdiArrowLeft, mdiArrowRight} from "@mdi/js"; import Icon from "@mdi/react"; import clsx from "clsx"; -import {Fragment, useState} from "react"; +import {Fragment, useEffect, useState} from "react"; import LineTo from "react-lineto"; import {CommonProps} from "."; import Button from "../Low/Button"; import Xarrow from "react-xarrows"; +import useExamStore from "@/stores/examStore"; export default function MatchSentences({id, options, type, prompt, sentences, userSolutions, onNext, onBack}: MatchSentencesExercise & CommonProps) { const [selectedQuestion, setSelectedQuestion] = useState(); const [answers, setAnswers] = useState<{question: string; option: string}[]>(userSolutions); + const hasExamEnded = useExamStore((state) => state.hasExamEnded); + const calculateScore = () => { const total = sentences.length; const correct = answers.filter((x) => sentences.find((y) => y.id === x.question)?.solution === x.option || false).length; @@ -27,9 +30,11 @@ export default function MatchSentences({id, options, type, prompt, sentences, us setSelectedQuestion(undefined); }; - const getSentenceColor = (id: string) => { - return sentences.find((x) => x.id === id)?.color || ""; - }; + useEffect(() => { + console.log({hasExamEnded}); + if (hasExamEnded) onNext({exercise: id, solutions: answers, score: calculateScore(), type}); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [hasExamEnded]); return ( <> @@ -44,7 +49,7 @@ export default function MatchSentences({id, options, type, prompt, sentences, us
- {sentences.map(({sentence, id, color}) => ( + {sentences.map(({sentence, id}) => (
{sentence}