sanamare/src/app/(shop)/konto/kurse/[slug]/page.tsx
Maaxxs 4eee36329a Kursansicht: Player über die volle Breite, Titel und Knöpfe darunter, Einheiten als klebende Seitenspalte
- Seite war im Flex-Body auf Inhaltsbreite geschrumpft (Player nur ~160 px); jetzt bis 1400 px breit
- Desktop: Player 16:9 über die Hauptspalte, Hochformat-Videos 9:16 mittig und höchstens 80 % der Bildschirmhöhe
- Seitenspalte (360 px) klebt beim Scrollen und scrollt bei vielen Einheiten selbst; unter 1024 px untereinander
- Wasserzeichen skaliert mit der Playergröße

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 22:35:31 +02:00

70 lines
3.6 KiB
TypeScript

import Link from "next/link";
import { notFound, redirect } from "next/navigation";
import { db } from "@/lib/db";
import { getCurrentUser } from "@/lib/auth";
import { getCourseOutline, hasCourseAccess, isCourse } from "@/lib/courses";
import { playbackUrl } from "@/lib/video";
import { Alert } from "@/components/shop/Blocks";
import { CourseOutline } from "@/components/shop/CourseOutline";
import { LessonPlayer } from "@/components/shop/LessonPlayer";
export const metadata = { title: "Kurs", robots: { index: false } };
export default async function CoursePage({ params, searchParams }: { params: Promise<{ slug: string }>; searchParams: Promise<{ einheit?: string }> }) {
const [{ slug }, { einheit }, user] = await Promise.all([params, searchParams, getCurrentUser()]);
if (!user) redirect(`/konto/anmelden?weiter=/konto/kurse/${slug}`);
const product = await db.product.findUnique({ where: { slug } });
if (!product || !isCourse(product)) notFound();
if (!(await hasCourseAccess(user.id, product.id))) redirect(`/produkt/${slug}`);
const [outline, progress] = await Promise.all([
getCourseOutline(product.id),
db.lessonProgress.findMany({ where: { userId: user.id, lesson: { chapter: { productId: product.id } } } }),
]);
// Abspielbar ist eine Einheit, sobald ein fertig umgewandeltes Video da ist
const lessons = outline.flatMap((c) => c.lessons).filter((l) => l.videoId);
const byLesson = new Map(progress.map((p) => [p.lessonId, p]));
const done = new Set(progress.filter((p) => p.completed).map((p) => p.lessonId));
// Gewählte Einheit, sonst die zuletzt angefangene, sonst die erste noch offene
const lastStarted = [...progress].filter((p) => !p.completed && p.position > 0).sort((a, b) => +b.updatedAt - +a.updatedAt)[0];
const lesson = lessons.find((l) => l.id === einheit) ?? lessons.find((l) => l.id === lastStarted?.lessonId) ?? lessons.find((l) => !done.has(l.id)) ?? lessons[0];
const index = lesson ? lessons.indexOf(lesson) : -1;
const next = index >= 0 ? lessons[index + 1] : undefined;
return (
<main className="sm-container sm-page sm-lesson">
<nav aria-label="Du bist hier">
<ol className="sm-crumbs">
<li><Link href="/konto">Mein Konto</Link></li>
<li><Link href="/konto/kurse">Meine Kurse</Link></li>
<li aria-current="page">{product.name}</li>
</ol>
</nav>
<div className="sm-lesson__grid">
<div>
{!lesson ? (
<Alert title="Hier kommen bald die Videos.">Dieser Kurs hat noch keine fertigen Einheiten. Schau bald wieder vorbei.</Alert>
) : (
<>
<LessonPlayer
lessonId={lesson.id}
src={await playbackUrl(lesson.videoId, user.id)}
title={lesson.title}
email={user.email}
startAt={byLesson.get(lesson.id)?.completed ? 0 : (byLesson.get(lesson.id)?.position ?? 0)}
done={done.has(lesson.id)}
nextHref={next ? `/konto/kurse/${slug}?einheit=${next.id}` : null}
/>
{lesson.description && <p className="body" style={{ whiteSpace: "pre-line", color: "var(--ink-muted)" }}>{lesson.description}</p>}
</>
)}
</div>
<aside className="sm-lesson__side">
<span className="eyebrow">{product.name}</span>
<p className="caption sm-muted" style={{ margin: "var(--space-1) 0 var(--space-4)" }}>{done.size} von {lessons.length} Einheiten erledigt</p>
<CourseOutline chapters={outline} current={lesson?.id} done={done} hrefFor={(l) => `/konto/kurse/${slug}?einheit=${l.id}`} />
</aside>
</div>
</main>
);
}