Corrected the behaviour of the exam after the timer has ended

This commit is contained in:
Tiago Ribeiro
2024-11-20 10:26:59 +00:00
parent e6d77af53f
commit 0eed8e4612
7 changed files with 53 additions and 52 deletions

View File

@@ -101,6 +101,11 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
const [showSolutionsSave, setShowSolutionsSave] = useState(showSolutions ? userSolutions.filter((x) => x.module === "level") : undefined) const [showSolutionsSave, setShowSolutionsSave] = useState(showSolutions ? userSolutions.filter((x) => x.module === "level") : undefined)
useEffect(() => {
if (hasExamEnded) onFinish(userSolutions)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasExamEnded]);
useEffect(() => { useEffect(() => {
if (typeof currentSolution !== "undefined") { if (typeof currentSolution !== "undefined") {
setUserSolutions([...userSolutions.filter((x) => x.exercise !== currentSolution.exercise), { ...currentSolution, module: "level" as Module, exam: exam.id, shuffleMaps: exam.shuffle ? [...shuffles.find((x) => x.exerciseID == currentExercise?.id)?.shuffles!] : [] }]); setUserSolutions([...userSolutions.filter((x) => x.exercise !== currentSolution.exercise), { ...currentSolution, module: "level" as Module, exam: exam.id, shuffleMaps: exam.shuffle ? [...shuffles.find((x) => x.exerciseID == currentExercise?.id)?.shuffles!] : [] }]);

View File

@@ -145,10 +145,9 @@ export default function Listening({ exam, showSolutions = false, preview = false
}, []); }, []);
useEffect(() => { useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) { if (hasExamEnded) onFinish(userSolutions)
setExerciseIndex(exerciseIndex + 1); // eslint-disable-next-line react-hooks/exhaustive-deps
} }, [hasExamEnded]);
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
const confirmFinishModule = (keepGoing?: boolean) => { const confirmFinishModule = (keepGoing?: boolean) => {
if (!keepGoing) { if (!keepGoing) {

View File

@@ -173,10 +173,9 @@ export default function Reading({ exam, showSolutions = false, preview = false,
}, []); }, []);
useEffect(() => { useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) { if (hasExamEnded) onFinish(userSolutions)
setExerciseIndex(exerciseIndex + 1); // eslint-disable-next-line react-hooks/exhaustive-deps
} }, [hasExamEnded]);
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
const confirmFinishModule = (keepGoing?: boolean) => { const confirmFinishModule = (keepGoing?: boolean) => {
if (!keepGoing) { if (!keepGoing) {

View File

@@ -53,10 +53,9 @@ export default function Speaking({ exam, showSolutions = false, onFinish, previe
}, [exerciseIndex]); }, [exerciseIndex]);
useEffect(() => { useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) { if (hasExamEnded) onFinish(userSolutions)
setExerciseIndex(exerciseIndex + 1); // eslint-disable-next-line react-hooks/exhaustive-deps
} }, [hasExamEnded]);
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0)); const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));

View File

@@ -34,10 +34,9 @@ export default function Writing({ exam, showSolutions = false, preview = false,
const [showPartDivider, setShowPartDivider] = useState<boolean>(typeof exam.exercises[0].intro === "string" && exam.exercises[0].intro !== ""); const [showPartDivider, setShowPartDivider] = useState<boolean>(typeof exam.exercises[0].intro === "string" && exam.exercises[0].intro !== "");
useEffect(() => { useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) { if (hasExamEnded) onFinish(userSolutions)
setExerciseIndex(exerciseIndex + 1); // eslint-disable-next-line react-hooks/exhaustive-deps
} }, [hasExamEnded]);
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0)); const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));

View File

@@ -110,7 +110,7 @@ export default function ExamList({user, entities}: {user: User; entities: Entity
setExams([exam]); setExams([exam]);
setSelectedModules([module]); setSelectedModules([module]);
router.push("/exercises"); router.push("/exam");
}; };
const privatizeExam = async (exam: Exam) => { const privatizeExam = async (exam: Exam) => {