Updated the counter of exercises
This commit is contained in:
@@ -88,7 +88,7 @@ export default function ModuleTitle({minTimer, module, label, exerciseIndex, tot
|
||||
<span className="text-base font-semibold">
|
||||
{moduleLabels[module]} exam {label && `- ${label}`}
|
||||
</span>
|
||||
<span className="text-sm font-normal self-end text-mti-gray-davy">
|
||||
<span className="text-sm font-semibold self-end">
|
||||
Exercise {exerciseIndex}/{totalExercises}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ import Button from "@/components/Low/Button";
|
||||
import BlankQuestionsModal from "@/components/BlankQuestionsModal";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {defaultUserSolutions} from "@/utils/exams";
|
||||
import {countExercises} from "@/utils/moduleUtils";
|
||||
|
||||
interface Props {
|
||||
exam: ListeningExam;
|
||||
@@ -133,7 +134,7 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props
|
||||
}
|
||||
minTimer={exam.minTimer}
|
||||
module="listening"
|
||||
totalExercises={exam.parts.flatMap((x) => x.exercises).length}
|
||||
totalExercises={countExercises(exam.parts.flatMap((x) => x.exercises))}
|
||||
disableTimer={showSolutions}
|
||||
/>
|
||||
{renderAudioPlayer()}
|
||||
|
||||
@@ -18,6 +18,7 @@ import Button from "@/components/Low/Button";
|
||||
import BlankQuestionsModal from "@/components/BlankQuestionsModal";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {defaultUserSolutions} from "@/utils/exams";
|
||||
import {countExercises} from "@/utils/moduleUtils";
|
||||
|
||||
interface Props {
|
||||
exam: ReadingExam;
|
||||
@@ -209,7 +210,7 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
|
||||
) || 0) + (exerciseIndex === -1 ? 0 : 1)
|
||||
}
|
||||
module="reading"
|
||||
totalExercises={exam.parts.flatMap((x) => x.exercises).length}
|
||||
totalExercises={countExercises(exam.parts.flatMap((x) => x.exercises))}
|
||||
disableTimer={showSolutions}
|
||||
label={exerciseIndex === -1 ? undefined : convertCamelCaseToReadable(exam.parts[partIndex].exercises[exerciseIndex].type)}
|
||||
/>
|
||||
|
||||
@@ -5,6 +5,7 @@ import {infoButtonStyle} from "@/constants/buttonStyles";
|
||||
import {UserSolution, SpeakingExam} from "@/interfaces/exam";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {defaultUserSolutions} from "@/utils/exams";
|
||||
import {countExercises} from "@/utils/moduleUtils";
|
||||
import {convertCamelCaseToReadable} from "@/utils/string";
|
||||
import {mdiArrowRight} from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
@@ -72,7 +73,7 @@ export default function Speaking({exam, showSolutions = false, onFinish}: Props)
|
||||
minTimer={exam.minTimer}
|
||||
exerciseIndex={exerciseIndex + 1}
|
||||
module="speaking"
|
||||
totalExercises={exam.exercises.length}
|
||||
totalExercises={countExercises(exam.exercises)}
|
||||
disableTimer={showSolutions}
|
||||
/>
|
||||
{exerciseIndex > -1 &&
|
||||
|
||||
@@ -5,6 +5,7 @@ import {infoButtonStyle} from "@/constants/buttonStyles";
|
||||
import {UserSolution, WritingExam} from "@/interfaces/exam";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {defaultUserSolutions} from "@/utils/exams";
|
||||
import {countExercises} from "@/utils/moduleUtils";
|
||||
import {mdiArrowRight} from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
import clsx from "clsx";
|
||||
@@ -71,7 +72,7 @@ export default function Writing({exam, showSolutions = false, onFinish}: Props)
|
||||
minTimer={exam.minTimer}
|
||||
exerciseIndex={exerciseIndex + 1}
|
||||
module="writing"
|
||||
totalExercises={exam.exercises.length}
|
||||
totalExercises={countExercises(exam.exercises)}
|
||||
disableTimer={showSolutions}
|
||||
/>
|
||||
{exerciseIndex > -1 &&
|
||||
|
||||
@@ -6,6 +6,7 @@ import {Exam} from "@/interfaces/exam";
|
||||
import {Type, User} from "@/interfaces/user";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {getExamById} from "@/utils/exams";
|
||||
import {countExercises} from "@/utils/moduleUtils";
|
||||
import {createColumnHelper, flexRender, getCoreRowModel, useReactTable} from "@tanstack/react-table";
|
||||
import axios from "axios";
|
||||
import clsx from "clsx";
|
||||
@@ -71,10 +72,10 @@ export default function ExamList({user}: {user: User}) {
|
||||
|
||||
const getTotalExercises = (exam: Exam) => {
|
||||
if (exam.module === "reading" || exam.module === "listening") {
|
||||
return exam.parts.flatMap((x) => x.exercises).length;
|
||||
return countExercises(exam.parts.flatMap((x) => x.exercises));
|
||||
}
|
||||
|
||||
return exam.exercises.length;
|
||||
return countExercises(exam.exercises);
|
||||
};
|
||||
|
||||
const defaultColumns = [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Module} from "@/interfaces";
|
||||
import {Exercise} from "@/interfaces/exam";
|
||||
|
||||
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking"];
|
||||
|
||||
@@ -16,3 +17,14 @@ export const sortByModule = (a: {module: Module}, b: {module: Module}) => {
|
||||
export const sortByModuleName = (a: string, b: string) => {
|
||||
return MODULE_ARRAY.findIndex((x) => a === x) - MODULE_ARRAY.findIndex((x) => b === x);
|
||||
};
|
||||
|
||||
export const countExercises = (exercises: Exercise[]) => {
|
||||
const lengthMap = exercises.map((e) => {
|
||||
if (e.type === "multipleChoice") return e.questions.length;
|
||||
if (e.type === "interactiveSpeaking") return e.prompts.length;
|
||||
|
||||
return 1;
|
||||
});
|
||||
|
||||
return lengthMap.reduce((accumulator, current) => accumulator + current, 0);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user