feat: Seiten für Übersicht, Kalender und Statistik

Der Kalender ist als Tabelle ausgezeichnet — ein Kalender ist eine Tabelle,
und mit Screenreader wird daraus dann „Woche 3, Donnerstag, 24." statt einer
ununterscheidbaren Kachelwüste.
This commit is contained in:
Florian Wilde
2026-09-01 19:54:16 +02:00
parent 0e51df7bad
commit 8c872b240a
5 changed files with 771 additions and 55 deletions
+138
View File
@@ -0,0 +1,138 @@
import Link from "next/link";
import { clsx } from "clsx";
import { episodeCode } from "@/lib/labels";
import type { UpcomingEpisode } from "@/lib/stats";
/**
* Monatsraster mit den Ausstrahlungsterminen.
*
* Bewusst als Tabelle ausgezeichnet: ein Kalender *ist* eine Tabelle, und mit
* Screenreader wird daraus dann „Woche 3, Donnerstag, 14." statt einer
* ununterscheidbaren Kachelwüste.
*/
const WEEKDAYS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
function startOfGrid(month: Date): Date {
const first = new Date(month.getFullYear(), month.getMonth(), 1);
// Montag als Wochenanfang: Sonntag (0) wird zu 6.
const weekday = (first.getDay() + 6) % 7;
return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);
}
function isSameDay(a: Date, b: Date): boolean {
return (
a.getFullYear() === b.getFullYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
);
}
export function CalendarMonth({
month,
episodes,
}: {
month: Date;
episodes: UpcomingEpisode[];
}) {
const today = new Date();
const start = startOfGrid(month);
// Sechs Wochen zeigen immer den ganzen Monat, egal auf welchen Tag er fällt.
const days = Array.from({ length: 42 }, (_, index) => {
const date = new Date(start);
date.setDate(start.getDate() + index);
return date;
});
const byDay = new Map<string, UpcomingEpisode[]>();
for (const episode of episodes) {
const key = episode.airDate.toDateString();
const list = byDay.get(key);
if (list) list.push(episode);
else byDay.set(key, [episode]);
}
const weeks = Array.from({ length: 6 }, (_, index) => days.slice(index * 7, index * 7 + 7));
return (
<table className="w-full table-fixed border-collapse">
<caption className="sr-only">
Ausstrahlungstermine im {month.toLocaleDateString("de-DE", { month: "long", year: "numeric" })}
</caption>
<thead>
<tr>
{WEEKDAYS.map((day) => (
<th
key={day}
scope="col"
className="pb-2 text-xs font-semibold uppercase tracking-wide text-[var(--fl-faint)]"
>
{day}
</th>
))}
</tr>
</thead>
<tbody>
{weeks.map((week, weekIndex) => (
<tr key={weekIndex}>
{week.map((date) => {
const inMonth = date.getMonth() === month.getMonth();
const isToday = isSameDay(date, today);
const list = byDay.get(date.toDateString()) ?? [];
return (
<td
key={date.toISOString()}
className={clsx(
"h-24 border border-[var(--fl-border)] p-1 align-top sm:h-28",
!inMonth && "opacity-40",
)}
style={
list.length > 0
? { backgroundColor: "color-mix(in oklab, var(--fl-magenta) 7%, transparent)" }
: undefined
}
>
<span
className={clsx(
"mb-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-xs tabular-nums",
isToday
? "font-semibold text-[var(--fl-on-accent)]"
: "text-[var(--fl-faint)]",
)}
style={isToday ? { backgroundImage: "var(--fl-gradient)" } : undefined}
>
{date.getDate()}
</span>
<ul className="space-y-0.5">
{list.slice(0, 3).map((episode) => (
<li key={episode.episodeId}>
<Link
href={`/titel/${episode.titleId}`}
title={`${episode.title} — ${episodeCode(episode.seasonNumber, episode.episodeNumber)} ${episode.name}`}
className="block truncate rounded px-1 py-0.5 text-[0.7rem] leading-tight text-[var(--fl-text)] transition-colors hover:bg-[var(--fl-surface-2)]"
>
<span className="font-mono text-[var(--fl-accent)]">
{episodeCode(episode.seasonNumber, episode.episodeNumber)}
</span>{" "}
{episode.title}
</Link>
</li>
))}
{list.length > 3 && (
<li className="px-1 text-[0.7rem] text-[var(--fl-faint)]">
+ {list.length - 3} weitere
</li>
)}
</ul>
</td>
);
})}
</tr>
))}
</tbody>
</table>
);
}
+38
View File
@@ -0,0 +1,38 @@
"use client";
import { useTransition } from "react";
import { useRouter } from "next/navigation";
import { undoAction, watchNextAction } from "@/app/actions/library";
import { useToasts } from "@/components/Toasts";
/**
* „+1 Episode" für die Übersicht — derselbe Griff wie auf der Detailseite,
* nur ohne Kontext drumherum.
*/
export function QuickWatch({ entryId }: { entryId: string }) {
const router = useRouter();
const { report } = useToasts();
const [pending, startTransition] = useTransition();
async function undo(watchIds: string[]) {
await undoAction(entryId, watchIds);
router.refresh();
}
return (
<button
type="button"
disabled={pending}
onClick={() =>
startTransition(async () => {
const result = await watchNextAction(entryId);
report(result, (ids) => undo(ids));
router.refresh();
})
}
className="fl-btn fl-btn-ghost px-3 py-1.5 text-sm"
>
+1 Episode
</button>
);
}