Redesign season and episode pages, add list/card views
This commit is contained in:
1 parent
d0cd1cd94b
commit
be248d7513
6 files changed
+1376
-538
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user