Updated the Level Exam to work based on Parts

This commit is contained in:
Tiago Ribeiro
2024-06-07 13:25:18 +01:00
parent 8ea97ee944
commit daec246835
15 changed files with 176 additions and 121 deletions

View File

@@ -72,7 +72,7 @@ export default function ExamList({user}: {user: User}) {
};
const getTotalExercises = (exam: Exam) => {
if (exam.module === "reading" || exam.module === "listening") {
if (exam.module === "reading" || exam.module === "listening" || exam.module === "level") {
return countExercises(exam.parts.flatMap((x) => x.exercises));
}

View File

@@ -304,7 +304,7 @@ export default function ExamPage({page}: Props) {
};
const updateExamWithUserSolutions = (exam: Exam): Exam => {
if (exam.module === "reading" || exam.module === "listening") {
if (exam.module === "reading" || exam.module === "listening" || exam.module === "level") {
const parts = exam.parts.map((p) =>
Object.assign(p, {
exercises: p.exercises.map((x) =>

View File

@@ -99,10 +99,12 @@ const TaskTab = ({exam, difficulty, setExam}: {exam?: LevelExam; difficulty: Dif
const updatedExam = {
...exam,
exercises: exam.exercises.map((x) => ({
...x,
questions: (x as MultipleChoiceExercise).questions.map((q) => (q.id === question.id ? question : q)),
})),
parts: exam.parts.map((p) =>
p.exercises.map((x) => ({
...x,
questions: (x as MultipleChoiceExercise).questions.map((q) => (q.id === question.id ? question : q)),
})),
),
};
console.log(updatedExam);
setExam(updatedExam as any);
@@ -136,7 +138,8 @@ const TaskTab = ({exam, difficulty, setExam}: {exam?: LevelExam; difficulty: Dif
)}
{exam && (
<div className="flex flex-col gap-2 w-full overflow-y-scroll scrollbar-hide h-full">
{exam.exercises
{exam.parts
.flatMap((x) => x.exercises)
.filter((x) => x.type === "multipleChoice")
.map((ex) => {
const exercise = ex as MultipleChoiceExercise;