Files
chadiapp/app/lesen/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

143 lines
4.9 KiB
TypeScript
Raw 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 { useState } from "react";
import { leseItems, leseTeile, type LeseItem } from "@/data/lesen";
import Quiz from "@/components/Quiz";
import ResultCard from "@/components/ResultCard";
import Ar from "@/components/Ar";
import SpeakButton from "@/components/SpeakButton";
import { recordResult, useProgress } from "@/lib/progress";
export default function LesenPage() {
const [teil, setTeil] = useState<number>(1);
const [item, setItem] = useState<LeseItem | null>(null);
const p = useProgress();
const info = leseTeile.find((t) => t.teil === teil)!;
if (item) return <Reader key={item.id} item={item} onBack={() => setItem(null)} />;
return (
<div>
<h1>📖 Lesen</h1>
<p className="sub">
Texte wie in der echten Prüfung – mit Wortliste und Übersetzung. <Ar>نصوص مثل الامتحان الحقيقي – مع قائمة كلمات وترجمة.</Ar>
</p>
<div className="tabs">
{leseTeile.map((t) => (
<button key={t.teil} className={teil === t.teil ? "active" : ""} onClick={() => setTeil(t.teil)}>
Teil {t.teil}
</button>
))}
</div>
<div className="card" style={{ background: "var(--green-soft)", borderColor: "var(--green)" }}>
<h3>{info.de}</h3>
<div className="ar">{info.ar}</div>
<div className="small" style={{ marginTop: 4 }}>
💡 {info.hint}
</div>
</div>
<div className="grid" style={{ marginTop: 12 }}>
{leseItems
.filter((l) => l.teil === teil)
.map((l) => {
const score = p.done[l.id];
return (
<button key={l.id} className="tile" onClick={() => setItem(l)}>
<div className="row">
<span style={{ fontSize: 28 }}>📰</span>
<div style={{ flex: 1 }}>
<div className="t" style={{ marginTop: 0 }}>
{l.title}
</div>
<div className="s">
{l.kind} • <span className="ar">{l.titleAr}</span>
</div>
</div>
{score !== undefined ? <span className={`pill ${score >= 60 ? "green" : "yellow"}`}>{score} %</span> : <span className="pill">{l.questions.length} Fragen</span>}
</div>
</button>
);
})}
</div>
</div>
);
}
function Reader({ item, onBack }: { item: LeseItem; onBack: () => void }) {
const [result, setResult] = useState<{ c: number; t: number; xp: number } | null>(null);
const [round, setRound] = useState(0);
const [showTr, setShowTr] = useState(false);
const [open, setOpen] = useState<number | null>(null);
return (
<div>
<button className="btn secondary small" style={{ marginTop: 16 }} onClick={onBack}>
← Zurück
</button>
<h1 style={{ fontSize: 24 }}>{item.title}</h1>
<div className="ar muted">{item.titleAr}</div>
<div className="card" style={{ marginTop: 12, background: "var(--yellow-soft)", borderColor: "var(--yellow)" }}>
<b>Aufgabe:</b> {item.task}
<Ar block>{item.taskAr}</Ar>
</div>
<div className="card" style={{ marginTop: 12 }}>
<div className="row" style={{ marginBottom: 8 }}>
<span className="pill green">{item.kind}</span>
<span className="spacer" />
<SpeakButton text={item.text} label="Vorlesen" />
</div>
<div className="reading">{item.text}</div>
</div>
<h2>Wortschatz-Hilfe • مساعدة المفردات</h2>
<div className="row">
{item.glossary.map((g, i) => (
<button key={i} className="word-chip" onClick={() => setOpen(open === i ? null : i)}>
{g.de}
{open === i && (
<span className="ar" style={{ display: "block", fontWeight: 600 }}>
{g.ar}
</span>
)}
</button>
))}
</div>
<h2>Fragen • الأسئلة</h2>
<Quiz
key={round}
questions={item.questions}
onFinish={(c, t) => {
const xp = 5 + c * 3;
recordResult(item.id, "lesen", (c / t) * 100, xp);
setResult({ c, t, xp });
}}
/>
{result && (
<ResultCard
correct={result.c}
total={result.t}
xp={result.xp}
onRetry={() => {
setResult(null);
setRound((r) => r + 1);
}}
/>
)}
<div style={{ marginTop: 16 }}>
<button className="btn secondary block" onClick={() => setShowTr((s) => !s)}>
🌍 {showTr ? "Übersetzung ausblenden" : "Arabische Übersetzung zeigen"} • الترجمة
</button>
{showTr && (
<div className="card ar fade-in" style={{ marginTop: 10 }}>
{item.translationAr}
</div>
)}
</div>
</div>
);
}