Updated the reading to a new format
This commit is contained in:
@@ -45,6 +45,15 @@ export default function ExamList() {
|
||||
router.push("/exercises");
|
||||
};
|
||||
|
||||
const getTotalExercises = (module: Module) => {
|
||||
const exam = exams.find((x) => x.module === module)!;
|
||||
if (exam.module === "reading") {
|
||||
return exam.parts.flatMap((x) => x.exercises).length;
|
||||
}
|
||||
|
||||
return exam.exercises.length;
|
||||
};
|
||||
|
||||
const defaultColumns = [
|
||||
columnHelper.accessor("id", {
|
||||
header: "ID",
|
||||
@@ -54,7 +63,7 @@ export default function ExamList() {
|
||||
header: "Module",
|
||||
cell: (info) => <span className={CLASSES[info.getValue()]}>{capitalize(info.getValue())}</span>,
|
||||
}),
|
||||
columnHelper.accessor((x) => x.exercises.length, {
|
||||
columnHelper.accessor((x) => getTotalExercises(x.module), {
|
||||
header: "Exercises",
|
||||
cell: (info) => info.getValue(),
|
||||
}),
|
||||
|
||||
@@ -21,7 +21,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const {module, avoidRepeated} = req.query as {module: string; avoidRepeated: string};
|
||||
const moduleRef = collection(db, module);
|
||||
|
||||
const q = query(moduleRef, where("isDiagnostic", "==", false));
|
||||
const q = query(moduleRef, where("isDiagnostic", "==", true));
|
||||
const snapshot = await getDocs(q);
|
||||
|
||||
const exams: Exam[] = shuffle(
|
||||
|
||||
@@ -137,10 +137,16 @@ export default function Page() {
|
||||
};
|
||||
|
||||
const updateExamWithUserSolutions = (exam: Exam): Exam => {
|
||||
const exercises = exam.exercises.map((x) =>
|
||||
Object.assign(x, !x.userSolutions ? {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions} : x.userSolutions),
|
||||
);
|
||||
if (exam.module === "reading") {
|
||||
const parts = exam.parts.map((p) =>
|
||||
Object.assign(p, {
|
||||
exercises: p.exercises.map((x) => Object.assign(x, {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions})),
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, {parts});
|
||||
}
|
||||
|
||||
const exercises = exam.exercises.map((x) => Object.assign(x, {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions}));
|
||||
return Object.assign(exam, {exercises});
|
||||
};
|
||||
|
||||
|
||||
@@ -141,8 +141,16 @@ export default function Page() {
|
||||
};
|
||||
|
||||
const updateExamWithUserSolutions = (exam: Exam): Exam => {
|
||||
const exercises = exam.exercises.map((x) => Object.assign(x, {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions}));
|
||||
if (exam.module === "reading") {
|
||||
const parts = exam.parts.map((p) =>
|
||||
Object.assign(p, {
|
||||
exercises: p.exercises.map((x) => Object.assign(x, {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions})),
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, {parts});
|
||||
}
|
||||
|
||||
const exercises = exam.exercises.map((x) => Object.assign(x, {userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions}));
|
||||
return Object.assign(exam, {exercises});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user