diff --git a/studio-v2/app/learn/[unitId]/quiz/page.tsx b/studio-v2/app/learn/[unitId]/quiz/page.tsx index 57579b4..e6979d2 100644 --- a/studio-v2/app/learn/[unitId]/quiz/page.tsx +++ b/studio-v2/app/learn/[unitId]/quiz/page.tsx @@ -42,10 +42,37 @@ export default function QuizPage() { const loadMC = async () => { setIsLoading(true) try { - const resp = await fetch(`${getApiBase()}/api/learning-units/${unitId}/mc`) - if (!resp.ok) throw new Error(`HTTP ${resp.status}`) - const data = await resp.json() - setQuestions(data.questions || []) + // Try MC endpoint first + let resp = await fetch(`${getApiBase()}/api/learning-units/${unitId}/mc`) + if (resp.ok) { + const data = await resp.json() + setQuestions(data.questions || []) + return + } + + // Fallback: Generate MC from QA items (vocab units don't have pre-generated MC) + resp = await fetch(`${getApiBase()}/api/learning-units/${unitId}/qa`) + if (!resp.ok) throw new Error('Keine Daten verfuegbar') + const qaData = await resp.json() + const qaItems = qaData.qa_items || [] + if (qaItems.length < 4) throw new Error('Zu wenige Woerter fuer Quiz (min. 4)') + + // Build MC questions from QA: question=EN word, options=4 DE answers (1 correct + 3 random) + const generated: MCQuestion[] = qaItems.map((item: any, idx: number) => { + const others = qaItems.filter((_: any, i: number) => i !== idx) + const distractors = [...others].sort(() => Math.random() - 0.5).slice(0, 3) + const options = [ + { id: item.id, text: item.answer }, + ...distractors.map((d: any) => ({ id: d.id, text: d.answer })), + ].sort(() => Math.random() - 0.5) + return { + id: item.id, + question: item.question, + options, + correct_answer: item.id, + } + }) + setQuestions(generated) } catch (err: any) { setError(err.message) } finally {