Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be248d7513 |
No files matched your search
@@ -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 (
|
||||
<section className="relative -mx-4 -mt-4 md:-mx-6 md:-mt-6">
|
||||
<div className="absolute inset-0 overflow-hidden">
|
||||
{backdrop ? (
|
||||
<img
|
||||
src={backdrop}
|
||||
alt=""
|
||||
className="h-full w-full object-cover object-top"
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full w-full bg-linear-to-br from-primary/30 via-primary/10 to-background" />
|
||||
)}
|
||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/75 to-background/10" />
|
||||
<div className="absolute inset-0 bg-linear-to-r from-background/90 via-background/40 to-transparent" />
|
||||
</div>
|
||||
<div className="relative mx-auto max-w-6xl px-4 pb-8 pt-24 md:px-6 sm:pt-40">
|
||||
{children}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function MetaItem({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-3">
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/50" />
|
||||
<span>{children}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function HeroChip({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-background/60 px-2.5 py-0.5 text-xs font-medium uppercase tracking-wider text-muted-foreground backdrop-blur [&_svg]:h-3 [&_svg]:w-3">
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function IconAction({
|
||||
label,
|
||||
onClick,
|
||||
disabled,
|
||||
active,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
onClick: () => void;
|
||||
disabled?: boolean;
|
||||
active?: boolean;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon-lg"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
aria-label={label}
|
||||
aria-pressed={active}
|
||||
className={`h-11 w-11 rounded-full border-border/60 bg-background/60 backdrop-blur ${active ? "border-foreground/20 bg-accent" : ""}`}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
/** Round icon link with a tooltip (same look as IconAction). */
|
||||
export function IconLink({
|
||||
label,
|
||||
to,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
to: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Link
|
||||
to={to}
|
||||
aria-label={label}
|
||||
className="inline-flex h-11 w-11 items-center justify-center rounded-full border border-border/60 bg-background/60 backdrop-blur transition-colors hover:bg-accent"
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export function DetailSection({
|
||||
title,
|
||||
action,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
action?: ReactNode;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h3 className="text-lg font-semibold">{title}</h3>
|
||||
{action}
|
||||
</div>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function DetailCard({
|
||||
title,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-xl border border-border/60 bg-card/50 p-4">
|
||||
<h3 className="mb-3 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
||||
{title}
|
||||
</h3>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DetailRow({
|
||||
icon,
|
||||
label,
|
||||
children,
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
label: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-start justify-between gap-4 text-sm">
|
||||
<dt className="flex items-center gap-2 text-muted-foreground [&_svg]:h-3.5 [&_svg]:w-3.5">
|
||||
{icon}
|
||||
{label}
|
||||
</dt>
|
||||
<dd className="text-right font-medium">{children}</dd>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="flex items-center rounded-lg border border-border/60 p-0.5">
|
||||
{(
|
||||
[
|
||||
{ value: "list", label: "List view", Icon: List },
|
||||
{ value: "cards", label: "Card view", Icon: LayoutGrid },
|
||||
] as const
|
||||
).map(({ value, label, Icon }) => (
|
||||
<Button
|
||||
key={value}
|
||||
variant={view === value ? "secondary" : "ghost"}
|
||||
size="icon-sm"
|
||||
aria-label={label}
|
||||
aria-pressed={view === value}
|
||||
title={label}
|
||||
onClick={() => onChange(value)}
|
||||
>
|
||||
<Icon />
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SeasonEpisodes({
|
||||
episodes,
|
||||
view,
|
||||
...actions
|
||||
}: EpisodeActions & { episodes: Episode[]; view: EpisodeView }) {
|
||||
if (view === "cards") {
|
||||
return (
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{episodes.map((ep) => (
|
||||
<EpisodeCard key={ep.id} episode={ep} {...actions} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{episodes.map((ep) => (
|
||||
<EpisodeRow key={ep.id} episode={ep} {...actions} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<span className="text-green-600 dark:text-green-400">
|
||||
Seen {formatDate(dates[0])}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span className="cursor-default text-green-600 underline decoration-dotted dark:text-green-400" />
|
||||
}
|
||||
>
|
||||
Seen {dates.length} times
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<div className="space-y-0.5 text-xs">
|
||||
{dates.map((d, i) => (
|
||||
<p key={i}>{formatDate(d)}</p>
|
||||
))}
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function EpisodeMeta({ episode }: { episode: Episode }) {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-muted-foreground">
|
||||
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
||||
{episode.runtime ? (
|
||||
<span className="inline-flex items-center gap-0.5">
|
||||
<Clock className="h-3 w-3" />
|
||||
{formatRuntime(episode.runtime)}
|
||||
</span>
|
||||
) : null}
|
||||
{episode.tmdb_rating ? (
|
||||
<span className="inline-flex items-center gap-0.5 tabular-nums">
|
||||
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
|
||||
{episode.tmdb_rating.toFixed(1)}
|
||||
</span>
|
||||
) : null}
|
||||
<SeenLabel episode={episode} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TypeBadge({ episode }: { episode: Episode }) {
|
||||
if (isEpisodeUpcoming(episode)) {
|
||||
return (
|
||||
<span className="rounded bg-sky-500/15 px-1.5 py-px text-[10px] font-semibold uppercase text-sky-600 dark:text-sky-400">
|
||||
Upcoming
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (
|
||||
episode.episode_type === "finale" ||
|
||||
episode.episode_type === "mid_season"
|
||||
) {
|
||||
return (
|
||||
<span className="rounded bg-violet-500/15 px-1.5 py-px text-[10px] font-semibold uppercase text-violet-600 dark:text-violet-400">
|
||||
{episode.episode_type === "finale" ? "Finale" : "Mid-season"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function Still({
|
||||
episode,
|
||||
size,
|
||||
className,
|
||||
onPlay,
|
||||
}: {
|
||||
episode: Episode;
|
||||
size: string;
|
||||
className: string;
|
||||
onPlay: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`group/thumb relative shrink-0 cursor-pointer overflow-hidden bg-muted ${className}`}
|
||||
onClick={(ev) => stop(ev, onPlay)}
|
||||
role="button"
|
||||
aria-label={`Play episode ${episode.episode_number}`}
|
||||
>
|
||||
{episode.still_path ? (
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, size)}
|
||||
alt={episode.name}
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover transition duration-300 group-hover/thumb:scale-[1.03] group-hover/thumb:brightness-50"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
|
||||
No image
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover/thumb:opacity-100">
|
||||
<PlayCircle className="h-9 w-9 text-white drop-shadow-lg" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WatchButton({
|
||||
episode,
|
||||
onClick,
|
||||
}: {
|
||||
episode: Episode;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const watched = isEpisodeWatched(episode);
|
||||
return (
|
||||
<Button
|
||||
size="icon"
|
||||
variant={watched ? "secondary" : "outline"}
|
||||
className="h-8 w-8 shrink-0"
|
||||
aria-label={watched ? "Watch again" : "Mark as watched"}
|
||||
title={watched ? "Add another watch" : "Mark as watched"}
|
||||
onClick={(ev) => stop(ev, onClick)}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function EpisodeRow({
|
||||
episode,
|
||||
entryId,
|
||||
seasonId,
|
||||
onPlay,
|
||||
onMarkWatched,
|
||||
}: EpisodeActions & { episode: Episode }) {
|
||||
const watched = isEpisodeWatched(episode);
|
||||
return (
|
||||
<Link
|
||||
to={episodeHref(entryId, seasonId, episode)}
|
||||
className={`flex items-center gap-3 rounded-xl border p-2 transition-colors hover:bg-accent/40 sm:gap-4 sm:p-2.5 ${
|
||||
watched ? "border-green-500/25 bg-green-500/[0.03]" : "border-border/60"
|
||||
}`}
|
||||
>
|
||||
<Still
|
||||
episode={episode}
|
||||
size="w300"
|
||||
className="h-16 w-28 rounded-lg sm:h-20 sm:w-36"
|
||||
onPlay={() => onPlay(episode)}
|
||||
/>
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-semibold text-muted-foreground tabular-nums">
|
||||
E{episode.episode_number}
|
||||
</span>
|
||||
<span className="truncate font-medium">{episode.name}</span>
|
||||
{watched && (
|
||||
<CheckCircle2 className="h-4 w-4 shrink-0 text-green-500" />
|
||||
)}
|
||||
<TypeBadge episode={episode} />
|
||||
</div>
|
||||
<EpisodeMeta episode={episode} />
|
||||
{episode.overview && (
|
||||
<p className="line-clamp-2 text-xs text-muted-foreground">
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<WatchButton episode={episode} onClick={() => onMarkWatched(episode)} />
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function EpisodeCard({
|
||||
episode,
|
||||
entryId,
|
||||
seasonId,
|
||||
onPlay,
|
||||
onMarkWatched,
|
||||
}: EpisodeActions & { episode: Episode }) {
|
||||
const watched = isEpisodeWatched(episode);
|
||||
return (
|
||||
<Link
|
||||
to={episodeHref(entryId, seasonId, episode)}
|
||||
className="group flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card/50 transition-colors hover:bg-accent/40"
|
||||
>
|
||||
<div className="relative">
|
||||
<Still
|
||||
episode={episode}
|
||||
size="w780"
|
||||
className="aspect-video w-full"
|
||||
onPlay={() => onPlay(episode)}
|
||||
/>
|
||||
<span className="pointer-events-none absolute left-2 top-2 rounded-md bg-black/65 px-2 py-0.5 text-xs font-bold text-white tabular-nums backdrop-blur">
|
||||
E{episode.episode_number}
|
||||
</span>
|
||||
{watched && (
|
||||
<span className="pointer-events-none absolute right-2 top-2 inline-flex items-center gap-1 rounded-full bg-green-500/90 px-2 py-0.5 text-[10px] font-semibold text-white shadow">
|
||||
<CheckCircle2 className="h-3 w-3" />
|
||||
Watched
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col gap-1.5 p-3">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className="line-clamp-1 font-semibold">{episode.name}</p>
|
||||
<TypeBadge episode={episode} />
|
||||
</div>
|
||||
<EpisodeMeta episode={episode} />
|
||||
{episode.overview && (
|
||||
<p className="line-clamp-3 text-xs text-muted-foreground">
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
<div className="mt-auto flex justify-end pt-1">
|
||||
<WatchButton
|
||||
episode={episode}
|
||||
onClick={() => onMarkWatched(episode)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -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">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h3 className="text-lg font-semibold">Seasons</h3>
|
||||
<div className="space-y-2">
|
||||
<EpisodeViewToggle view={view} onChange={changeView} />
|
||||
</div>
|
||||
|
||||
{view === "cards" ? (
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-4">
|
||||
{display.map((season) => (
|
||||
<SeasonItem key={season.id} season={season} entryId={entryId} />
|
||||
<SeasonCard
|
||||
key={season.id}
|
||||
season={season}
|
||||
entryId={entryId}
|
||||
onMarkWatched={() => setMarkingSeason(season)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{sorted.length > 2 && (
|
||||
) : (
|
||||
<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,36 +93,63 @@ 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")}
|
||||
@@ -90,48 +159,142 @@ function SeasonItem({ season, entryId }: { season: Season; entryId: number }) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-sm truncate">{season.name}</span>
|
||||
<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="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}
|
||||
<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>
|
||||
|
||||
{/* Quick watch button - opens dialog */}
|
||||
{nextUnwatched && (
|
||||
{canMark && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 shrink-0"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setDialogOpen(true);
|
||||
}}
|
||||
aria-label="Mark next episode as watched"
|
||||
title="Mark next episode as watched"
|
||||
onClick={(e) => stop(e, onMarkWatched)}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
{nextUnwatched && dialogOpen && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
mode="create"
|
||||
episodeId={nextUnwatched.id}
|
||||
entryId={entryId}
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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,65 +98,31 @@ export function EpisodePage() {
|
||||
const [deleteTarget, setDeleteTarget] = useState<number | null>(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 (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-48 w-full rounded-lg" />
|
||||
<Skeleton className="-mx-4 -mt-4 h-80 md:-mx-6 md:-mt-6" />
|
||||
<div className="mx-auto max-w-6xl space-y-3">
|
||||
<Skeleton className="h-6 w-48" />
|
||||
<Skeleton className="h-4 w-80" />
|
||||
<Skeleton className="h-20 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8 mx-auto max-w-4xl">
|
||||
{/* Breadcrumb: Title / Season x / Episode x */}
|
||||
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
||||
<Link
|
||||
to={`/entry/${entryId}`}
|
||||
className="hover:text-foreground transition-colors truncate max-w-50"
|
||||
>
|
||||
{entryTitle || "Entry"}
|
||||
</Link>
|
||||
<span>/</span>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}`}
|
||||
className="hover:text-foreground transition-colors"
|
||||
>
|
||||
Season {seasonNumber ?? "?"}
|
||||
</Link>
|
||||
<span>/</span>
|
||||
<span className="text-foreground font-medium">
|
||||
Episode {episode.episode_number}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Top bar: nav breadcrumb + Mark Watched */}
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span className="font-medium text-foreground">
|
||||
S{String(seasonNumber ?? 0).padStart(2, "0")} E
|
||||
{String(episode.episode_number).padStart(2, "0")}
|
||||
</span>
|
||||
</div>
|
||||
<Button size="sm" onClick={() => setShowAddDialog(true)}>
|
||||
<Eye className="mr-1.5 h-4 w-4" />
|
||||
Mark as Watched
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* High-quality thumbnail — click to watch */}
|
||||
{episode.still_path && (
|
||||
<div
|
||||
className="relative overflow-hidden rounded-xl cursor-pointer group"
|
||||
onClick={() => {
|
||||
const canPlay = !!entry?.entryIds?.tmdb_id && !!seasonNumber;
|
||||
const watchEpisode = () => {
|
||||
if (!entry?.entryIds?.tmdb_id || !seasonNumber) return;
|
||||
initialize();
|
||||
play({
|
||||
@@ -152,61 +133,149 @@ export function EpisodePage() {
|
||||
episode: episode.episode_number,
|
||||
});
|
||||
setStreamingOpen(true);
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, "w1280")}
|
||||
alt={episode.name}
|
||||
className="w-full max-h-96 object-cover transition-[filter] group-hover:brightness-50"
|
||||
/>
|
||||
<div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<div className="flex items-center gap-2 bg-black/60 backdrop-blur-sm rounded-full px-5 py-2.5">
|
||||
<PlayCircle className="h-6 w-6 text-white" />
|
||||
<span className="text-white font-medium text-sm">
|
||||
Watch Episode
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
};
|
||||
|
||||
{/* Info */}
|
||||
<div className="space-y-3">
|
||||
<h1 className="text-2xl font-bold">{episode.name}</h1>
|
||||
const watched = isEpisodeWatched(episode);
|
||||
const upcoming = isEpisodeUpcoming(episode);
|
||||
const backdrop = episode.still_path
|
||||
? getTmdbPosterUrl(episode.still_path, "original")
|
||||
: show
|
||||
? getBackdropUrl(show)
|
||||
: null;
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||||
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
||||
{episode.runtime && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{formatRuntime(episode.runtime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{episode.overview && (
|
||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl">
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{episode.crew && episode.crew.length > 0 && (
|
||||
<div className="space-y-1 text-sm">
|
||||
{(["Director", "Writer"] as const).map((job) => {
|
||||
const people = episode.crew!.filter(
|
||||
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,
|
||||
all.findIndex((o) => o.id === c.id && o.department === c.department) ===
|
||||
i,
|
||||
);
|
||||
if (people.length === 0) return null;
|
||||
const directors = crewBy("Director");
|
||||
const writers = crewBy("Writer");
|
||||
|
||||
return (
|
||||
<p key={job} className="text-muted-foreground">
|
||||
{job === "Director" ? "Directed by" : "Written by"}{" "}
|
||||
{people.map((p, i) => (
|
||||
<div className="animate-page-enter">
|
||||
<DetailHero backdrop={backdrop}>
|
||||
<div className="max-w-3xl 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>
|
||||
<Link to={`/entry/${entryId}/season/${seasonId}`}>
|
||||
<HeroChip>Season {seasonNumber ?? "?"}</HeroChip>
|
||||
</Link>
|
||||
<span className="rounded border border-foreground/30 px-1.5 py-px text-xs font-semibold tracking-wide tabular-nums">
|
||||
S{pad(seasonNumber)}E{pad(episode.episode_number)}
|
||||
</span>
|
||||
{episode.episode_type === "finale" && (
|
||||
<span className="rounded bg-violet-500/15 px-1.5 py-px text-xs font-semibold uppercase text-violet-600 dark:text-violet-400">
|
||||
Finale
|
||||
</span>
|
||||
)}
|
||||
{upcoming && (
|
||||
<span className="rounded bg-sky-500/15 px-1.5 py-px text-xs font-semibold uppercase text-sky-600 dark:text-sky-400">
|
||||
Upcoming
|
||||
</span>
|
||||
)}
|
||||
{watched && (
|
||||
<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" /> Watched
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h1 className="select-text text-4xl font-extrabold leading-[1.05] tracking-tight text-balance sm:text-5xl">
|
||||
{episode.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">
|
||||
{episode.air_date && (
|
||||
<span className="font-medium text-foreground/90">
|
||||
{formatDate(episode.air_date)}
|
||||
</span>
|
||||
)}
|
||||
{episode.runtime ? (
|
||||
<MetaItem>{formatRuntime(episode.runtime)}</MetaItem>
|
||||
) : null}
|
||||
{episode.tmdb_rating ? (
|
||||
<MetaItem>
|
||||
<span className="inline-flex items-center gap-1 tabular-nums">
|
||||
<Star className="h-3.5 w-3.5 fill-yellow-400 text-yellow-400" />
|
||||
{episode.tmdb_rating.toFixed(1)}
|
||||
{episode.tmdb_vote_count ? (
|
||||
<span className="text-xs">
|
||||
({episode.tmdb_vote_count} votes)
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</MetaItem>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
|
||||
<Button
|
||||
size="lg"
|
||||
className="h-11 gap-2 px-6"
|
||||
onClick={watchEpisode}
|
||||
disabled={!canPlay}
|
||||
>
|
||||
<Play className="h-4 w-4 fill-current" />
|
||||
Watch episode
|
||||
</Button>
|
||||
<Button
|
||||
size="lg"
|
||||
variant="outline"
|
||||
className="h-11 gap-2 border-border/60 bg-background/60 px-5 backdrop-blur"
|
||||
onClick={() => setShowAddDialog(true)}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
{watched ? "Watch again" : "Mark as watched"}
|
||||
</Button>
|
||||
{prevEpisode && (
|
||||
<IconLink
|
||||
to={episodeHref(prevEpisode)}
|
||||
label={`Previous: E${prevEpisode.episode_number}`}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</IconLink>
|
||||
)}
|
||||
{nextEpisode && (
|
||||
<IconLink
|
||||
to={episodeHref(nextEpisode)}
|
||||
label={`Next: E${nextEpisode.episode_number}`}
|
||||
>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</IconLink>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</DetailHero>
|
||||
|
||||
<div className="mx-auto mt-4 grid max-w-6xl gap-10 lg:grid-cols-[minmax(0,1fr)_300px]">
|
||||
<div className="min-w-0 space-y-10">
|
||||
{(episode.overview || directors.length > 0 || writers.length > 0) && (
|
||||
<DetailSection title="Overview">
|
||||
{episode.overview && (
|
||||
<p className="select-text max-w-prose text-[15px] leading-relaxed text-foreground/85">
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
{(directors.length > 0 || writers.length > 0) && (
|
||||
<div className="space-y-1 text-sm">
|
||||
{[
|
||||
{ label: "Directed by", people: directors },
|
||||
{ label: "Written by", people: writers },
|
||||
]
|
||||
.filter((g) => g.people.length > 0)
|
||||
.map((g) => (
|
||||
<p key={g.label} className="text-muted-foreground">
|
||||
{g.label}{" "}
|
||||
{g.people.map((p, i) => (
|
||||
<span key={p.id}>
|
||||
{i > 0 && ", "}
|
||||
<Link
|
||||
@@ -218,27 +287,20 @@ export function EpisodePage() {
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DetailSection>
|
||||
)}
|
||||
|
||||
{/* Guest Stars (stored from TMDB; link to their TMDB person page) */}
|
||||
{episode.guest_stars && episode.guest_stars.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<CastList
|
||||
title="Guest Stars"
|
||||
credits={episode.guest_stars.map(toGuestCredit)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Watch History */}
|
||||
{watchHistory.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<EpisodeWatchHistory
|
||||
watchHistory={watchHistory}
|
||||
onEdit={(id) => {
|
||||
@@ -248,50 +310,108 @@ export function EpisodePage() {
|
||||
}}
|
||||
onDelete={(id) => setDeleteTarget(id)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Prev / Next navigation */}
|
||||
<Separator />
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
{/* Prev / Next */}
|
||||
{(prevEpisode || nextEpisode) && (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{prevEpisode ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-1 max-w-60"
|
||||
onClick={() =>
|
||||
navigate(
|
||||
`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`,
|
||||
)
|
||||
}
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4 shrink-0" />
|
||||
<span className="truncate">
|
||||
E{prevEpisode.episode_number}: {prevEpisode.name}
|
||||
</span>
|
||||
</Button>
|
||||
<NeighbourCard
|
||||
episode={prevEpisode}
|
||||
href={episodeHref(prevEpisode)}
|
||||
direction="prev"
|
||||
/>
|
||||
) : (
|
||||
<div />
|
||||
<div className="hidden sm:block" />
|
||||
)}
|
||||
{nextEpisode ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-1 max-w-60 ml-auto"
|
||||
onClick={() =>
|
||||
navigate(
|
||||
`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`,
|
||||
)
|
||||
}
|
||||
{nextEpisode && (
|
||||
<NeighbourCard
|
||||
episode={nextEpisode}
|
||||
href={episodeHref(nextEpisode)}
|
||||
direction="next"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<aside className="space-y-4 lg:sticky lg:top-6 lg:self-start">
|
||||
<DetailCard title="Details">
|
||||
<dl className="space-y-2.5">
|
||||
{episode.air_date && (
|
||||
<DetailRow icon={<CalendarDays />} label="Aired">
|
||||
{formatDate(episode.air_date)}
|
||||
</DetailRow>
|
||||
)}
|
||||
{episode.runtime ? (
|
||||
<DetailRow icon={<Clock />} label="Runtime">
|
||||
{formatRuntime(episode.runtime)}
|
||||
</DetailRow>
|
||||
) : null}
|
||||
{episode.tmdb_rating ? (
|
||||
<DetailRow icon={<Star />} label="TMDB">
|
||||
{episode.tmdb_rating.toFixed(1)}/10
|
||||
</DetailRow>
|
||||
) : null}
|
||||
{episode.production_code && (
|
||||
<DetailRow icon={<Hash />} label="Prod. code">
|
||||
{episode.production_code}
|
||||
</DetailRow>
|
||||
)}
|
||||
<DetailRow icon={<Eye />} 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"}
|
||||
</DetailRow>
|
||||
</dl>
|
||||
</DetailCard>
|
||||
|
||||
{episodes.length > 1 && (
|
||||
<DetailCard title={`Season ${seasonNumber ?? ""} episodes`}>
|
||||
<ol className="-mx-1 max-h-96 space-y-0.5 overflow-y-auto">
|
||||
{episodes.map((ep) => {
|
||||
const current = ep.id === episode.id;
|
||||
return (
|
||||
<li key={ep.id}>
|
||||
<Link
|
||||
to={episodeHref(ep)}
|
||||
aria-current={current ? "page" : undefined}
|
||||
className={`flex items-center gap-2 rounded-md px-1.5 py-1.5 text-sm transition-colors ${
|
||||
current
|
||||
? "bg-accent font-semibold"
|
||||
: "hover:bg-accent/50"
|
||||
}`}
|
||||
>
|
||||
<span className="truncate">
|
||||
E{nextEpisode.episode_number}: {nextEpisode.name}
|
||||
<span className="w-7 shrink-0 text-xs text-muted-foreground tabular-nums">
|
||||
E{ep.episode_number}
|
||||
</span>
|
||||
<ChevronRight className="h-4 w-4 shrink-0" />
|
||||
</Button>
|
||||
) : (
|
||||
<div />
|
||||
<span className="line-clamp-1 flex-1">{ep.name}</span>
|
||||
{isEpisodeWatched(ep) && (
|
||||
<CheckCircle2 className="h-3.5 w-3.5 shrink-0 text-green-500" />
|
||||
)}
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}`}
|
||||
className="mt-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ListVideo className="h-3 w-3" /> Open season
|
||||
</Link>
|
||||
</DetailCard>
|
||||
)}
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
{/* 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() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NeighbourCard({
|
||||
episode,
|
||||
href,
|
||||
direction,
|
||||
}: {
|
||||
episode: Episode;
|
||||
href: string;
|
||||
direction: "prev" | "next";
|
||||
}) {
|
||||
return (
|
||||
<Link
|
||||
to={href}
|
||||
className={`group flex items-center gap-3 rounded-xl border border-border/60 bg-card/50 p-2 transition-colors hover:bg-accent/40 ${
|
||||
direction === "next" ? "flex-row-reverse text-right" : ""
|
||||
}`}
|
||||
>
|
||||
<div className="h-16 w-28 shrink-0 overflow-hidden rounded-lg bg-muted">
|
||||
{episode.still_path && (
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, "w300")}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-cover transition-transform group-hover:scale-[1.04]"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="inline-flex items-center gap-1 text-xs text-muted-foreground">
|
||||
{direction === "prev" && <ChevronLeft className="h-3 w-3" />}
|
||||
{direction === "prev" ? "Previous" : "Next"} · E
|
||||
{episode.episode_number}
|
||||
{direction === "next" && <ChevronRight className="h-3 w-3" />}
|
||||
</p>
|
||||
<p className="line-clamp-1 font-medium">{episode.name}</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -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,71 +100,159 @@ 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}
|
||||
<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"
|
||||
/>
|
||||
|
||||
<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>
|
||||
|
||||
{/* 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>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="outline"
|
||||
className="shrink-0 self-end sm:self-start"
|
||||
<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"
|
||||
>
|
||||
<Ellipsis className="h-4 w-4" />
|
||||
<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="lg"
|
||||
className="h-11 gap-2 px-6"
|
||||
onClick={() => handleWatchEpisode(nextUp)}
|
||||
disabled={!entry?.entryIds?.tmdb_id}
|
||||
>
|
||||
<Play className="h-4 w-4 fill-current" />
|
||||
{watchedCount > 0 ? "Continue" : "Start"}: E
|
||||
{nextUp.episode_number}
|
||||
</Button>
|
||||
)}
|
||||
<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"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</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}
|
||||
@@ -147,173 +260,39 @@ export function SeasonPage() {
|
||||
<RefreshCw
|
||||
className={`mr-2 h-4 w-4 ${refreshSeason.isPending ? "animate-spin" : ""}`}
|
||||
/>
|
||||
Refresh Season
|
||||
{refreshSeason.isPending
|
||||
? "Refreshing..."
|
||||
: "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>
|
||||
</div>
|
||||
|
||||
{/* 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>
|
||||
</DetailHero>
|
||||
|
||||
<div className="mx-auto mt-4 max-w-6xl space-y-10">
|
||||
{season.overview && (
|
||||
<p className="text-sm text-muted-foreground max-w-lg">
|
||||
<DetailSection title="Overview">
|
||||
<p className="select-text max-w-prose text-[15px] leading-relaxed text-foreground/85">
|
||||
{season.overview}
|
||||
</p>
|
||||
</DetailSection>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 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"
|
||||
<DetailSection
|
||||
title="Episodes"
|
||||
action={<EpisodeViewToggle view={view} onChange={changeView} />}
|
||||
>
|
||||
{/* 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"
|
||||
<SeasonEpisodes
|
||||
episodes={episodes}
|
||||
view={view}
|
||||
entryId={entryIdNum}
|
||||
seasonId={seasonIdNum}
|
||||
onPlay={handleWatchEpisode}
|
||||
onMarkWatched={setDialogEpisode}
|
||||
/>
|
||||
) : (
|
||||
<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>
|
||||
</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}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Streaming dialog */}
|
||||
{entry && streamingOpen && (
|
||||
|
||||
Reference in new issue
Block a user