- Add TmdbPreviewPage showing TMDB details without adding to library - Display backdrop, poster, title, tagline, genres, rating, storyline - Show season/episode count for TV series - Add "Add to Library" button that creates entry then redirects to details page - Show "Already in Library — View" if entry exists in DB - Add /entry/tmdb/:type/:tmdbId route in router.tsx - Add TmdbPreview type, entriesApi.previewTmdb(), and useTmdbPreview() hook - Update EntryCard to navigate to preview page instead of auto-adding Co-authored-by: Copilot <copilot@github.com>
241 lines
9.4 KiB
TypeScript
241 lines
9.4 KiB
TypeScript
import { useState } from 'react';
|
|
import { useParams, Link } from 'react-router-dom';
|
|
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
|
|
|
|
import { useLibraryStore } from '@/stores/useLibraryStore';
|
|
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
|
import { MarkSeasonWatchedDialog } from '@/components/dialogs/MarkSeasonWatchedDialog';
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
|
import { Progress } from '@/components/ui/progress';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Eye, CheckCircle2, ListChecks } 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';
|
|
|
|
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 entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
|
|
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
|
|
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
|
|
|
|
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>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const watchedCount = episodes.filter(
|
|
(ep: Episode) =>
|
|
ep.date_first_seen ||
|
|
(ep.episodeSeens && ep.episodeSeens.length > 0)
|
|
).length;
|
|
const totalEpisodes = episodes.length;
|
|
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
|
|
|
|
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">
|
|
<Link
|
|
to={`/entry/${entryId}`}
|
|
className="hover:text-foreground transition-colors truncate max-w-50"
|
|
>
|
|
{entryTitle || 'Entry'}
|
|
</Link>
|
|
<span>/</span>
|
|
<span className="text-foreground font-medium">Season {season.season_number}</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>
|
|
{/* Mark Season as Watched — top right */}
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
className="shrink-0 w-full sm:w-auto"
|
|
onClick={() => setShowMarkAllDialog(true)}
|
|
>
|
|
<ListChecks className="mr-1.5 h-4 w-4" />
|
|
Mark Season Watched
|
|
</Button>
|
|
</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>
|
|
|
|
{/* Watch progress */}
|
|
<div className="flex items-center gap-3 max-w-xs">
|
|
<Progress value={progress} className="flex-1 h-2" />
|
|
<span className="text-sm font-medium">
|
|
{watchedCount}/{totalEpisodes}
|
|
</span>
|
|
</div>
|
|
|
|
{season.overview && (
|
|
<p className="text-sm text-muted-foreground max-w-lg">
|
|
{season.overview}
|
|
</p>
|
|
)}
|
|
</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"
|
|
>
|
|
{/* Thumbnail */}
|
|
<div className="h-14 w-24 shrink-0 overflow-hidden rounded bg-muted sm:h-16 sm:w-28">
|
|
{episode.still_path ? (
|
|
<img
|
|
src={getTmdbPosterUrl(episode.still_path, 'w300')}
|
|
alt={episode.name}
|
|
className="h-full w-full object-cover"
|
|
loading="lazy"
|
|
/>
|
|
) : (
|
|
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
|
|
No Image
|
|
</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>
|
|
</div>
|
|
|
|
{/* Episode Seen Dialog */}
|
|
{dialogEpisode && (
|
|
<EpisodeSeenEditDialog
|
|
open={!!dialogEpisode}
|
|
onOpenChange={(open) => { if (!open) setDialogEpisode(null); }}
|
|
mode="create"
|
|
episodeId={dialogEpisode.id}
|
|
entryId={parseInt(entryId!, 10)}
|
|
seasonId={parseInt(seasonId!, 10)}
|
|
/>
|
|
)}
|
|
|
|
{/* Mark Season Watched dialog */}
|
|
<MarkSeasonWatchedDialog
|
|
open={showMarkAllDialog}
|
|
onOpenChange={setShowMarkAllDialog}
|
|
entryId={parseInt(entryId!, 10)}
|
|
seasonId={parseInt(seasonId!, 10)}
|
|
episodes={episodes}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|