-
{episode.name}
+
+
+ {(episode.overview || directors.length > 0 || writers.length > 0) && (
+
+ {episode.overview && (
+
+ {episode.overview}
+
+ )}
+ {(directors.length > 0 || writers.length > 0) && (
+
+ {[
+ { label: "Directed by", people: directors },
+ { label: "Written by", people: writers },
+ ]
+ .filter((g) => g.people.length > 0)
+ .map((g) => (
+
+ {g.label}{" "}
+ {g.people.map((p, i) => (
+
+ {i > 0 && ", "}
+
+ {p.name}
+
+
+ ))}
+
+ ))}
+
+ )}
+
+ )}
-
- {episode.air_date &&
{formatDate(episode.air_date)} }
- {episode.runtime && (
-
-
- {formatRuntime(episode.runtime)}
-
+ {episode.guest_stars && episode.guest_stars.length > 0 && (
+
+ )}
+
+ {watchHistory.length > 0 && (
+
{
+ const rec = watchHistory.find((r) => r.id === id) as
+ EpisodeSeen | undefined;
+ if (rec) setEditRecord(rec);
+ }}
+ onDelete={(id) => setDeleteTarget(id)}
+ />
+ )}
+
+ {/* Prev / Next */}
+ {(prevEpisode || nextEpisode) && (
+
+ {prevEpisode ? (
+
+ ) : (
+
+ )}
+ {nextEpisode && (
+
+ )}
+
)}
- {episode.overview && (
-
- {episode.overview}
-
- )}
+ {/* Sidebar */}
+
+
+
+ {episode.air_date && (
+ } label="Aired">
+ {formatDate(episode.air_date)}
+
+ )}
+ {episode.runtime ? (
+ } label="Runtime">
+ {formatRuntime(episode.runtime)}
+
+ ) : null}
+ {episode.tmdb_rating ? (
+ } label="TMDB">
+ {episode.tmdb_rating.toFixed(1)}/10
+
+ ) : null}
+ {episode.production_code && (
+ } label="Prod. code">
+ {episode.production_code}
+
+ )}
+ } label="Watched">
+ {watchHistory.length > 0
+ ? watchHistory.length === 1
+ ? formatDate(watchHistory[0].date_seen)
+ : `${watchHistory.length}× · last ${formatDate(
+ watchHistory
+ .map((r) => r.date_seen)
+ .filter(Boolean)
+ .sort()
+ .at(-1) ?? null,
+ )}`
+ : "Not yet"}
+
+
+
- {episode.crew && episode.crew.length > 0 && (
-
- {(["Director", "Writer"] as const).map((job) => {
- const people = episode.crew!.filter(
- (c, i, all) =>
- (job === "Writer"
- ? c.department === "Writing"
- : c.job === "Director") &&
- all.findIndex(
- (o) => o.id === c.id && o.department === c.department,
- ) === i,
- );
- if (people.length === 0) return null;
- return (
-
- {job === "Director" ? "Directed by" : "Written by"}{" "}
- {people.map((p, i) => (
-
- {i > 0 && ", "}
+ {episodes.length > 1 && (
+
+
+ {episodes.map((ep) => {
+ const current = ep.id === episode.id;
+ return (
+
- {p.name}
+
+ E{ep.episode_number}
+
+ {ep.name}
+ {isEpisodeWatched(ep) && (
+
+ )}
-
- ))}
-
- );
- })}
-
- )}
-
-
- {/* Guest Stars (stored from TMDB; link to their TMDB person page) */}
- {episode.guest_stars && episode.guest_stars.length > 0 && (
- <>
-
-
- >
- )}
-
- {/* Watch History */}
- {watchHistory.length > 0 && (
- <>
-
-
{
- const rec = watchHistory.find((r) => r.id === id) as
- EpisodeSeen | undefined;
- if (rec) setEditRecord(rec);
- }}
- onDelete={(id) => setDeleteTarget(id)}
- />
- >
- )}
-
- {/* Prev / Next navigation */}
-
-
- {prevEpisode ? (
-
- navigate(
- `/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`,
- )
- }
- >
-
-
- E{prevEpisode.episode_number}: {prevEpisode.name}
-
-
- ) : (
-
- )}
- {nextEpisode ? (
-
- navigate(
- `/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`,
- )
- }
- >
-
- E{nextEpisode.episode_number}: {nextEpisode.name}
-
-
-
- ) : (
-
- )}
+
+ );
+ })}
+
+
+
Open season
+
+
+ )}
+
{/* Add watch record dialog */}
@@ -302,7 +422,7 @@ export function EpisodePage() {
mode="create"
episodeId={episode.id}
entryId={entryIdNum}
- seasonId={parseInt(seasonId!, 10)}
+ seasonId={seasonIdNum}
/>
)}
@@ -316,7 +436,7 @@ export function EpisodePage() {
mode="edit"
record={editRecord}
entryId={entryIdNum}
- seasonId={parseInt(seasonId!, 10)}
+ seasonId={seasonIdNum}
/>
)}
@@ -336,7 +456,7 @@ export function EpisodePage() {
id: deleteTarget,
entryId: entryIdNum,
episodeId: epId,
- seasonId: parseInt(seasonId!, 10),
+ seasonId: seasonIdNum,
});
setDeleteTarget(null);
}
@@ -358,3 +478,42 @@ export function EpisodePage() {
);
}
+
+function NeighbourCard({
+ episode,
+ href,
+ direction,
+}: {
+ episode: Episode;
+ href: string;
+ direction: "prev" | "next";
+}) {
+ return (
+
+
+ {episode.still_path && (
+
+ )}
+
+
+
+ {direction === "prev" && }
+ {direction === "prev" ? "Previous" : "Next"} · E
+ {episode.episode_number}
+ {direction === "next" && }
+
+
{episode.name}
+
+
+ );
+}
diff --git a/react_frontend/src/pages/SeasonPage.tsx b/react_frontend/src/pages/SeasonPage.tsx
index 25de4d9..fe2f830 100644
--- a/react_frontend/src/pages/SeasonPage.tsx
+++ b/react_frontend/src/pages/SeasonPage.tsx
@@ -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
(null);
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
const [showRatingDialog, setShowRatingDialog] = useState(false);
const [streamingOpen, setStreamingOpen] = useState(false);
+ const [view, setView] = useState(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 (
-
-
-
-
-
-
-
+
+
+ {Array.from({ length: 5 }).map((_, i) => (
+
+ ))}
);
}
- 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 (
-
- {/* Breadcrumb: Title / Season x */}
-
+
+
- {entryTitle || "Entry"}
+
+ Back to {show?.title ?? "show"}
- /
-
- Season {season.season_number}
-
-
+
+
- {/* Header */}
-
-
-
-
-
{season.name}
- {/* Actions dropdown — top right */}
-
-
+
+
+
+
+
+ {show?.title ?? "Show"}
+
+
+ Season {season.season_number}
+ {progress === 100 && totalEpisodes > 0 && (
+
+ Completed
+
+ )}
+
+
+
+ {season.name}
+
+
+
+ {season.air_date && (
+
+ {getYear(season.air_date)}
+
+ )}
+
+ {totalEpisodes} {totalEpisodes === 1 ? "episode" : "episodes"}
+
+ {totalRuntime > 0 && (
+ {formatRuntime(totalRuntime)}
+ )}
+ {airDates.length > 1 && (
+
+ {formatDate(airDates[0])} – {formatDate(airDates.at(-1)!)}
+
+ )}
+
+
+ {/* Ratings + progress */}
+
+
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"
+ >
+ 0 ? "fill-yellow-400 text-yellow-400" : "text-muted-foreground"}`}
+ />
+ {userRating > 0 ? (
+
+ {userRating}/10
+
+ ) : (
+ Rate season
+ )}
+
+ {season.tmdb_rating ? (
+
+ TMDB{" "}
+
+ {season.tmdb_rating.toFixed(1)}
+
+
+ ) : null}
+
+
+
+ {watchedCount}/{totalEpisodes}
+
+
+
+
+ {/* Actions */}
+
+ {nextUp && (
handleWatchEpisode(nextUp)}
+ disabled={!entry?.entryIds?.tmdb_id}
>
-
+
+ {watchedCount > 0 ? "Continue" : "Start"}: E
+ {nextUp.episode_number}
-
-
- setShowMarkAllDialog(true)}>
-
- Mark Season Watched
-
- setShowRatingDialog(true)}>
-
- Rate Season
-
- refreshSeason.mutate(season.id)}
- disabled={refreshSeason.isPending}
+ )}
+ setShowMarkAllDialog(true)}
+ >
+
+
+ 0 ? "Change rating" : "Rate season"}
+ onClick={() => setShowRatingDialog(true)}
+ active={userRating > 0}
+ >
+
+
+
+
+ }
>
-
- Refresh Season
-
-
-
-
-
- Season {season.season_number}
- {season.air_date && (
- <>
- •
- {getYear(season.air_date)}
- >
- )}
- •
- {totalEpisodes} episodes
+
+
+
+ refreshSeason.mutate(season.id)}
+ disabled={refreshSeason.isPending}
+ >
+
+ {refreshSeason.isPending
+ ? "Refreshing..."
+ : "Refresh season"}
+
+
+
+
+
+
- {/* Season rating */}
-
-
- {season.user_rating != null && season.user_rating > 0 && (
-
- {season.user_rating}/10
-
- )}
- {season.tmdb_rating != null && season.tmdb_rating > 0 && (
-
- TMDB {season.tmdb_rating}
-
- )}
-
-
- {/* Watch progress */}
-
-
-
- {watchedCount}/{totalEpisodes}
-
-
-
- {season.overview && (
-
+
+ {season.overview && (
+
+
{season.overview}
- )}
-
-
+
+ )}
- {/* Episodes */}
-
-
Episodes
-
- {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 (
-
- {/* Thumbnail — click to watch */}
-
{
- ev.preventDefault();
- ev.stopPropagation();
- if (!entry?.entryIds?.tmdb_id) return;
- handleWatchEpisode(
- season.season_number,
- episode.episode_number,
- );
- }}
- >
- {episode.still_path ? (
-
- ) : (
-
- No Image
-
- )}
-
-
-
- {/* Info */}
-
-
-
- E{episode.episode_number}
-
-
- {episode.name}
-
- {isWatched && (
-
- )}
-
-
- {episode.air_date && (
-
- {formatDate(episode.air_date)}
-
- )}
- {seenDates.length > 0 && (
- <>
-
•
- {seenDates.length === 1 ? (
-
- Seen {formatDate(seenDates[0])}
-
- ) : (
-
-
-
-
- Seen {seenDates.length} times
-
-
-
-
- {seenDates.map((d: string, i: number) => (
-
{formatDate(d)}
- ))}
-
-
-
-
- )}
- >
- )}
-
- {episode.overview && (
-
- {episode.overview}
-
- )}
-
-
- {/* Watch button — always clickable to add another seen record */}
-
{
- ev.preventDefault();
- ev.stopPropagation();
- setDialogEpisode(episode);
- }}
- >
-
-
-
- );
- })}
-
+
}
+ >
+
+
{/* 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() {
{/* Season Rating dialog */}
- {season && (
-
- )}
+
{/* Streaming dialog */}
{entry && streamingOpen && (