fix(exam): fix startexam function (not finding examdata)

This commit is contained in:
shafin-r
2025-07-22 22:08:42 +06:00
parent 341a46e788
commit d57aa9b073
5 changed files with 31 additions and 25 deletions

View File

@ -86,18 +86,21 @@ export const ExamProvider: React.FC<{ children: ReactNode }> = ({
setCurrentAttemptState(null);
};
const startExam = () => {
if (!currentExam) {
const startExam = (exam?: Exam) => {
const examToUse = exam || currentExam;
if (!examToUse) {
console.warn("No exam selected, redirecting to /unit");
router.push("/unit");
return;
}
const attempt: ExamAttempt = {
examId: currentExam.id,
exam: currentExam,
examId: examToUse.id,
exam: examToUse,
answers: [],
startTime: new Date(),
totalQuestions: 0,
};
setCurrentAttemptState(attempt);