Files
X4Lo c754477f07 Add much more practice content to every section
Hoeren 28 exercises, Lesen 22 texts, Schreiben 24 tasks, Sprechen 20 topics + 8 planning tasks + 10 presentations, Grammatik 20 lessons with ~260 exercises and a random drill, 332 words with gap-fill, plural and hat/ist drills.
2026-11-05 21:47:08 +00:00

297 lines
11 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useMemo, useState } from "react";
import { allGrammarExercises, lessons, type GrammarEx, type Lesson } from "@/data/grammatik";
import Ar from "@/components/Ar";
import SpeakButton from "@/components/SpeakButton";
import ResultCard from "@/components/ResultCard";
import { recordResult, useProgress } from "@/lib/progress";
import { sfx } from "@/lib/sfx";
export default function GrammatikPage() {
const [lesson, setLesson] = useState<Lesson | null>(null);
const [drill, setDrill] = useState(0);
const p = useProgress();
if (drill > 0) return <Drill key={drill} onBack={() => setDrill(0)} onAgain={() => setDrill((d) => d + 1)} />;
if (lesson) return <LessonView key={lesson.id} lesson={lesson} onBack={() => setLesson(null)} />;
return (
<div>
<h1>🧩 Grammatik</h1>
<p className="sub">
{lessons.length} B1-Themen mit {allGrammarExercises.length} Übungen – auf Arabisch erklärt. <Ar>مواضيع B1 مشروحة بالعربية مع تمارين كثيرة.</Ar>
</p>
<button
className="tile"
style={{ background: "linear-gradient(135deg, var(--purple), var(--blue))", color: "#fff", marginBottom: 12 }}
onClick={() => setDrill(1)}
>
<div className="row">
<span className="emoji">🎲</span>
<div style={{ flex: 1 }}>
<div className="t" style={{ marginTop: 0 }}>
Zufalls-Drill: 20 gemischte Fragen
</div>
<div className="s" style={{ color: "#fff", opacity: 0.9 }}>
Aus allen Themen – jedes Mal anders! • تمرين عشوائي من كل المواضيع
</div>
</div>
</div>
</button>
<div className="grid grid-2">
{lessons.map((l) => {
const score = p.done[l.id];
return (
<button key={l.id} className="tile" onClick={() => setLesson(l)}>
<div className="row" style={{ alignItems: "flex-start" }}>
<span className="emoji">{l.emoji}</span>
<span className="spacer" />
{score !== undefined && <span className={`pill ${score >= 60 ? "green" : "yellow"}`}>{score} %</span>}
</div>
<div className="t">{l.title}</div>
<div className="s ar" style={{ textAlign: "left" }}>
{l.titleAr}
</div>
</button>
);
})}
</div>
</div>
);
}
function LessonView({ lesson, onBack }: { lesson: Lesson; onBack: () => void }) {
const [round, setRound] = useState(0);
const [results, setResults] = useState<(boolean | null)[]>(() => lesson.exercises.map(() => null));
const [awarded, setAwarded] = useState<{ c: number; t: number; xp: number } | null>(null);
const onAnswer = (i: number, ok: boolean) => {
const next = results.map((r, j) => (j === i ? ok : r));
setResults(next);
if (next.every((r) => r !== null) && !awarded) {
const c = next.filter(Boolean).length;
const xp = 5 + c * 2;
recordResult(lesson.id, "grammatik", (c / next.length) * 100, xp);
setAwarded({ c, t: next.length, xp });
}
};
return (
<div>
<button className="btn secondary small" style={{ marginTop: 16 }} onClick={onBack}>
← Zurück
</button>
<h1 style={{ fontSize: 24 }}>
{lesson.emoji} {lesson.title}
</h1>
<div className="ar muted">{lesson.titleAr}</div>
<div className="card" style={{ marginTop: 12, background: "var(--purple-soft)", borderColor: "var(--purple)" }}>
<h3>📚 الشرح</h3>
{lesson.explainAr.map((t, i) => (
<p key={i} className="ar" style={{ margin: "4px 0" }}>
{t}
</p>
))}
</div>
<h2>Regeln • القواعد</h2>
<div className="card">
{lesson.rules.map((r, i) => (
<div key={i} style={{ padding: "8px 0", borderBottom: i < lesson.rules.length - 1 ? "1px dashed var(--line)" : "none" }}>
<div style={{ fontWeight: 800 }}>{r.de}</div>
<div className="ar small muted">{r.ar}</div>
</div>
))}
</div>
<h2>Beispiele • أمثلة</h2>
{lesson.examples.map((e, i) => (
<div key={i} className="card row" style={{ flexWrap: "nowrap" }}>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 700 }}>{e.de}</div>
<Ar block>
<span className="small muted">{e.ar}</span>
</Ar>
</div>
<SpeakButton text={e.de} />
</div>
))}
<h2>Übungen • تمارين</h2>
<div key={round}>
{lesson.exercises.map((ex, i) => (
<div key={i} className="card" style={{ marginTop: 12 }}>
<div className="row" style={{ marginBottom: 6 }}>
<span className="pill">{i + 1}</span>
<span className="small muted">{ex.kind === "order" ? "Bring die Wörter in die richtige Reihenfolge • رتّب الكلمات" : "Wähle die richtige Antwort • اختر الإجابة الصحيحة"}</span>
</div>
{ex.kind === "mc" ? <McEx ex={ex} onAnswer={(ok) => onAnswer(i, ok)} /> : <OrderEx ex={ex} onAnswer={(ok) => onAnswer(i, ok)} />}
</div>
))}
</div>
{awarded && (
<ResultCard
correct={awarded.c}
total={awarded.t}
xp={awarded.xp}
onRetry={() => {
setResults(lesson.exercises.map(() => null));
setAwarded(null);
setRound((r) => r + 1);
}}
/>
)}
</div>
);
}
function Drill({ onBack, onAgain }: { onBack: () => void; onAgain: () => void }) {
const items = useMemo(() => [...allGrammarExercises].sort(() => Math.random() - 0.5).slice(0, 20), []);
const [results, setResults] = useState<(boolean | null)[]>(() => items.map(() => null));
const [done, setDone] = useState<{ c: number; xp: number } | null>(null);
const answered = results.filter((r) => r !== null).length;
const onAnswer = (i: number, ok: boolean) => {
const next = results.map((r, j) => (j === i ? ok : r));
setResults(next);
if (next.every((r) => r !== null) && !done) {
const c = next.filter(Boolean).length;
const xp = 10 + c * 2;
recordResult("grammatik-drill", "grammatik", (c / next.length) * 100, xp);
setDone({ c, xp });
}
};
return (
<div>
<button className="btn secondary small" style={{ marginTop: 16 }} onClick={onBack}>
← Zurück
</button>
<h1 style={{ fontSize: 24 }}>🎲 Zufalls-Drill</h1>
<div className="row">
<span className="pill">
{answered} / {items.length}
</span>
<span className="pill green">✅ {results.filter((r) => r === true).length}</span>
</div>
<div className="bar" style={{ marginTop: 8 }}>
<div style={{ width: `${(answered / items.length) * 100}%` }} />
</div>
{items.map((it, i) => (
<div key={i} className="card" style={{ marginTop: 12 }}>
<div className="row" style={{ marginBottom: 6 }}>
<span className="pill">{i + 1}</span>
<span className="small muted">{it.lessonTitle}</span>
</div>
{it.ex.kind === "mc" ? <McEx ex={it.ex} onAnswer={(ok) => onAnswer(i, ok)} /> : <OrderEx ex={it.ex} onAnswer={(ok) => onAnswer(i, ok)} />}
</div>
))}
{done && <ResultCard correct={done.c} total={items.length} xp={done.xp} onRetry={onAgain} />}
</div>
);
}
function McEx({ ex, onAnswer }: { ex: Extract<GrammarEx, { kind: "mc" }>; onAnswer: (ok: boolean) => void }) {
const [chosen, setChosen] = useState<number | null>(null);
return (
<div>
<div style={{ fontWeight: 800, fontSize: 17 }}>{ex.q}</div>
{ex.ar && (
<Ar block>
<span className="small muted">{ex.ar}</span>
</Ar>
)}
<div className="grid grid-2">
{ex.options.map((o, i) => {
let cls = "option";
if (chosen !== null && i === ex.answer) cls += " correct";
else if (chosen === i) cls += " wrong";
return (
<button
key={i}
className={cls}
disabled={chosen !== null}
onClick={() => {
setChosen(i);
const ok = i === ex.answer;
if (ok) sfx.correct();
else sfx.wrong();
onAnswer(ok);
}}
>
{o}
</button>
);
})}
</div>
{chosen !== null && (
<div className={`feedback ${chosen === ex.answer ? "ok" : "no"}`}>
{chosen === ex.answer ? "Richtig! 🎉" : `Richtig wäre: ${ex.options[ex.answer]}`}
{ex.why && <span style={{ fontWeight: 600 }}> – {ex.why}</span>}
</div>
)}
</div>
);
}
function OrderEx({ ex, onAnswer }: { ex: Extract<GrammarEx, { kind: "order" }>; onAnswer: (ok: boolean) => void }) {
const shuffled = useMemo(() => {
const idx = ex.words.map((_, i) => i);
for (let k = 0; k < 20; k++) {
idx.sort(() => Math.random() - 0.5);
if (idx.some((v, i) => v !== i)) break;
}
return idx;
}, [ex]);
const [picked, setPicked] = useState<number[]>([]);
const [checked, setChecked] = useState<boolean | null>(null);
const target = ex.words.join(" ");
const current = picked.map((i) => ex.words[i]).join(" ");
const check = () => {
const ok = current === target;
setChecked(ok);
if (ok) sfx.correct();
else sfx.wrong();
onAnswer(ok);
};
return (
<div>
<Ar block>
<span className="small">{ex.ar}</span>
</Ar>
<div className="drop-zone" style={{ marginTop: 8, borderColor: checked === null ? undefined : checked ? "var(--green)" : "var(--red)" }}>
{picked.length === 0 && <span className="muted small">Tippe die Wörter an …</span>}
{picked.map((wi, k) => (
<button key={k} className="word-chip" disabled={checked !== null} onClick={() => setPicked((p) => p.filter((_, j) => j !== k))}>
{ex.words[wi]}
</button>
))}
</div>
<div className="row" style={{ marginTop: 10 }}>
{shuffled
.filter((i) => !picked.includes(i))
.map((i) => (
<button key={i} className="word-chip" disabled={checked !== null} onClick={() => setPicked((p) => [...p, i])}>
{ex.words[i]}
</button>
))}
</div>
{checked === null ? (
<button className="btn green small" style={{ marginTop: 10 }} disabled={picked.length !== ex.words.length} onClick={check}>
Prüfen ✔
</button>
) : (
<div className={`feedback ${checked ? "ok" : "no"}`}>
{checked ? "Perfekt! 🎉" : "Richtig wäre:"} {!checked && <b>{target}</b>}
<span style={{ marginLeft: 8 }}>
<SpeakButton text={target} />
</span>
</div>
)}
</div>
);
}