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

@@ -78,7 +78,7 @@ export default function Level({ exam, showSolutions = false, onFinish, preview =
const [startNow, setStartNow] = useState<boolean>(!showSolutions);
useEffect(() => {
useEffect(() => {
if (!showSolutions && exam.parts[partIndex]?.intro !== undefined && exam.parts[partIndex]?.intro !== "" && !seenParts.has(partIndex)) {
setShowPartDivider(true);
setBgColor(levelBgColor);
@@ -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)
useEffect(() => {
if (hasExamEnded) onFinish(userSolutions)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasExamEnded]);
useEffect(() => {
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!] : [] }]);

View File

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

View File

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

View File

@@ -53,10 +53,9 @@ export default function Speaking({ exam, showSolutions = false, onFinish, previe
}, [exerciseIndex]);
useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) {
setExerciseIndex(exerciseIndex + 1);
}
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
if (hasExamEnded) onFinish(userSolutions)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasExamEnded]);
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 !== "");
useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) {
setExerciseIndex(exerciseIndex + 1);
}
}, [hasExamEnded, exerciseIndex, setExerciseIndex]);
if (hasExamEnded) onFinish(userSolutions)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasExamEnded]);
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
@@ -100,7 +99,7 @@ export default function Writing({ exam, showSolutions = false, preview = false,
defaultTitle="Writing exam"
section={exam.exercises[exerciseIndex]}
sectionIndex={exerciseIndex}
onNext={() => { setShowPartDivider(false); setBgColor("bg-white"); setSeenParts((prev) => new Set(prev).add(exerciseIndex))}}
onNext={() => { setShowPartDivider(false); setBgColor("bg-white"); setSeenParts((prev) => new Set(prev).add(exerciseIndex)) }}
/> : (
<div className="flex flex-col h-full w-full gap-8 items-center">
<ModuleTitle