fix
This commit is contained in:
@@ -98,6 +98,9 @@ const Testen = () => {
|
|||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const q = await generateWeeklyQuiz(currentUser.id, weekNumber);
|
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);
|
setQuiz(q);
|
||||||
setCurrentQ(0);
|
setCurrentQ(0);
|
||||||
setAnswers({});
|
setAnswers({});
|
||||||
@@ -323,6 +326,17 @@ const Testen = () => {
|
|||||||
// ─── Active Quiz ──────────────────────────────────────────
|
// ─── Active Quiz ──────────────────────────────────────────
|
||||||
if (phase === 'quiz' && quiz) {
|
if (phase === 'quiz' && quiz) {
|
||||||
const q = quiz.questions[currentQ];
|
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 selectedAnswer = answers[q.id];
|
||||||
const isCorrect = selectedAnswer === q.correctIndex;
|
const isCorrect = selectedAnswer === q.correctIndex;
|
||||||
const progress = ((currentQ + (showFeedback ? 1 : 0)) / quiz.questions.length) * 100;
|
const progress = ((currentQ + (showFeedback ? 1 : 0)) / quiz.questions.length) * 100;
|
||||||
|
|||||||
Reference in New Issue
Block a user