Add B1 Meister: OeSD B1 exam trainer (German-Arabic)

Next.js app with Hoeren, Lesen, Schreiben, Sprechen, Grammatik and Wortschatz sections, flashcards with spaced repetition, speaking chat, XP/streaks/badges, daily reminders (PWA) and Docker Compose setup for Coolify.
This commit is contained in:
X4Lo committed 2026-11-05 19:11:46 +00:00
commit 1f1d28a34d
42 files changed
+8879

No files matched your search

+195
View File
@@ -0,0 +1,195 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { badgeInfo, levelInfo, onAppEvent, useProgress } from "@/lib/progress";
import { registerServiceWorker, startInAppReminderLoop } from "@/lib/reminder";
import { sfx } from "@/lib/sfx";
import { hasGermanVoice, TTS_MISSING_EVENT, ttsSupported, voicesReady } from "@/lib/speech";
const nav = [
{ href: "/", ico: "🏠", de: "Start" },
{ href: "/hoeren", ico: "🎧", de: "Hören" },
{ href: "/lesen", ico: "📖", de: "Lesen" },
{ href: "/schreiben", ico: "✍️", de: "Schreiben" },
{ href: "/sprechen", ico: "🗣️", de: "Sprechen" },
{ href: "/grammatik", ico: "🧩", de: "Grammatik" },
{ href: "/wortschatz", ico: "🃏", de: "Wörter" },
];
interface Toast {
id: number;
text: string;
}
let confettiTrigger: (() => void) | null = null;
export function fireConfetti() {
confettiTrigger?.();
}
export default function AppShell({ children }: { children: React.ReactNode }) {
const p = useProgress();
const path = usePathname();
const [toasts, setToasts] = useState<Toast[]>([]);
const [confetti, setConfetti] = useState(0);
const [noVoice, setNoVoice] = useState(false);
const li = levelInfo(p.xp);
useEffect(() => {
const show = () => setNoVoice(true);
window.addEventListener(TTS_MISSING_EVENT, show);
if (ttsSupported()) void voicesReady().then(() => !hasGermanVoice() && show());
return () => window.removeEventListener(TTS_MISSING_EVENT, show);
}, []);
useEffect(() => {
confettiTrigger = () => setConfetti((c) => c + 1);
let n = 0;
const push = (text: string) => {
const id = ++n + Date.now();
setToasts((t) => [...t, { id, text }]);
setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 2800);
};
const off = onAppEvent((e) => {
if (e.type === "xp") push(`+${e.amount} XP ⚡`);
if (e.type === "level") {
push(`🎉 Level ${e.level}: ${e.name}!`);
setConfetti((c) => c + 1);
sfx.win();
}
if (e.type === "goal") {
push("🏆 Tagesziel erreicht! أحسنت! حققت هدف اليوم");
setConfetti((c) => c + 1);
sfx.win();
}
if (e.type === "badge") {
const b = badgeInfo[e.id];
if (b) push(`${b.emoji} Neues Abzeichen: ${b.de}`);
}
});
void registerServiceWorker();
const stopLoop = startInAppReminderLoop();
return () => {
off();
stopLoop();
confettiTrigger = null;
};
}, []);
return (
<div className={p.showArabic ? "" : "hide-ar"}>
<header className="topbar">
<div className="topbar-inner">
<Link href="/" className="brand">
<img src="/icon.svg" alt="" />
<span>B1 Meister</span>
</Link>
<span className="chip fire" title="Lern-Serie (Tage)">
🔥 {p.streak}
</span>
<span className="chip xp" title={`Level ${li.level}: ${li.name}`}>
⚡ {p.xp}
</span>
<Link href="/einstellungen" className="chip" aria-label="Einstellungen">
⚙️
</Link>
</div>
</header>
<main className="shell">
{noVoice && (
<div className="card fade-in" style={{ marginTop: 14, background: "var(--yellow-soft)", borderColor: "var(--yellow)" }}>
<div className="row" style={{ alignItems: "flex-start", flexWrap: "nowrap" }}>
<div style={{ flex: 1 }}>
<b>🔇 Keine deutsche Stimme gefunden</b>
<div className="small" style={{ marginTop: 4 }}>
Dein Gerät hat nur englische Stimmen, darum kann die App die Hörtexte nicht auf Deutsch vorlesen. So behebst du das:
</div>
<ul className="small" style={{ margin: "6px 0 0", paddingLeft: 18, lineHeight: 1.7 }}>
<li>
<b>Windows:</b> Einstellungen → Zeit und Sprache → Sprache und Region → Sprache hinzufügen → <b>Deutsch (Österreich oder Deutschland)</b> mit
„Text-to-Speech“. Danach den Browser neu starten.
</li>
<li>
<b>Oder</b> die App in <b>Google Chrome</b> öffnen (hat „Google Deutsch“) oder in <b>Microsoft Edge</b> (hat Online-Stimmen wie „Katja“).
</li>
<li>
<b>Handy:</b> Einstellungen → Sprache → Sprachausgabe → Deutsch installieren.
</li>
</ul>
<div className="ar small" style={{ marginTop: 6 }}>
جهازك لا يحتوي على صوت ألماني، لذلك لا يمكن قراءة النصوص بالألمانية. ثبّت اللغة الألمانية مع خاصية تحويل النص إلى كلام في إعدادات Windows ثم أعد تشغيل المتصفح، أو افتح التطبيق في
Chrome أو Edge.
</div>
</div>
<button className="btn secondary small" onClick={() => setNoVoice(false)} aria-label="Schließen">
✕
</button>
</div>
</div>
)}
{children}
</main>
<nav className="bottomnav" aria-label="Hauptnavigation">
<div className="bottomnav-inner">
{nav.map((n) => {
const active = n.href === "/" ? path === "/" : path.startsWith(n.href);
return (
<Link key={n.href} href={n.href} className={`navlink ${active ? "active" : ""}`}>
<span className="ico">{n.ico}</span>
<span>{n.de}</span>
</Link>
);
})}
</div>
</nav>
<div className="toasts" aria-live="polite">
{toasts.map((t) => (
<div key={t.id} className="toast">
{t.text}
</div>
))}
</div>
{confetti > 0 && <Confetti key={confetti} />}
</div>
);
}
function Confetti() {
const [pieces] = useState(() =>
Array.from({ length: 70 }, (_, i) => ({
id: i,
left: Math.random() * 100,
delay: Math.random() * 0.6,
dur: 1.8 + Math.random() * 1.6,
color: ["#e63946", "#ffb703", "#2a9d8f", "#3a86ff", "#8338ec", "#fb8500"][i % 6],
rot: Math.random() * 360,
})),
);
const [show, setShow] = useState(true);
useEffect(() => {
const t = setTimeout(() => setShow(false), 3600);
return () => clearTimeout(t);
}, []);
if (!show) return null;
return (
<div className="confetti" aria-hidden>
{pieces.map((c) => (
<i
key={c.id}
style={{
left: `${c.left}%`,
background: c.color,
animationDuration: `${c.dur}s`,
animationDelay: `${c.delay}s`,
transform: `rotate(${c.rot}deg)`,
}}
/>
))}
</div>
);
}
+33
View File
@@ -0,0 +1,33 @@
"use client";
import { useState } from "react";
import { useProgress } from "@/lib/progress";
/** Arabische Übersetzung. Wenn „Arabisch ausblenden“ aktiv ist, erscheint sie erst nach Antippen. */
export default function Ar({ children, block = false, always = false }: { children: React.ReactNode; block?: boolean; always?: boolean }) {
const { showArabic } = useProgress();
const [revealed, setRevealed] = useState(false);
const Tag = block ? "div" : "span";
if (!showArabic && !always && !revealed) {
return (
<Tag>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
setRevealed(true);
}}
className="pill purple"
style={{ border: "none", cursor: "pointer" }}
>
👁 عربي
</button>
</Tag>
);
}
return (
<Tag className="ar" lang="ar" dir="rtl" style={block ? { display: "block" } : undefined}>
{children}
</Tag>
);
}
+93
View File
@@ -0,0 +1,93 @@
"use client";
import { useState } from "react";
import type { Question } from "@/data/types";
import { sfx } from "@/lib/sfx";
import Ar from "./Ar";
interface Props {
questions: Question[];
onFinish: (correct: number, total: number) => void;
/** Im Prüfungsmodus wird die Lösung erst am Ende gezeigt. */
examMode?: boolean;
}
const letters = "abcdefghij";
export default function Quiz({ questions, onFinish, examMode = false }: Props) {
const [answers, setAnswers] = useState<(number | null)[]>(() => questions.map(() => null));
const [submitted, setSubmitted] = useState(false);
const correctOf = (q: Question) => (q.kind === "tf" ? (q.answer ? 0 : 1) : q.answer);
const allAnswered = answers.every((a) => a !== null);
const reveal = (i: number) => (examMode ? submitted : answers[i] !== null);
const choose = (qi: number, oi: number) => {
if (answers[qi] !== null && !examMode) return;
if (submitted) return;
const next = [...answers];
next[qi] = oi;
setAnswers(next);
if (!examMode) {
if (oi === correctOf(questions[qi])) sfx.correct();
else sfx.wrong();
}
};
const finish = () => {
setSubmitted(true);
const correct = questions.reduce((n, q, i) => n + (answers[i] === correctOf(q) ? 1 : 0), 0);
onFinish(correct, questions.length);
};
return (
<div>
{questions.map((q, qi) => {
const options = q.kind === "tf" ? ["Richtig ✅", "Falsch ❌"] : q.options;
const chosen = answers[qi];
const right = correctOf(q);
const shown = reveal(qi);
return (
<div key={qi} className="card fade-in" style={{ marginTop: 12 }}>
<div className="row" style={{ alignItems: "flex-start" }}>
<span className="pill">{qi + 1}</span>
<div style={{ flex: 1 }}>
<div style={{ fontWeight: 800 }}>{q.q}</div>
<Ar block>
<span className="small muted">{q.qAr}</span>
</Ar>
</div>
</div>
<div className={q.kind === "mc" && q.options.every((o) => o.length <= 2) ? "grid grid-3" : ""}>
{options.map((o, oi) => {
let cls = "option";
if (shown && oi === right) cls += " correct";
else if (shown && chosen === oi && oi !== right) cls += " wrong";
else if (!shown && chosen === oi) cls += " selected";
return (
<button key={oi} type="button" className={cls} disabled={(!examMode && chosen !== null) || submitted} onClick={() => choose(qi, oi)}>
<span className="key">{q.kind === "tf" ? (oi === 0 ? "R" : "F") : letters[oi]}</span>
<span>{o}</span>
</button>
);
})}
</div>
{shown && chosen !== null && (
<div className={`feedback ${chosen === right ? "ok" : "no"}`}>
{chosen === right ? "Super! Richtig 🎉" : "Leider falsch."}
{q.why ? <span style={{ fontWeight: 600 }}> – {q.why}</span> : null}
</div>
)}
</div>
);
})}
{!submitted && (
<div style={{ marginTop: 16 }}>
<button type="button" className="btn green block" disabled={!allAnswered} onClick={finish}>
{allAnswered ? "Auswerten ✔" : `Noch ${answers.filter((a) => a === null).length} Fragen offen`}
</button>
</div>
)}
</div>
);
}
+44
View File
@@ -0,0 +1,44 @@
"use client";
import { useEffect } from "react";
import { fireConfetti } from "./AppShell";
import { sfx } from "@/lib/sfx";
export function scoreMessage(pct: number) {
if (pct === 100) return { emoji: "🏆", de: "Perfekt! Du bist bereit für die Prüfung!", ar: "ممتاز! أنت جاهز للامتحان!" };
if (pct >= 80) return { emoji: "🌟", de: "Sehr gut! Weiter so!", ar: "جيد جداً! استمر هكذا!" };
if (pct >= 60) return { emoji: "👍", de: "Bestanden! (60 % reichen in der Prüfung)", ar: "ناجح! (60% تكفي في الامتحان)" };
return { emoji: "💪", de: "Noch nicht ganz – versuch es noch einmal!", ar: "ليس بعد – حاول مرة أخرى!" };
}
export default function ResultCard({ correct, total, xp, onRetry, children }: { correct: number; total: number; xp: number; onRetry?: () => void; children?: React.ReactNode }) {
const pct = total ? Math.round((correct / total) * 100) : 0;
const m = scoreMessage(pct);
useEffect(() => {
if (pct >= 80) {
fireConfetti();
sfx.win();
}
}, [pct]);
return (
<div className="card fade-in" style={{ marginTop: 16, textAlign: "center", borderColor: pct >= 60 ? "var(--green)" : "var(--orange)" }}>
<div style={{ fontSize: 52 }}>{m.emoji}</div>
<div style={{ fontSize: 30, fontWeight: 900 }}>
{correct} / {total} <span className="muted" style={{ fontSize: 18 }}>({pct} %)</span>
</div>
<div style={{ fontWeight: 800, marginTop: 4 }}>{m.de}</div>
<div className="ar muted">{m.ar}</div>
<div className="pill purple" style={{ marginTop: 8 }}>
+{xp} XP
</div>
{children}
{onRetry && (
<div style={{ marginTop: 14 }}>
<button type="button" className="btn secondary" onClick={onRetry}>
🔁 Nochmal
</button>
</div>
)}
</div>
);
}
+27
View File
@@ -0,0 +1,27 @@
"use client";
import { speak, stopSpeaking } from "@/lib/speech";
import { useState } from "react";
export default function SpeakButton({ text, gender = "f", rate = 0.9, label }: { text: string; gender?: "f" | "m"; rate?: number; label?: string }) {
const [on, setOn] = useState(false);
return (
<button
type="button"
className="btn secondary small"
aria-label="Vorlesen"
onClick={(e) => {
e.stopPropagation();
if (on) {
stopSpeaking();
setOn(false);
return;
}
setOn(true);
speak(text, { gender, rate, onEnd: () => setOn(false) });
}}
>
{on ? "⏹" : "🔊"} {label}
</button>
);
}