Updated the code to solve the double stats creation

This commit is contained in:
Tiago Ribeiro
2024-03-24 00:46:42 +00:00
parent 51cc1e3f36
commit 29b2c8b3b8
3 changed files with 14 additions and 9 deletions

View File

@@ -266,7 +266,7 @@ export default function ExamPage({page}: Props) {
return Object.assign(exam, {exercises});
};
const onFinish = (solutions: UserSolution[]) => {
const onFinish = async (solutions: UserSolution[]) => {
const solutionIds = solutions.map((x) => x.exercise);
const solutionExams = solutions.map((x) => x.exam);
@@ -276,7 +276,7 @@ export default function ExamPage({page}: Props) {
setHasBeenUploaded(true);
setIsEvaluationLoading(true);
Promise.all(
await Promise.all(
exam.exercises.map(async (exercise) => {
const evaluationID = uuidv4();
if (exercise.type === "writing")
@@ -288,7 +288,7 @@ export default function ExamPage({page}: Props) {
)
.then((responses) => {
setStatsAwaitingEvaluation((prev) => [...prev, ...responses.filter((x) => !!x).map((r) => (r as any).id)]);
setUserSolutions([...userSolutions, ...responses.filter((x) => !!x)] as any);
setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...responses.filter((x) => !!x)] as any);
})
.finally(() => {
setHasBeenUploaded(false);
@@ -297,7 +297,8 @@ export default function ExamPage({page}: Props) {
axios.get("/api/stats/update");
setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...solutions]);
if (exam && exam.module !== "writing" && exam.module !== "speaking")
setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...solutions]);
setModuleIndex(moduleIndex + 1);
setPartIndex(-1);