Redesign season and episode pages, add list/card views

This commit is contained in:
X4Lo committed 2026-11-05 17:48:44 +00:00
1 parent d0cd1cd94b
commit be248d7513
6 files changed
+1376 -538

No files matched your search

@@ -1,9 +1,16 @@
import { useState } from "react";
import { Link } from "react-router-dom";
import { ChevronDown, ChevronUp, Play } from "lucide-react";
import { Check, ChevronDown, ChevronUp, Eye } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { EpisodeSeenEditDialog } from "@/components/dialogs/EpisodeSeenEditDialog";
import { EpisodeViewToggle } from "@/components/entries/SeasonEpisodes";
import {
isEpisodeWatched,
loadSeasonView,
saveSeasonView,
type EpisodeView,
} from "@/lib/episodes";
import { getYear, getTmdbPosterUrl } from "@/lib/media-utils";
import type { Season } from "@/types";
@@ -12,8 +19,18 @@ interface SeasonsContainerProps {
entryId: number;
}
// How many seasons show before "Show all", per view
const COLLAPSED = { list: 2, cards: 4 } as const;
export function SeasonsContainer({ seasons, entryId }: SeasonsContainerProps) {
const [expanded, setExpanded] = useState(false);
const [view, setView] = useState<EpisodeView>(loadSeasonView);
const [markingSeason, setMarkingSeason] = useState<Season | null>(null);
const changeView = (next: EpisodeView) => {
setView(next);
saveSeasonView(next);
};
// Sort: specials (season 0) at bottom, rest latest to oldest
const sorted = [...seasons].sort((a, b) => {
@@ -22,17 +39,42 @@ export function SeasonsContainer({ seasons, entryId }: SeasonsContainerProps) {
return b.season_number - a.season_number;
});
const display = expanded ? sorted : sorted.slice(0, 2);
const limit = COLLAPSED[view];
const display = expanded ? sorted : sorted.slice(0, limit);
const nextToMark = markingSeason ? nextUnwatched(markingSeason) : undefined;
return (
<div className="space-y-3">
<h3 className="text-lg font-semibold">Seasons</h3>
<div className="space-y-2">
{display.map((season) => (
<SeasonItem key={season.id} season={season} entryId={entryId} />
))}
<div className="flex items-center justify-between gap-3">
<h3 className="text-lg font-semibold">Seasons</h3>
<EpisodeViewToggle view={view} onChange={changeView} />
</div>
{sorted.length > 2 && (
{view === "cards" ? (
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-4">
{display.map((season) => (
<SeasonCard
key={season.id}
season={season}
entryId={entryId}
onMarkWatched={() => setMarkingSeason(season)}
/>
))}
</div>
) : (
<div className="space-y-2">
{display.map((season) => (
<SeasonRow
key={season.id}
season={season}
entryId={entryId}
onMarkWatched={() => setMarkingSeason(season)}
/>
))}
</div>
)}
{sorted.length > limit && (
<Button
variant="ghost"
size="sm"
@@ -51,87 +93,208 @@ export function SeasonsContainer({ seasons, entryId }: SeasonsContainerProps) {
)}
</Button>
)}
{/* Marks the season's next unwatched episode */}
{nextToMark && (
<EpisodeSeenEditDialog
open={!!markingSeason}
onOpenChange={(open) => {
if (!open) setMarkingSeason(null);
}}
mode="create"
episodeId={nextToMark.id}
entryId={entryId}
/>
)}
</div>
);
}
function SeasonItem({ season, entryId }: { season: Season; entryId: number }) {
const [dialogOpen, setDialogOpen] = useState(false);
const watchedCount =
season.episodes?.filter(
(ep) =>
ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0),
).length ?? 0;
const totalEpisodes = season.episode_count || season.episodes?.length || 0;
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
function seasonProgress(season: Season) {
const watched = season.episodes?.filter(isEpisodeWatched).length ?? 0;
const total = season.episode_count || season.episodes?.length || 0;
return {
watched,
total,
percent: total > 0 ? (watched / total) * 100 : 0,
};
}
const nextUnwatched = season.episodes
function nextUnwatched(season: Season) {
return season.episodes
?.slice()
.sort((a, b) => a.episode_number - b.episode_number)
.find(
(ep) =>
!ep.date_first_seen &&
(!ep.episodeSeens || ep.episodeSeens.length === 0),
);
.find((ep) => !isEpisodeWatched(ep));
}
function stop(ev: React.MouseEvent, fn: () => void) {
ev.preventDefault();
ev.stopPropagation();
fn();
}
function SeasonRow({
season,
entryId,
onMarkWatched,
}: {
season: Season;
entryId: number;
onMarkWatched: () => void;
}) {
const { watched, total, percent } = seasonProgress(season);
const canMark = !!nextUnwatched(season);
return (
<>
<Link
to={`/entry/${entryId}/season/${season.id}`}
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
>
{/* Poster thumbnail */}
<div className="h-16 w-11 shrink-0 overflow-hidden rounded bg-muted">
<img
src={getTmdbPosterUrl(season.poster_path, "w92")}
alt={season.name}
className="h-full w-full object-cover"
loading="lazy"
/>
</div>
{/* Info */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-medium text-sm truncate">{season.name}</span>
<span className="text-xs text-muted-foreground">
{getYear(season.air_date)}
</span>
</div>
<div className="flex items-center gap-2 mt-1">
<Progress value={progress} className="h-1.5 flex-1" />
<span className="text-xs text-muted-foreground shrink-0">
{watchedCount}/{totalEpisodes}
</span>
</div>
</div>
{/* Quick watch button - opens dialog */}
{nextUnwatched && (
<Button
size="icon"
variant="ghost"
className="h-8 w-8 shrink-0"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setDialogOpen(true);
}}
>
<Play className="h-4 w-4" />
</Button>
)}
</Link>
{nextUnwatched && dialogOpen && (
<EpisodeSeenEditDialog
open={dialogOpen}
onOpenChange={setDialogOpen}
mode="create"
episodeId={nextUnwatched.id}
entryId={entryId}
<Link
to={`/entry/${entryId}/season/${season.id}`}
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
>
<div className="h-16 w-11 shrink-0 overflow-hidden rounded bg-muted">
<img
src={getTmdbPosterUrl(season.poster_path, "w92")}
alt={season.name}
className="h-full w-full object-cover"
loading="lazy"
/>
</div>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="truncate text-sm font-medium">{season.name}</span>
<span className="text-xs text-muted-foreground">
{getYear(season.air_date)}
</span>
</div>
<div className="mt-1 flex items-center gap-2">
<Progress value={percent} className="h-1.5 flex-1" />
<span className="shrink-0 text-xs text-muted-foreground">
{watched}/{total}
</span>
</div>
</div>
{canMark && (
<Button
size="icon"
variant="ghost"
className="h-8 w-8 shrink-0"
aria-label="Mark next episode as watched"
title="Mark next episode as watched"
onClick={(e) => stop(e, onMarkWatched)}
>
<Eye className="h-4 w-4" />
</Button>
)}
</>
</Link>
);
}
function SeasonCard({
season,
entryId,
onMarkWatched,
}: {
season: Season;
entryId: number;
onMarkWatched: () => void;
}) {
const { watched, total, percent } = seasonProgress(season);
const canMark = !!nextUnwatched(season);
return (
<Link
to={`/entry/${entryId}/season/${season.id}`}
className="group flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card/50 transition-colors hover:bg-accent/40"
>
<div className="aspect-2/3 overflow-hidden bg-muted">
<img
src={getTmdbPosterUrl(season.poster_path, "w342")}
alt={season.name}
loading="lazy"
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.03]"
/>
</div>
<div className="flex items-center gap-2 p-2.5">
<div className="min-w-0 flex-1">
<p className="line-clamp-1 text-sm font-semibold">{season.name}</p>
<p className="text-xs text-muted-foreground tabular-nums">
{[getYear(season.air_date), `${watched}/${total} eps`]
.filter(Boolean)
.join(" · ")}
</p>
</div>
<ProgressRing
percent={percent}
done={total > 0 && watched >= total}
onClick={canMark ? (e) => stop(e, onMarkWatched) : undefined}
/>
</div>
</Link>
);
}
/** Circular progress with the mark-as-watched button in the middle. */
function ProgressRing({
percent,
done,
onClick,
}: {
percent: number;
done: boolean;
onClick?: (e: React.MouseEvent) => void;
}) {
const size = 44;
const stroke = 3.5;
const radius = (size - stroke) / 2;
const circumference = 2 * Math.PI * radius;
const offset = circumference * (1 - Math.min(100, percent) / 100);
return (
<div
className="relative shrink-0"
style={{ width: size, height: size }}
title={`${Math.round(percent)}% watched`}
>
<svg width={size} height={size} className="-rotate-90" aria-hidden="true">
<circle
cx={size / 2}
cy={size / 2}
r={radius}
fill="none"
strokeWidth={stroke}
className="stroke-muted"
/>
<circle
cx={size / 2}
cy={size / 2}
r={radius}
fill="none"
strokeWidth={stroke}
strokeLinecap="round"
strokeDasharray={circumference}
strokeDashoffset={offset}
className={`transition-[stroke-dashoffset] duration-500 ${
done ? "stroke-green-500" : "stroke-primary"
}`}
/>
</svg>
{done ? (
<span className="absolute inset-0 flex items-center justify-center text-green-500">
<Check className="h-4 w-4" />
</span>
) : (
<button
type="button"
onClick={onClick}
disabled={!onClick}
aria-label="Mark next episode as watched"
title="Mark next episode as watched"
className="absolute inset-1.5 flex items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none"
>
<Eye className="h-4 w-4" />
</button>
)}
</div>
);
}