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.
196 lines
6.9 KiB
TypeScript
196 lines
6.9 KiB
TypeScript
"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>
|
|
);
|
|
}
|