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

+227 -250
View File
@@ -15,7 +15,6 @@ import { useStreamingStore } from "@/stores/useStreamingStore";
import { Skeleton } from "@/components/ui/skeleton";
import { Progress } from "@/components/ui/progress";
import { Button } from "@/components/ui/button";
import { StarRating } from "@/components/ui/star-rating";
import {
DropdownMenu,
DropdownMenuContent,
@@ -23,51 +22,77 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Eye,
CheckCircle2,
ArrowLeft,
ListChecks,
PlayCircle,
Ellipsis,
MoreHorizontal,
Play,
RefreshCw,
Star,
Tv,
CheckCircle2,
} from "lucide-react";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { getTmdbPosterUrl, getYear, formatDate } from "@/lib/media-utils";
import type { Episode, EpisodeSeen } from "@/types";
DetailHero,
DetailSection,
HeroChip,
IconAction,
MetaItem,
} from "@/components/entries/DetailHero";
import {
EpisodeViewToggle,
SeasonEpisodes,
} from "@/components/entries/SeasonEpisodes";
import {
isEpisodeWatched,
loadEpisodeView,
nextUnwatchedEpisode,
saveEpisodeView,
type EpisodeView,
} from "@/lib/episodes";
import {
getBackdropUrl,
getTmdbPosterUrl,
getYear,
formatDate,
formatRuntime,
} from "@/lib/media-utils";
import type { Episode } from "@/types";
export function SeasonPage() {
const { entryId, seasonId } = useParams<{
entryId: string;
seasonId: string;
}>();
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
const { data: entry } = useEntry(parseInt(entryId!, 10));
const { data: entrySeasons } = useEntrySeasons(parseInt(entryId!, 10));
const entryTitle =
entry?.title ??
useLibraryStore.getState().entries.get(parseInt(entryId!, 10))?.title;
const entryIdNum = parseInt(entryId!, 10);
const seasonIdNum = parseInt(seasonId!, 10);
const { data: season, isLoading } = useSeason(seasonIdNum);
const { data: episodes = [] } = useSeasonEpisodes(seasonIdNum);
const { data: entry } = useEntry(entryIdNum);
const { data: entrySeasons } = useEntrySeasons(entryIdNum);
const libraryEntry = useLibraryStore((s) => s.entries.get(entryIdNum));
const show = entry ?? libraryEntry;
const { initialize, play } = useStreamingStore();
const refreshSeason = useRefreshSeason();
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
const [showRatingDialog, setShowRatingDialog] = useState(false);
const [streamingOpen, setStreamingOpen] = useState(false);
const [view, setView] = useState<EpisodeView>(loadEpisodeView);
const handleWatchEpisode = (season: number, episodeNumber: number) => {
if (!entry?.entryIds?.tmdb_id) return;
const changeView = (next: EpisodeView) => {
setView(next);
saveEpisodeView(next);
};
const handleWatchEpisode = (episode: Episode) => {
if (!entry?.entryIds?.tmdb_id || !season) return;
initialize();
play({
type: "tv",
tmdbId: entry.entryIds.tmdb_id,
imdbId: entry.entryIds?.imdb_id || undefined,
season,
episode: episodeNumber,
season: season.season_number,
episode: episode.episode_number,
});
setStreamingOpen(true);
};
@@ -75,245 +100,199 @@ export function SeasonPage() {
if (isLoading || !season) {
return (
<div className="space-y-6">
<div className="flex gap-6">
<Skeleton className="h-56 w-36 shrink-0 rounded-lg" />
<div className="flex-1 space-y-3">
<Skeleton className="h-6 w-48" />
<Skeleton className="h-4 w-32" />
<Skeleton className="h-4 w-64" />
</div>
<Skeleton className="-mx-4 -mt-4 h-72 md:-mx-6 md:-mt-6" />
<div className="mx-auto max-w-6xl space-y-3">
{Array.from({ length: 5 }).map((_, i) => (
<Skeleton key={i} className="h-20 w-full rounded-xl" />
))}
</div>
</div>
);
}
const watchedCount = episodes.filter(
(ep: Episode) =>
ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0),
).length;
const watchedCount = episodes.filter(isEpisodeWatched).length;
const totalEpisodes = episodes.length;
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
const totalRuntime = episodes.reduce((sum, ep) => sum + (ep.runtime ?? 0), 0);
const airDates = episodes
.map((ep) => ep.air_date)
.filter(Boolean)
.sort() as string[];
const nextUp = nextUnwatchedEpisode(episodes);
const userRating = season.user_rating ?? 0;
const backdrop = show ? getBackdropUrl(show) : null;
return (
<div className="space-y-8 animate-page-enter mx-auto max-w-4xl">
{/* Breadcrumb: Title / Season x */}
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<div className="animate-page-enter">
<DetailHero backdrop={backdrop}>
<Link
to={`/entry/${entryId}`}
className="hover:text-foreground transition-colors truncate max-w-50"
className="mb-6 inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-background/60 py-1 pl-2 pr-3 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
>
{entryTitle || "Entry"}
<ArrowLeft className="h-4 w-4" />
Back to {show?.title ?? "show"}
</Link>
<span>/</span>
<span className="text-foreground font-medium">
Season {season.season_number}
</span>
</div>
<div className="flex flex-col items-center gap-6 sm:flex-row sm:items-end sm:gap-8">
<img
src={getTmdbPosterUrl(season.poster_path, "w500")}
alt={season.name}
className="aspect-2/3 w-36 shrink-0 rounded-xl object-cover shadow-2xl shadow-black/50 ring-1 ring-white/10 sm:w-48 lg:w-52"
/>
{/* Header */}
<div className="flex flex-col gap-4 sm:flex-row sm:gap-6">
<img
src={getTmdbPosterUrl(season.poster_path, "w185")}
alt={season.name}
className="h-40 w-28 shrink-0 rounded-lg object-cover shadow-lg self-center sm:self-start sm:h-56 sm:w-36"
/>
<div className="flex-1 flex flex-col justify-center space-y-3">
<div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
<h1 className="text-xl font-bold sm:text-2xl">{season.name}</h1>
{/* Actions dropdown — top right */}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<div className="min-w-0 flex-1 space-y-4 text-center sm:text-left">
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
<Link to={`/entry/${entryId}`}>
<HeroChip>
<Tv />
{show?.title ?? "Show"}
</HeroChip>
</Link>
<HeroChip>Season {season.season_number}</HeroChip>
{progress === 100 && totalEpisodes > 0 && (
<span className="inline-flex items-center gap-1 rounded-full bg-green-500/15 px-2.5 py-0.5 text-xs font-medium text-green-600 dark:text-green-400">
<CheckCircle2 className="h-3 w-3" /> Completed
</span>
)}
</div>
<h1 className="select-text text-4xl font-extrabold leading-[1.05] tracking-tight text-balance sm:text-5xl">
{season.name}
</h1>
<div className="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 text-sm text-muted-foreground sm:justify-start">
{season.air_date && (
<span className="font-medium text-foreground/90">
{getYear(season.air_date)}
</span>
)}
<MetaItem>
{totalEpisodes} {totalEpisodes === 1 ? "episode" : "episodes"}
</MetaItem>
{totalRuntime > 0 && (
<MetaItem>{formatRuntime(totalRuntime)}</MetaItem>
)}
{airDates.length > 1 && (
<MetaItem>
{formatDate(airDates[0])} – {formatDate(airDates.at(-1)!)}
</MetaItem>
)}
</div>
{/* Ratings + progress */}
<div className="flex flex-wrap items-center justify-center gap-x-5 gap-y-3 sm:justify-start">
<button
type="button"
onClick={() => setShowRatingDialog(true)}
className="inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-background/60 px-3 py-1 text-sm backdrop-blur transition-colors hover:bg-accent"
>
<Star
className={`h-4 w-4 ${userRating > 0 ? "fill-yellow-400 text-yellow-400" : "text-muted-foreground"}`}
/>
{userRating > 0 ? (
<span className="font-semibold tabular-nums">
{userRating}/10
</span>
) : (
<span className="text-muted-foreground">Rate season</span>
)}
</button>
{season.tmdb_rating ? (
<span className="text-sm text-muted-foreground tabular-nums">
TMDB{" "}
<span className="font-semibold text-sky-500">
{season.tmdb_rating.toFixed(1)}
</span>
</span>
) : null}
<div className="flex w-56 items-center gap-2">
<Progress value={progress} className="h-2 flex-1" />
<span className="text-xs font-medium tabular-nums text-muted-foreground">
{watchedCount}/{totalEpisodes}
</span>
</div>
</div>
{/* Actions */}
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
{nextUp && (
<Button
size="icon"
variant="outline"
className="shrink-0 self-end sm:self-start"
size="lg"
className="h-11 gap-2 px-6"
onClick={() => handleWatchEpisode(nextUp)}
disabled={!entry?.entryIds?.tmdb_id}
>
<Ellipsis className="h-4 w-4" />
<Play className="h-4 w-4 fill-current" />
{watchedCount > 0 ? "Continue" : "Start"}: E
{nextUp.episode_number}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
<DropdownMenuItem onClick={() => setShowMarkAllDialog(true)}>
<ListChecks className="mr-2 h-4 w-4" />
Mark Season Watched
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setShowRatingDialog(true)}>
<Star className="mr-2 h-4 w-4" />
Rate Season
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => refreshSeason.mutate(season.id)}
disabled={refreshSeason.isPending}
)}
<IconAction
label="Mark season watched"
onClick={() => setShowMarkAllDialog(true)}
>
<ListChecks className="h-4 w-4" />
</IconAction>
<IconAction
label={userRating > 0 ? "Change rating" : "Rate season"}
onClick={() => setShowRatingDialog(true)}
active={userRating > 0}
>
<Star className="h-4 w-4" />
</IconAction>
<DropdownMenu>
<DropdownMenuTrigger
render={
<Button
variant="outline"
size="icon-lg"
className="h-11 w-11 rounded-full border-border/60 bg-background/60 backdrop-blur"
aria-label="More actions"
/>
}
>
<RefreshCw
className={`mr-2 h-4 w-4 ${refreshSeason.isPending ? "animate-spin" : ""}`}
/>
Refresh Season
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span>Season {season.season_number}</span>
{season.air_date && (
<>
<span>•</span>
<span>{getYear(season.air_date)}</span>
</>
)}
<span>•</span>
<span>{totalEpisodes} episodes</span>
<MoreHorizontal className="h-4 w-4" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
<DropdownMenuItem
onClick={() => refreshSeason.mutate(season.id)}
disabled={refreshSeason.isPending}
>
<RefreshCw
className={`mr-2 h-4 w-4 ${refreshSeason.isPending ? "animate-spin" : ""}`}
/>
{refreshSeason.isPending
? "Refreshing..."
: "Refresh season"}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div>
</DetailHero>
{/* Season rating */}
<div className="flex items-center gap-2">
<StarRating value={season.user_rating ?? 0} readOnly size="sm" />
{season.user_rating != null && season.user_rating > 0 && (
<span className="text-sm font-medium tabular-nums">
{season.user_rating}/10
</span>
)}
{season.tmdb_rating != null && season.tmdb_rating > 0 && (
<span className="text-xs text-muted-foreground">
TMDB {season.tmdb_rating}
</span>
)}
</div>
{/* Watch progress */}
<div className="flex items-center gap-3 max-w-xs">
<Progress value={progress} className="flex-1 h-2" />
<span className="text-sm font-medium">
{watchedCount}/{totalEpisodes}
</span>
</div>
{season.overview && (
<p className="text-sm text-muted-foreground max-w-lg">
<div className="mx-auto mt-4 max-w-6xl space-y-10">
{season.overview && (
<DetailSection title="Overview">
<p className="select-text max-w-prose text-[15px] leading-relaxed text-foreground/85">
{season.overview}
</p>
)}
</div>
</div>
</DetailSection>
)}
{/* Episodes */}
<div className="space-y-3">
<h3 className="text-lg font-semibold">Episodes</h3>
<div className="space-y-2">
{episodes.map((episode: Episode) => {
const isWatched =
!!episode.date_first_seen ||
(episode.episodeSeens && episode.episodeSeens.length > 0);
const seenDates = (episode.episodeSeens ?? []).map(
(s: EpisodeSeen) => s.date_seen,
);
return (
<Link
key={episode.id}
to={`/entry/${entryId}/season/${seasonId}/episode/${episode.id}`}
className="flex gap-3 rounded-lg border border-border p-2 transition-colors hover:bg-accent/50 sm:gap-4 sm:p-3"
>
{/* Thumbnail — click to watch */}
<div
className="relative h-14 w-24 shrink-0 overflow-hidden rounded bg-muted sm:h-16 sm:w-28 group/thumb cursor-pointer"
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
if (!entry?.entryIds?.tmdb_id) return;
handleWatchEpisode(
season.season_number,
episode.episode_number,
);
}}
>
{episode.still_path ? (
<img
src={getTmdbPosterUrl(episode.still_path, "w300")}
alt={episode.name}
className="h-full w-full object-cover transition-[filter] group-hover/thumb:brightness-50"
loading="lazy"
/>
) : (
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground bg-muted group-hover/thumb:bg-muted/70 transition-colors">
No Image
</div>
)}
<div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover/thumb:opacity-100 transition-opacity">
<PlayCircle className="h-7 w-7 text-white drop-shadow-lg" />
</div>
</div>
{/* Info */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">
E{episode.episode_number}
</span>
<span className="text-sm font-medium truncate">
{episode.name}
</span>
{isWatched && (
<CheckCircle2 className="h-4 w-4 shrink-0 text-green-500" />
)}
</div>
<div className="flex items-center gap-2 flex-wrap">
{episode.air_date && (
<p className="text-xs text-muted-foreground">
{formatDate(episode.air_date)}
</p>
)}
{seenDates.length > 0 && (
<>
<span className="text-xs text-muted-foreground">•</span>
{seenDates.length === 1 ? (
<span className="text-xs text-green-600 dark:text-green-400">
Seen {formatDate(seenDates[0])}
</span>
) : (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<span className="text-xs text-green-600 dark:text-green-400 cursor-default underline decoration-dotted">
Seen {seenDates.length} times
</span>
</TooltipTrigger>
<TooltipContent>
<div className="space-y-0.5 text-xs">
{seenDates.map((d: string, i: number) => (
<p key={i}>{formatDate(d)}</p>
))}
</div>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</>
)}
</div>
{episode.overview && (
<p className="mt-1 text-xs text-muted-foreground line-clamp-2">
{episode.overview}
</p>
)}
</div>
{/* Watch button — always clickable to add another seen record */}
<Button
size="icon"
variant={isWatched ? "secondary" : "outline"}
className="h-8 w-8 shrink-0 self-center"
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
setDialogEpisode(episode);
}}
>
<Eye className="h-4 w-4" />
</Button>
</Link>
);
})}
</div>
<DetailSection
title="Episodes"
action={<EpisodeViewToggle view={view} onChange={changeView} />}
>
<SeasonEpisodes
episodes={episodes}
view={view}
entryId={entryIdNum}
seasonId={seasonIdNum}
onPlay={handleWatchEpisode}
onMarkWatched={setDialogEpisode}
/>
</DetailSection>
</div>
{/* Episode Seen Dialog */}
@@ -325,8 +304,8 @@ export function SeasonPage() {
}}
mode="create"
episodeId={dialogEpisode.id}
entryId={parseInt(entryId!, 10)}
seasonId={parseInt(seasonId!, 10)}
entryId={entryIdNum}
seasonId={seasonIdNum}
/>
)}
@@ -334,19 +313,17 @@ export function SeasonPage() {
<MarkSeasonWatchedDialog
open={showMarkAllDialog}
onOpenChange={setShowMarkAllDialog}
entryId={parseInt(entryId!, 10)}
seasonId={parseInt(seasonId!, 10)}
entryId={entryIdNum}
seasonId={seasonIdNum}
episodes={episodes}
/>
{/* Season Rating dialog */}
{season && (
<SeasonRatingDialog
open={showRatingDialog}
onOpenChange={setShowRatingDialog}
season={season}
/>
)}
<SeasonRatingDialog
open={showRatingDialog}
onOpenChange={setShowRatingDialog}
season={season}
/>
{/* Streaming dialog */}
{entry && streamingOpen && (