fix
This commit is contained in:
@@ -98,6 +98,9 @@ const Testen = () => {
|
||||
setError(null);
|
||||
try {
|
||||
const q = await generateWeeklyQuiz(currentUser.id, weekNumber);
|
||||
if (!q?.questions?.length) {
|
||||
throw new Error('No questions could be generated for this week. Please try again.');
|
||||
}
|
||||
setQuiz(q);
|
||||
setCurrentQ(0);
|
||||
setAnswers({});
|
||||
@@ -323,6 +326,17 @@ const Testen = () => {
|
||||
// ─── Active Quiz ──────────────────────────────────────────
|
||||
if (phase === 'quiz' && quiz) {
|
||||
const q = quiz.questions[currentQ];
|
||||
|
||||
// Safety guard — should never happen, but prevents a crash if questions array is empty
|
||||
if (!q) {
|
||||
return (
|
||||
<div className="p-4 md:p-8 max-w-2xl mx-auto text-center py-20">
|
||||
<p className="text-red-500 font-medium">Something went wrong loading this question.</p>
|
||||
<Button className="mt-4" onClick={() => setPhase('intro')}>Back</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const selectedAnswer = answers[q.id];
|
||||
const isCorrect = selectedAnswer === q.correctIndex;
|
||||
const progress = ((currentQ + (showFeedback ? 1 : 0)) / quiz.questions.length) * 100;
|
||||
|
||||
Reference in New Issue
Block a user