From 782976c14f09a7a82176073549d5a7a32bc8ace9 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Fri, 29 Sep 2023 13:56:11 +0100 Subject: [PATCH] Updated the Listening format to work --- src/exams/Finish.tsx | 2 +- src/exams/Listening.tsx | 56 ++++++++++++++++++++++------ src/interfaces/exam.ts | 12 +++--- src/pages/(admin)/Lists/ExamList.tsx | 6 +-- src/pages/exam.tsx | 2 +- src/pages/exercises.tsx | 2 +- 6 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/exams/Finish.tsx b/src/exams/Finish.tsx index 4ddc5b29..3235cd58 100644 --- a/src/exams/Finish.tsx +++ b/src/exams/Finish.tsx @@ -55,7 +55,7 @@ export default function Finish({user, scores, modules, isLoading, onViewResults} const getTotalExercises = () => { const exam = exams.find((x) => x.module === selectedModule)!; - if (exam.module === "reading") { + if (exam.module === "reading" || exam.module === "listening") { return exam.parts.flatMap((x) => x.exercises).length; } diff --git a/src/exams/Listening.tsx b/src/exams/Listening.tsx index 66fe4499..70eed3fa 100644 --- a/src/exams/Listening.tsx +++ b/src/exams/Listening.tsx @@ -17,8 +17,11 @@ interface Props { export default function Listening({exam, showSolutions = false, onFinish}: Props) { const [exerciseIndex, setExerciseIndex] = useState(showSolutions ? 0 : -1); + const [partIndex, setPartIndex] = useState(0); const [timesListened, setTimesListened] = useState(0); - const [userSolutions, setUserSolutions] = useState(exam.exercises.map((x) => defaultUserSolutions(x, exam))); + const [userSolutions, setUserSolutions] = useState( + exam.parts.flatMap((x) => x.exercises).map((x) => defaultUserSolutions(x, exam)), + ); const [showBlankModal, setShowBlankModal] = useState(false); const [hasExamEnded, setHasExamEnded] = useExamStore((state) => [state.hasExamEnded, state.setHasExamEnded]); @@ -43,11 +46,17 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props setUserSolutions((prev) => [...prev.filter((x) => x.exercise !== solution.exercise), solution]); } - if (exerciseIndex + 1 < exam.exercises.length && !hasExamEnded) { + if (exerciseIndex + 1 < exam.parts[partIndex].exercises.length && !hasExamEnded) { setExerciseIndex((prev) => prev + 1); return; } + if (partIndex + 1 < exam.parts.length && !hasExamEnded) { + setPartIndex((prev) => prev + 1); + setExerciseIndex(showSolutions ? 0 : -1); + return; + } + if ( solution && ![...userSolutions.filter((x) => x.exercise !== solution?.exercise).map((x) => x.score.missing), solution?.score.missing].every( @@ -80,7 +89,7 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props }; const getExercise = () => { - const exercise = exam.exercises[exerciseIndex]; + const exercise = exam.parts[partIndex].exercises[exerciseIndex]; return { ...exercise, userSolutions: userSolutions.find((x) => x.exercise === exercise.id)?.solutions || [], @@ -92,17 +101,17 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props

Please listen to the following audio attentively.

- {exam.audio.repeatableTimes > 0 - ? `You will only be allowed to listen to the audio ${exam.audio.repeatableTimes - timesListened} time(s).` + {exam.parts[partIndex].audio.repeatableTimes > 0 + ? `You will only be allowed to listen to the audio ${exam.parts[partIndex].audio.repeatableTimes - timesListened} time(s).` : "You may listen to the audio as many times as you would like."}
setTimesListened((prev) => prev + 1)} - disabled={timesListened === exam.audio.repeatableTimes} + disabled={timesListened === exam.parts[partIndex].audio.repeatableTimes} disablePause />
@@ -114,23 +123,46 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props
x.exercises) + .findIndex( + (x) => x.id === exam.parts[partIndex].exercises[exerciseIndex === -1 ? exerciseIndex + 1 : exerciseIndex]?.id, + ) || 0) + (exerciseIndex === -1 ? 0 : 1) + } minTimer={exam.minTimer} module="listening" - totalExercises={exam.exercises.length} + totalExercises={exam.parts.flatMap((x) => x.exercises).length} disableTimer={showSolutions} /> {renderAudioPlayer()} {exerciseIndex > -1 && - exerciseIndex < exam.exercises.length && + exerciseIndex < exam.parts[partIndex].exercises.length && !showSolutions && renderExercise(getExercise(), nextExercise, previousExercise)} {exerciseIndex > -1 && - exerciseIndex < exam.exercises.length && + exerciseIndex < exam.parts[partIndex].exercises.length && showSolutions && - renderSolution(exam.exercises[exerciseIndex], nextExercise, previousExercise)} + renderSolution(exam.parts[partIndex].exercises[exerciseIndex], nextExercise, previousExercise)}
+ {exerciseIndex === -1 && partIndex > 0 && ( +
+ + +
+ )} {exerciseIndex === -1 && (