- Adapted the exam to store all of its information to Zustand;

- Made it so, every time there is a change or every X seconds, it saves the session;
This commit is contained in:
Tiago Ribeiro
2024-02-06 12:34:45 +00:00
parent 8baa25c445
commit c4b61c4787
13 changed files with 270 additions and 77 deletions

View File

@@ -50,6 +50,13 @@ export const getExamById = async (module: Module, id: string): Promise<Exam | un
}
};
export const defaultExamUserSolutions = (exam: Exam) => {
if (exam.module === "reading" || exam.module === "listening")
return exam.parts.flatMap((x) => x.exercises).map((x) => defaultUserSolutions(x, exam));
return exam.exercises.map((x) => defaultUserSolutions(x, exam));
};
export const defaultUserSolutions = (exercise: Exercise, exam: Exam): UserSolution => {
const defaultSettings = {
exam: exam.id,
@@ -73,6 +80,9 @@ export const defaultUserSolutions = (exercise: Exercise, exam: Exam): UserSoluti
case "writeBlanks":
total = exercise.text.match(/({{\d+}})/g)?.length || 0;
return {...defaultSettings, score: {correct: 0, total, missing: total}};
case "trueFalse":
total = exercise.questions.length;
return {...defaultSettings, score: {correct: 0, total, missing: total}};
case "writing":
total = 1;
return {...defaultSettings, score: {correct: 0, total, missing: total}};