Solved the solution duplication bug

This commit is contained in:
Tiago Ribeiro
2024-03-24 12:22:52 +00:00
parent f320fee416
commit c2b6be4425

View File

@@ -276,13 +276,16 @@ export default function ExamPage({page}: Props) {
const solutionIds = solutions.map((x) => x.exercise); const solutionIds = solutions.map((x) => x.exercise);
const solutionExams = solutions.map((x) => x.exam); const solutionExams = solutions.map((x) => x.exam);
let newSolutions = [...solutions];
if (exam && !solutionExams.includes(exam.id)) return; if (exam && !solutionExams.includes(exam.id)) return;
if (exam && (exam.module === "writing" || exam.module === "speaking") && solutions.length > 0 && !showSolutions) { if (exam && (exam.module === "writing" || exam.module === "speaking") && solutions.length > 0 && !showSolutions) {
setHasBeenUploaded(true); setHasBeenUploaded(true);
setIsEvaluationLoading(true); setIsEvaluationLoading(true);
Promise.all( const responses: UserSolution[] = (
await Promise.all(
exam.exercises.map(async (exercise) => { exam.exercises.map(async (exercise) => {
const evaluationID = uuidv4(); const evaluationID = uuidv4();
if (exercise.type === "writing") if (exercise.type === "writing")
@@ -292,31 +295,16 @@ export default function ExamPage({page}: Props) {
return await evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!, evaluationID); return await evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!, evaluationID);
}), }),
) )
.then((responses) => { ).filter((x) => !!x) as UserSolution[];
examStore.setState((prev) => {
return { newSolutions = [...newSolutions.filter((x) => !responses.map((y) => y.exercise).includes(x.exercise)), ...responses];
userSolutions: [
...prev.userSolutions.filter(
(x) =>
!responses
.filter((r) => !!r)
.map((r) => r!.id)
.includes(x.id),
),
...responses.filter((x) => !!x),
] as any,
};
});
setStatsAwaitingEvaluation((prev) => [...prev, ...responses.filter((x) => !!x).map((r) => (r as any).id)]); setStatsAwaitingEvaluation((prev) => [...prev, ...responses.filter((x) => !!x).map((r) => (r as any).id)]);
})
.finally(() => {
setHasBeenUploaded(false); setHasBeenUploaded(false);
});
} }
axios.get("/api/stats/update"); axios.get("/api/stats/update");
setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...solutions]); setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...newSolutions]);
setModuleIndex(moduleIndex + 1); setModuleIndex(moduleIndex + 1);
setPartIndex(-1); setPartIndex(-1);