fix: make revealed optional in ExamState; fix keyboard handler stale closure; fix navStatus fallthrough

This commit is contained in:
LaurensBartelds committed 2026-04-21 21:53:33 +02:00
1 parent 7217cd3a28
commit 62f714a4a4
2 files changed
+4 -3

No files matched your search

+3 -2
View File
@@ -59,12 +59,12 @@ export default function ExamRunner({ exam, state, setState, onSubmit, onExit }:
if (e.key === 'f') toggleFlag()
if (/^[1-9]$/.test(e.key) && q.type === 'multiple-choice' && q.choices) {
const ci = parseInt(e.key, 10) - 1
if (q.choices[ci]) setAnswer(q.choices[ci].id)
if (q.choices[ci]) setState((s) => ({ ...s, answers: { ...s.answers, [q.id]: q.choices[ci].id } }))
}
}
window.addEventListener('keydown', handler)
return () => window.removeEventListener('keydown', handler)
}, [currentIdx, q, goTo, toggleFlag]) // eslint-disable-line react-hooks/exhaustive-deps
}, [currentIdx, q, goTo, toggleFlag, setState])
const graded = feedbackMode === 'immediate' && revealed
const answered = answers[q.id] != null && (!Array.isArray(answers[q.id]) || (answers[q.id] as unknown[]).length > 0)
@@ -75,6 +75,7 @@ export default function ExamRunner({ exam, state, setState, onSubmit, onExit }:
const r = gradeQuestion(qq, answers[qq.id])
if (r.status === 'correct') return 'correct'
if (r.status === 'wrong') return 'wrong'
// fall through to answered/flagged for ungraded/unanswered revealed states (e.g. essay)
}
if (flags[qq.id]) return 'flagged'
const a = answers[qq.id]