diff --git a/react_frontend/src/components/entries/DetailHero.tsx b/react_frontend/src/components/entries/DetailHero.tsx new file mode 100644 index 0000000..8f4d425 --- /dev/null +++ b/react_frontend/src/components/entries/DetailHero.tsx @@ -0,0 +1,178 @@ +import type { ReactNode } from "react"; +import { Link } from "react-router-dom"; +import { Button } from "@/components/ui/button"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; + +/** + * Full-bleed hero used by the season and episode pages: a backdrop that fades + * into the page, with content laid over it (same look as the entry page). + */ +export function DetailHero({ + backdrop, + children, +}: { + backdrop: string | null | undefined; + children: ReactNode; +}) { + return ( +
+
+ {backdrop ? ( + + ) : ( +
+ )} +
+
+
+
+ {children} +
+
+ ); +} + +export function MetaItem({ children }: { children: ReactNode }) { + return ( + + + {children} + + ); +} + +export function HeroChip({ children }: { children: ReactNode }) { + return ( + + {children} + + ); +} + +export function IconAction({ + label, + onClick, + disabled, + active, + children, +}: { + label: string; + onClick: () => void; + disabled?: boolean; + active?: boolean; + children: ReactNode; +}) { + return ( + + + } + > + {children} + + {label} + + ); +} + +/** Round icon link with a tooltip (same look as IconAction). */ +export function IconLink({ + label, + to, + children, +}: { + label: string; + to: string; + children: ReactNode; +}) { + return ( + + + } + > + {children} + + {label} + + ); +} + +export function DetailSection({ + title, + action, + children, +}: { + title: string; + action?: ReactNode; + children: ReactNode; +}) { + return ( +
+
+

{title}

+ {action} +
+ {children} +
+ ); +} + +export function DetailCard({ + title, + children, +}: { + title: string; + children: ReactNode; +}) { + return ( +
+

+ {title} +

+ {children} +
+ ); +} + +export function DetailRow({ + icon, + label, + children, +}: { + icon: ReactNode; + label: string; + children: ReactNode; +}) { + return ( +
+
+ {icon} + {label} +
+
{children}
+
+ ); +} diff --git a/react_frontend/src/components/entries/SeasonEpisodes.tsx b/react_frontend/src/components/entries/SeasonEpisodes.tsx new file mode 100644 index 0000000..be0f9e8 --- /dev/null +++ b/react_frontend/src/components/entries/SeasonEpisodes.tsx @@ -0,0 +1,324 @@ +import { Link } from "react-router-dom"; +import { + CheckCircle2, + Clock, + Eye, + LayoutGrid, + List, + PlayCircle, + Star, +} from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { getTmdbPosterUrl, formatDate, formatRuntime } from "@/lib/media-utils"; +import { + isEpisodeUpcoming, + isEpisodeWatched, + type EpisodeView, +} from "@/lib/episodes"; +import type { Episode, EpisodeSeen } from "@/types"; + +interface EpisodeActions { + entryId: number; + seasonId: number; + onPlay: (episode: Episode) => void; + onMarkWatched: (episode: Episode) => void; +} + +/** List/cards toggle for the season page's episodes header. */ +export function EpisodeViewToggle({ + view, + onChange, +}: { + view: EpisodeView; + onChange: (view: EpisodeView) => void; +}) { + return ( +
+ {( + [ + { value: "list", label: "List view", Icon: List }, + { value: "cards", label: "Card view", Icon: LayoutGrid }, + ] as const + ).map(({ value, label, Icon }) => ( + + ))} +
+ ); +} + +export function SeasonEpisodes({ + episodes, + view, + ...actions +}: EpisodeActions & { episodes: Episode[]; view: EpisodeView }) { + if (view === "cards") { + return ( +
+ {episodes.map((ep) => ( + + ))} +
+ ); + } + return ( +
+ {episodes.map((ep) => ( + + ))} +
+ ); +} + +function episodeHref(entryId: number, seasonId: number, ep: Episode) { + return `/entry/${entryId}/season/${seasonId}/episode/${ep.id}`; +} + +function stop(ev: React.MouseEvent, fn: () => void) { + ev.preventDefault(); + ev.stopPropagation(); + fn(); +} + +function SeenLabel({ episode }: { episode: Episode }) { + const dates = (episode.episodeSeens ?? []).map( + (s: EpisodeSeen) => s.date_seen, + ); + if (dates.length === 0) return null; + if (dates.length === 1) { + return ( + + Seen {formatDate(dates[0])} + + ); + } + return ( + + + } + > + Seen {dates.length} times + + +
+ {dates.map((d, i) => ( +

{formatDate(d)}

+ ))} +
+
+
+ ); +} + +function EpisodeMeta({ episode }: { episode: Episode }) { + return ( +
+ {episode.air_date && {formatDate(episode.air_date)}} + {episode.runtime ? ( + + + {formatRuntime(episode.runtime)} + + ) : null} + {episode.tmdb_rating ? ( + + + {episode.tmdb_rating.toFixed(1)} + + ) : null} + +
+ ); +} + +function TypeBadge({ episode }: { episode: Episode }) { + if (isEpisodeUpcoming(episode)) { + return ( + + Upcoming + + ); + } + if ( + episode.episode_type === "finale" || + episode.episode_type === "mid_season" + ) { + return ( + + {episode.episode_type === "finale" ? "Finale" : "Mid-season"} + + ); + } + return null; +} + +function Still({ + episode, + size, + className, + onPlay, +}: { + episode: Episode; + size: string; + className: string; + onPlay: () => void; +}) { + return ( +
stop(ev, onPlay)} + role="button" + aria-label={`Play episode ${episode.episode_number}`} + > + {episode.still_path ? ( + {episode.name} + ) : ( +
+ No image +
+ )} +
+ +
+
+ ); +} + +function WatchButton({ + episode, + onClick, +}: { + episode: Episode; + onClick: () => void; +}) { + const watched = isEpisodeWatched(episode); + return ( + + ); +} + +function EpisodeRow({ + episode, + entryId, + seasonId, + onPlay, + onMarkWatched, +}: EpisodeActions & { episode: Episode }) { + const watched = isEpisodeWatched(episode); + return ( + + onPlay(episode)} + /> +
+
+ + E{episode.episode_number} + + {episode.name} + {watched && ( + + )} + +
+ + {episode.overview && ( +

+ {episode.overview} +

+ )} +
+ onMarkWatched(episode)} /> + + ); +} + +function EpisodeCard({ + episode, + entryId, + seasonId, + onPlay, + onMarkWatched, +}: EpisodeActions & { episode: Episode }) { + const watched = isEpisodeWatched(episode); + return ( + +
+ onPlay(episode)} + /> + + E{episode.episode_number} + + {watched && ( + + + Watched + + )} +
+
+
+

{episode.name}

+ +
+ + {episode.overview && ( +

+ {episode.overview} +

+ )} +
+ onMarkWatched(episode)} + /> +
+
+ + ); +} diff --git a/react_frontend/src/components/entries/SeasonsContainer.tsx b/react_frontend/src/components/entries/SeasonsContainer.tsx index 72590cb..5717ca9 100644 --- a/react_frontend/src/components/entries/SeasonsContainer.tsx +++ b/react_frontend/src/components/entries/SeasonsContainer.tsx @@ -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(loadSeasonView); + const [markingSeason, setMarkingSeason] = useState(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 (
-

Seasons

-
- {display.map((season) => ( - - ))} +
+

Seasons

+
- {sorted.length > 2 && ( + + {view === "cards" ? ( +
+ {display.map((season) => ( + setMarkingSeason(season)} + /> + ))} +
+ ) : ( +
+ {display.map((season) => ( + setMarkingSeason(season)} + /> + ))} +
+ )} + + {sorted.length > limit && (
); } -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 ( - <> - - {/* Poster thumbnail */} -
- {season.name} -
- - {/* Info */} -
-
- {season.name} - - {getYear(season.air_date)} - -
-
- - - {watchedCount}/{totalEpisodes} - -
-
- - {/* Quick watch button - opens dialog */} - {nextUnwatched && ( - - )} - - - {nextUnwatched && dialogOpen && ( - +
+ {season.name} +
+ +
+
+ {season.name} + + {getYear(season.air_date)} + +
+
+ + + {watched}/{total} + +
+
+ + {canMark && ( + )} - + + ); +} + +function SeasonCard({ + season, + entryId, + onMarkWatched, +}: { + season: Season; + entryId: number; + onMarkWatched: () => void; +}) { + const { watched, total, percent } = seasonProgress(season); + const canMark = !!nextUnwatched(season); + + return ( + +
+ {season.name} +
+
+
+

{season.name}

+

+ {[getYear(season.air_date), `${watched}/${total} eps`] + .filter(Boolean) + .join(" · ")} +

+
+ 0 && watched >= total} + onClick={canMark ? (e) => stop(e, onMarkWatched) : undefined} + /> +
+ + ); +} + +/** 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 ( +
+ + {done ? ( + + + + ) : ( + + )} +
); } diff --git a/react_frontend/src/lib/episodes.ts b/react_frontend/src/lib/episodes.ts new file mode 100644 index 0000000..b616950 --- /dev/null +++ b/react_frontend/src/lib/episodes.ts @@ -0,0 +1,37 @@ +import type { Episode } from "@/types"; + +export const isEpisodeWatched = (ep: Episode) => + !!ep.date_first_seen || (ep.episodeSeens?.length ?? 0) > 0; + +export const isEpisodeUpcoming = (ep: Episode) => + !!ep.air_date && new Date(ep.air_date).getTime() > Date.now(); + +/** First aired episode not watched yet (what "Continue" should play). */ +export const nextUnwatchedEpisode = (episodes: Episode[]) => + episodes.find((ep) => !isEpisodeWatched(ep) && !isEpisodeUpcoming(ep)); + +export type EpisodeView = "list" | "cards"; + +/** Remembered list/cards choice (per browser); falls back to list. */ +function loadView(key: string): EpisodeView { + try { + return localStorage.getItem(key) === "cards" ? "cards" : "list"; + } catch { + return "list"; + } +} + +function saveView(key: string, view: EpisodeView) { + try { + localStorage.setItem(key, view); + } catch { + // storage unavailable (private mode); the choice just isn't remembered + } +} + +export const loadEpisodeView = () => loadView("showy.episodeView"); +export const saveEpisodeView = (view: EpisodeView) => + saveView("showy.episodeView", view); +export const loadSeasonView = () => loadView("showy.seasonView"); +export const saveSeasonView = (view: EpisodeView) => + saveView("showy.seasonView", view); diff --git a/react_frontend/src/pages/EpisodePage.tsx b/react_frontend/src/pages/EpisodePage.tsx index 168c536..2935211 100644 --- a/react_frontend/src/pages/EpisodePage.tsx +++ b/react_frontend/src/pages/EpisodePage.tsx @@ -1,8 +1,6 @@ import { useState } from "react"; -import { useParams, useNavigate, Link } from "react-router-dom"; -import { useQuery } from "@tanstack/react-query"; -import { seasonsApi } from "@/api/seasons"; -import { useSeason } from "@/hooks/useSeasons"; +import { useParams, Link } from "react-router-dom"; +import { useSeason, useSeasonEpisodes } from "@/hooks/useSeasons"; import { useEntry, useEntrySeasons } from "@/hooks/useEntries"; import { useLibraryStore } from "@/stores/useLibraryStore"; import { @@ -13,19 +11,39 @@ import { StreamingDialog } from "@/components/streaming/StreamingDialog"; import { useStreamingStore } from "@/stores/useStreamingStore"; import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button"; -import { Separator } from "@/components/ui/separator"; import { EpisodeWatchHistory } from "@/components/entries/EpisodeWatchHistory"; import { EpisodeSeenEditDialog } from "@/components/dialogs/EpisodeSeenEditDialog"; import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog"; import { CastList } from "@/components/entries/CastList"; import { - Eye, + DetailCard, + DetailHero, + DetailRow, + DetailSection, + HeroChip, + IconLink, + MetaItem, +} from "@/components/entries/DetailHero"; +import { + CalendarDays, + CheckCircle2, ChevronLeft, ChevronRight, Clock, - PlayCircle, + Eye, + Hash, + ListVideo, + Play, + Star, + Tv, } from "lucide-react"; -import { getTmdbPosterUrl, formatDate, formatRuntime } from "@/lib/media-utils"; +import { isEpisodeUpcoming, isEpisodeWatched } from "@/lib/episodes"; +import { + getBackdropUrl, + getTmdbPosterUrl, + formatDate, + formatRuntime, +} from "@/lib/media-utils"; import type { Credit, Episode, EpisodePerson, EpisodeSeen } from "@/types"; /** Stored guest star → the Credit shape CastList renders (links via TMDB id). */ @@ -47,32 +65,29 @@ function toGuestCredit(guest: EpisodePerson): Credit { }; } +const pad = (n: number | null | undefined) => String(n ?? 0).padStart(2, "0"); + export function EpisodePage() { const { entryId, seasonId, episodeId } = useParams<{ entryId: string; seasonId: string; episodeId: string; }>(); - const navigate = useNavigate(); + const entryIdNum = parseInt(entryId!, 10); + const seasonIdNum = parseInt(seasonId!, 10); + const epId = parseInt(episodeId!, 10); - const { data: episodes = [] } = useQuery({ - queryKey: ["seasons", parseInt(seasonId!, 10), "episodes"], - queryFn: () => seasonsApi.getEpisodes(parseInt(seasonId!, 10)), - }); - - const { data: season } = useSeason(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 { data: episodes = [] } = useSeasonEpisodes(seasonIdNum); + const { data: season } = useSeason(seasonIdNum); + const { data: entry } = useEntry(entryIdNum); + const { data: entrySeasons } = useEntrySeasons(entryIdNum); + const libraryEntry = useLibraryStore((s) => s.entries.get(entryIdNum)); + const show = entry ?? libraryEntry; const seasonNumber = season?.season_number; const { initialize, play } = useStreamingStore(); const [streamingOpen, setStreamingOpen] = useState(false); - const epId = parseInt(episodeId!, 10); - const entryIdNum = parseInt(entryId!, 10); const episode: Episode | undefined = episodes.find( (ep: Episode) => ep.id === epId, ); @@ -83,215 +98,320 @@ export function EpisodePage() { const [deleteTarget, setDeleteTarget] = useState(null); const [showAddDialog, setShowAddDialog] = useState(false); - // Find prev/next episode const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId); const prevEpisode: Episode | undefined = currentIndex > 0 ? episodes[currentIndex - 1] : undefined; const nextEpisode: Episode | undefined = - currentIndex < episodes.length - 1 ? episodes[currentIndex + 1] : undefined; + currentIndex >= 0 && currentIndex < episodes.length - 1 + ? episodes[currentIndex + 1] + : undefined; + + const episodeHref = (ep: Episode) => + `/entry/${entryId}/season/${seasonId}/episode/${ep.id}`; if (!episode) { return (
- - - + +
+ + +
); } + const canPlay = !!entry?.entryIds?.tmdb_id && !!seasonNumber; + const watchEpisode = () => { + if (!entry?.entryIds?.tmdb_id || !seasonNumber) return; + initialize(); + play({ + type: "tv", + tmdbId: entry.entryIds.tmdb_id, + imdbId: entry.entryIds?.imdb_id || undefined, + season: seasonNumber, + episode: episode.episode_number, + }); + setStreamingOpen(true); + }; + + const watched = isEpisodeWatched(episode); + const upcoming = isEpisodeUpcoming(episode); + const backdrop = episode.still_path + ? getTmdbPosterUrl(episode.still_path, "original") + : show + ? getBackdropUrl(show) + : null; + + const crewBy = (job: "Director" | "Writer") => + (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, + ); + const directors = crewBy("Director"); + const writers = crewBy("Writer"); + return ( -
- {/* Breadcrumb: Title / Season x / Episode x */} -
- - {entryTitle || "Entry"} - - / - - Season {seasonNumber ?? "?"} - - / - - Episode {episode.episode_number} - -
- - {/* Top bar: nav breadcrumb + Mark Watched */} -
-
- - S{String(seasonNumber ?? 0).padStart(2, "0")} E - {String(episode.episode_number).padStart(2, "0")} - -
- -
- - {/* High-quality thumbnail — click to watch */} - {episode.still_path && ( -
{ - if (!entry?.entryIds?.tmdb_id || !seasonNumber) return; - initialize(); - play({ - type: "tv", - tmdbId: entry.entryIds.tmdb_id, - imdbId: entry.entryIds?.imdb_id || undefined, - season: seasonNumber, - episode: episode.episode_number, - }); - setStreamingOpen(true); - }} - > - {episode.name} -
-
- - - Watch Episode +
+ +
+
+ + + + {show?.title ?? "Show"} + + + + Season {seasonNumber ?? "?"} + + + S{pad(seasonNumber)}E{pad(episode.episode_number)} + + {episode.episode_type === "finale" && ( + + Finale -
+ )} + {upcoming && ( + + Upcoming + + )} + {watched && ( + + Watched + + )} +
+ +

+ {episode.name} +

+ +
+ {episode.air_date && ( + + {formatDate(episode.air_date)} + + )} + {episode.runtime ? ( + {formatRuntime(episode.runtime)} + ) : null} + {episode.tmdb_rating ? ( + + + + {episode.tmdb_rating.toFixed(1)} + {episode.tmdb_vote_count ? ( + + ({episode.tmdb_vote_count} votes) + + ) : null} + + + ) : null} +
+ +
+ + + {prevEpisode && ( + + + + )} + {nextEpisode && ( + + + + )}
- )} + - {/* Info */} -
-

{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 */} +
- - {/* 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 ? ( - - ) : ( -
- )} - {nextEpisode ? ( - - ) : ( -
- )} + + ); + })} + + + 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} - -
+
+ {season.name} - {/* Header */} -
- {season.name} -
-
-

{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 */} +
+ + {season.tmdb_rating ? ( + + TMDB{" "} + + {season.tmdb_rating.toFixed(1)} + + + ) : null} +
+ + + {watchedCount}/{totalEpisodes} + +
+
+ + {/* Actions */} +
+ {nextUp && ( - - - 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 ? ( - {episode.name} - ) : ( -
- 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 */} - - - ); - })} -
+ } + > + +
{/* 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 && (