Files
chadiapp/app/einstellungen/page.tsx
T
X4Lo 1f1d28a34d 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.
2026-11-05 19:11:46 +00:00

180 lines
9.0 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 { useEffect, useState } from "react";
import { resetProgress, updateSettings, useProgress } from "@/lib/progress";
import { downloadCalendarReminder, notificationsSupported, registerServiceWorker, requestNotificationPermission, showReminder } from "@/lib/reminder";
import { germanVoices, speak } from "@/lib/speech";
import Ar from "@/components/Ar";
export default function EinstellungenPage() {
const p = useProgress();
const [perm, setPerm] = useState<string>("…");
const [msg, setMsg] = useState("");
const [ai, setAi] = useState<boolean | null>(null);
const [voices, setVoices] = useState<string[]>([]);
useEffect(() => {
setPerm(notificationsSupported() ? Notification.permission : "unsupported");
fetch("/api/coach")
.then((r) => r.json())
.then((d: { enabled: boolean }) => setAi(d.enabled))
.catch(() => setAi(false));
const load = () => setVoices(germanVoices().map((v) => `${v.name} (${v.lang})`));
load();
const t = setTimeout(load, 800);
return () => clearTimeout(t);
}, []);
const enableReminders = async (on: boolean) => {
if (!on) {
updateSettings({ reminder: { ...p.reminder, enabled: false } });
return;
}
const r = await requestNotificationPermission();
setPerm(r);
if (r === "granted") {
await registerServiceWorker();
updateSettings({ reminder: { ...p.reminder, enabled: true } });
setMsg("✅ Erinnerungen sind aktiv! • التذكيرات مفعّلة!");
} else if (r === "unsupported") {
setMsg("Dieser Browser unterstützt keine Benachrichtigungen. Nutze die Kalender-Erinnerung unten. • استخدم تذكير التقويم.");
} else {
setMsg("Benachrichtigungen wurden blockiert. Erlaube sie in den Browser-Einstellungen. • اسمح بالإشعارات في إعدادات المتصفح.");
}
};
return (
<div>
<h1>⚙️ Einstellungen</h1>
<p className="sub">
Personalisiere deinen Lernplan. <Ar>خصّص خطة تعلّمك.</Ar>
</p>
<div className="card">
<h3>👤 Profil</h3>
<label className="small muted">Dein Name • اسمك</label>
<input value={p.name} onChange={(e) => updateSettings({ name: e.target.value })} placeholder="z. B. Chadi" />
<label className="small muted" style={{ display: "block", marginTop: 10 }}>
Prüfungsdatum • تاريخ الامتحان
</label>
<input type="date" value={p.examDate ?? ""} onChange={(e) => updateSettings({ examDate: e.target.value || null })} />
<label className="small muted" style={{ display: "block", marginTop: 10 }}>
Tagesziel • هدف اليوم
</label>
<div className="grid grid-3">
{[
{ xp: 30, de: "🙂 Locker", ar: "خفيف" },
{ xp: 50, de: "💪 Normal", ar: "عادي" },
{ xp: 100, de: "🔥 Intensiv", ar: "مكثّف" },
].map((g) => (
<button key={g.xp} className={`option ${p.dailyGoal === g.xp ? "selected" : ""}`} style={{ flexDirection: "column", alignItems: "center" }} onClick={() => updateSettings({ dailyGoal: g.xp })}>
<span>{g.de}</span>
<span className="small muted">
{g.xp} XP • {g.ar}
</span>
</button>
))}
</div>
</div>
<div className="card">
<h3>🔔 Tägliche Erinnerung • التذكير اليومي</h3>
<label className="row" style={{ cursor: "pointer" }}>
<input type="checkbox" checked={p.reminder.enabled} onChange={(e) => void enableReminders(e.target.checked)} style={{ width: 22, height: 22 }} />
<b>Jeden Tag erinnern</b>
</label>
<label className="small muted" style={{ display: "block", marginTop: 10 }}>
Uhrzeit • الوقت
</label>
<input type="time" value={p.reminder.time} onChange={(e) => updateSettings({ reminder: { ...p.reminder, time: e.target.value } })} />
<div className="small muted" style={{ marginTop: 6 }}>
Status: {perm === "granted" ? "✅ erlaubt" : perm === "denied" ? "🚫 blockiert" : perm === "unsupported" ? "❌ nicht unterstützt" : "❔ noch nicht gefragt"}
</div>
{msg && <div className="feedback ok">{msg}</div>}
<div className="row" style={{ marginTop: 12 }}>
<button className="btn secondary small" disabled={perm !== "granted"} onClick={() => void showReminder(true)}>
🔔 Test-Benachrichtigung
</button>
<button className="btn blue small" onClick={() => downloadCalendarReminder(p.reminder.time)}>
📅 Als Kalender-Erinnerung speichern
</button>
</div>
<details style={{ marginTop: 12 }}>
<summary>Wie funktionieren die Erinnerungen? • كيف تعمل التذكيرات؟</summary>
<ul className="small" style={{ paddingLeft: 18, lineHeight: 1.7 }}>
<li>Wenn du heute noch nicht gelernt hast, bekommst du zur gewählten Uhrzeit eine Benachrichtigung.</li>
<li>
Am Handy: Installiere die App (Browser-Menü → „Zum Startbildschirm hinzufügen“). Auf Android/Chrome kommen die Erinnerungen dann auch bei geschlossener App (der Browser
entscheidet über den genauen Zeitpunkt).
</li>
<li>Auf iPhone (ab iOS 16.4) gehen Benachrichtigungen nur bei installierter App, solange sie im Hintergrund läuft.</li>
<li>
<b>Am zuverlässigsten:</b> „Als Kalender-Erinnerung speichern“ – dein Handy-Kalender erinnert dich dann jeden Tag, egal welcher Browser.
</li>
</ul>
<Ar block>
<span className="small">
إذا لم تدرس اليوم ستصلك إشعار في الوقت المحدد. على الهاتف: ثبّت التطبيق على الشاشة الرئيسية. الطريقة الأكثر موثوقية هي حفظ التذكير في تقويم الهاتف – سيذكّرك كل يوم.
</span>
</Ar>
</details>
</div>
<div className="card">
<h3>🎛️ Lernen</h3>
<label className="row" style={{ cursor: "pointer" }}>
<input type="checkbox" checked={p.showArabic} onChange={(e) => updateSettings({ showArabic: e.target.checked })} style={{ width: 22, height: 22 }} />
<span>
<b>Arabische Übersetzungen anzeigen</b>
<br />
<span className="small muted">Aus = Challenge-Modus: Übersetzung erst nach Antippen • إخفاء الترجمة لتحدٍّ أكبر</span>
</span>
</label>
<label className="row" style={{ cursor: "pointer", marginTop: 10 }}>
<input type="checkbox" checked={p.sound} onChange={(e) => updateSettings({ sound: e.target.checked })} style={{ width: 22, height: 22 }} />
<b>Soundeffekte 🔊</b>
</label>
<div style={{ marginTop: 12 }}>
<b>Deutsche Stimmen auf diesem Gerät:</b>{" "}
<button className="btn secondary small" onClick={() => speak("Hallo! Ich bin deine Stimme für die Hörübungen. Viel Erfolg bei der Prüfung!")}>
🔊 Testen
</button>
<div className="small muted" style={{ marginTop: 4 }}>
{voices.length ? voices.join(" • ") : "Keine deutsche Stimme gefunden – installiere eine deutsche Sprachausgabe im System (Windows: Einstellungen → Zeit & Sprache → Sprache)."}
</div>
</div>
</div>
<div className="card">
<h3>🤖 KI-Gesprächspartner</h3>
{ai === null ? (
<p className="muted">Prüfe …</p>
) : ai ? (
<div className="feedback ok">✅ Aktiv – im Sprechen-Teil führt die KI echte, freie Gespräche und korrigiert deine Texte im Schreiben-Teil.</div>
) : (
<div className="small">
<p style={{ marginTop: 0 }}>
Nicht aktiv. Die App funktioniert trotzdem komplett mit dem eingebauten Trainer. Für freie KI-Gespräche und KI-Textkorrektur: Lege im Projektordner eine Datei <code>.env.local</code>{" "}
mit <code>ANTHROPIC_API_KEY=…</code> an und starte die App neu.
</p>
<Ar block>غير مفعّل. التطبيق يعمل كاملاً بدونه. لتفعيل المحادثة الحرة بالذكاء الاصطناعي أضف مفتاح API في ملف ‎.env.local ثم أعد تشغيل التطبيق.</Ar>
</div>
)}
</div>
<div className="card" style={{ borderColor: "var(--red)" }}>
<h3>🗑️ Fortschritt zurücksetzen</h3>
<p className="small muted">Löscht XP, Serie, Karteikarten und Ergebnisse auf diesem Gerät.</p>
<button
className="btn small"
onClick={() => {
if (window.confirm("Wirklich den gesamten Fortschritt löschen? • هل تريد حذف كل التقدّم؟")) resetProgress();
}}
>
Zurücksetzen
</button>
</div>
</div>
);
}