ENCOA-315
This commit is contained in:
@@ -35,7 +35,7 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
const [variant, setVariant] = useState<Variant>("full");
|
||||
const [avoidRepeated, setAvoidRepeated] = useState(false);
|
||||
const [showAbandonPopup, setShowAbandonPopup] = useState(false);
|
||||
const [pendingExercises, setPendingExercises] = useState<string[]>([]);
|
||||
const [moduleLock, setModuleLock] = useState(false);
|
||||
|
||||
const {
|
||||
exam, setExam,
|
||||
@@ -58,7 +58,6 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
saveSession,
|
||||
setFlags,
|
||||
setShuffles,
|
||||
evaluated,
|
||||
} = useExamStore();
|
||||
|
||||
const [isFetchingExams, setIsFetchingExams] = useState(false);
|
||||
@@ -114,68 +113,77 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
setShowAbandonPopup(false);
|
||||
};
|
||||
|
||||
useEvaluationPolling(sessionId ? [sessionId] : [], "exam", user?.id);
|
||||
|
||||
useEffect(() => {
|
||||
if (flags.finalizeModule && !showSolutions && flags.pendingEvaluation) {
|
||||
if (exam && (exam.module === "writing" || exam.module === "speaking") && userSolutions.length > 0 && !showSolutions) {
|
||||
const exercisesToEvaluate = exam.exercises
|
||||
.map(exercise => exercise.id);
|
||||
setModuleLock(true);
|
||||
}, [flags.finalizeModule])
|
||||
|
||||
setPendingExercises(exercisesToEvaluate);
|
||||
useEffect(() => {
|
||||
if (flags.finalizeModule && !showSolutions) {
|
||||
if (exam && (exam.module === "writing" || exam.module === "speaking") && userSolutions.length > 0) {
|
||||
(async () => {
|
||||
await Promise.all(
|
||||
exam.exercises.map(async (exercise, index) => {
|
||||
if (exercise.type === "writing")
|
||||
await evaluateWritingAnswer(user.id, sessionId, exercise, index + 1, userSolutions.find((x) => x.exercise === exercise.id)!, exercise.attachment?.url);
|
||||
|
||||
if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking") {
|
||||
await evaluateSpeakingAnswer(
|
||||
user.id,
|
||||
sessionId,
|
||||
exercise,
|
||||
userSolutions.find((x) => x.exercise === exercise.id)!,
|
||||
index + 1,
|
||||
);
|
||||
}
|
||||
}),
|
||||
)
|
||||
try {
|
||||
const results = await Promise.all(
|
||||
exam.exercises.map(async (exercise, index) => {
|
||||
if (exercise.type === "writing") {
|
||||
const sol = await evaluateWritingAnswer(
|
||||
user.id, sessionId, exercise, index + 1,
|
||||
userSolutions.find((x) => x.exercise === exercise.id)!,
|
||||
exercise.attachment?.url
|
||||
);
|
||||
return sol;
|
||||
}
|
||||
if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking") {
|
||||
const sol = await evaluateSpeakingAnswer(
|
||||
user.id,
|
||||
sessionId,
|
||||
exercise,
|
||||
userSolutions.find((x) => x.exercise === exercise.id)!,
|
||||
index + 1,
|
||||
);
|
||||
return sol;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
const updatedSolutions = userSolutions.map(solution => {
|
||||
const completed = results.filter(r => r !== null).find(
|
||||
(c: any) => c.exercise === solution.exercise
|
||||
);
|
||||
return completed || solution;
|
||||
});
|
||||
setUserSolutions(updatedSolutions);
|
||||
} catch (error) {
|
||||
console.error('Error during module evaluation:', error);
|
||||
} finally {
|
||||
setModuleLock(false);
|
||||
}
|
||||
})();
|
||||
} else {
|
||||
setModuleLock(false);
|
||||
}
|
||||
}
|
||||
}, [exam, showSolutions, userSolutions, sessionId, user?.id, flags]);
|
||||
|
||||
useEvaluationPolling({ pendingExercises, setPendingExercises });
|
||||
}, [exam, showSolutions, userSolutions, sessionId, user.id, flags.finalizeModule, setUserSolutions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (flags.finalizeExam && moduleIndex !== -1) {
|
||||
setModuleIndex(-1);
|
||||
|
||||
|
||||
}
|
||||
}, [flags.finalizeExam, moduleIndex, setModuleIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
if (flags.finalizeExam && !flags.pendingEvaluation && pendingExercises.length === 0) {
|
||||
if (flags.finalizeExam && moduleIndex !== -1 && !moduleLock) {
|
||||
(async () => {
|
||||
if (evaluated.length !== 0) {
|
||||
setUserSolutions(
|
||||
userSolutions.map(solution => {
|
||||
const evaluatedSolution = evaluated.find(e => e.exercise === solution.exercise);
|
||||
if (evaluatedSolution) {
|
||||
return { ...solution, ...evaluatedSolution };
|
||||
}
|
||||
return solution;
|
||||
})
|
||||
);
|
||||
}
|
||||
setModuleIndex(-1);
|
||||
await saveStats();
|
||||
await axios.get("/api/stats/update");
|
||||
setShowSolutions(true);
|
||||
setFlags({ finalizeExam: false });
|
||||
dispatch({ type: "UPDATE_EXAMS" })
|
||||
})();
|
||||
})()
|
||||
}
|
||||
}, [flags.finalizeExam, moduleIndex, saveStats, setModuleIndex, userSolutions, moduleLock, flags.finalizeModule]);
|
||||
|
||||
useEffect(() => {
|
||||
if (flags.finalizeExam && !userSolutions.some(s => s.isDisabled) && !moduleLock) {
|
||||
setShowSolutions(true);
|
||||
setFlags({ finalizeExam: false });
|
||||
dispatch({ type: "UPDATE_EXAMS" });
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [saveStats, setFlags, setModuleIndex, evaluated, pendingExercises, setUserSolutions, flags]);
|
||||
}, [flags.finalizeExam]);
|
||||
|
||||
|
||||
const aggregateScoresByModule = (isPractice?: boolean): {
|
||||
@@ -276,7 +284,7 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
)}
|
||||
{(moduleIndex === -1 && selectedModules.length !== 0) &&
|
||||
<Finish
|
||||
isLoading={flags.pendingEvaluation}
|
||||
isLoading={userSolutions.some(s => s.isDisabled)}
|
||||
user={user!}
|
||||
modules={selectedModules}
|
||||
solutions={userSolutions}
|
||||
|
||||
Reference in New Issue
Block a user