- Entry details page now also renders entries not in the library, using the TMDB preview mapped to the same entry shape; remove TmdbPreviewPage - Preview endpoint returns an entry-shaped object, TMDB seasons and directors - Artwork section: TMDB posters, backdrops and logos merged with the media table, with in-library badges, language filter and add-to-library - Record tmdb_path on downloaded media so TMDB images can be matched - Recommendations by TMDB id for entries not in the library
1255 lines
44 KiB
TypeScript
1255 lines
44 KiB
TypeScript
import { useState, useEffect, type ReactNode } from "react";
|
||
import { useParams, Link, useNavigate } from "react-router-dom";
|
||
import {
|
||
useEntry,
|
||
useEntrySeasons,
|
||
useRefreshEntry,
|
||
useEntryCredits,
|
||
useTmdbPreview,
|
||
useCreateEntry,
|
||
} from "@/hooks/useEntries";
|
||
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
||
import { useCollections } from "@/hooks/useCollections";
|
||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
||
import { Button } from "@/components/ui/button";
|
||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||
import {
|
||
DropdownMenu,
|
||
DropdownMenuContent,
|
||
DropdownMenuItem,
|
||
DropdownMenuSeparator,
|
||
DropdownMenuTrigger,
|
||
} from "@/components/ui/dropdown-menu";
|
||
import {
|
||
Heart,
|
||
MoreHorizontal,
|
||
Eye,
|
||
EyeOff,
|
||
RefreshCw,
|
||
FolderPlus,
|
||
ImageIcon,
|
||
Settings,
|
||
Star,
|
||
History,
|
||
Trash2,
|
||
ExternalLink,
|
||
Play,
|
||
BookmarkCheck,
|
||
Film,
|
||
Tv,
|
||
Clock,
|
||
CalendarDays,
|
||
Globe,
|
||
Languages,
|
||
Building2,
|
||
DollarSign,
|
||
ListVideo,
|
||
CircleDot,
|
||
Plus,
|
||
Loader2,
|
||
} from "lucide-react";
|
||
import {
|
||
Tooltip,
|
||
TooltipContent,
|
||
TooltipTrigger,
|
||
} from "@/components/ui/tooltip";
|
||
import { CastList } from "@/components/entries/CastList";
|
||
import { SeasonsContainer } from "@/components/entries/SeasonsContainer";
|
||
import { StreamingSection } from "@/components/streaming/StreamingSection";
|
||
import { WatchProvidersCard } from "@/components/entries/WatchProvidersCard";
|
||
import { TrailerDialog } from "@/components/entries/TrailerDialog";
|
||
import { RecommendationsSection } from "@/components/entries/RecommendationsSection";
|
||
import { ArtworkSection } from "@/components/entries/ArtworkSection";
|
||
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
||
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
||
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
||
import { AddEntryToCollectionDialog } from "@/components/dialogs/AddEntryToCollectionDialog";
|
||
import { RatingDialog } from "@/components/dialogs/RatingDialog";
|
||
import { MovieWatchHistoryDialog } from "@/components/dialogs/MovieWatchHistoryDialog";
|
||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||
import {
|
||
Dialog,
|
||
DialogContent,
|
||
DialogHeader,
|
||
DialogTitle,
|
||
} from "@/components/ui/dialog";
|
||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
||
import { getTmdbImageUrl } from "@/lib/api";
|
||
import {
|
||
getPosterUrl,
|
||
getFullPosterUrl,
|
||
getBackdropUrl,
|
||
getCollectionBackdropUrl,
|
||
getYear,
|
||
formatRuntime,
|
||
formatDate,
|
||
} from "@/lib/media-utils";
|
||
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
|
||
import type {
|
||
Collection,
|
||
Credit,
|
||
Entry,
|
||
EntrySeen,
|
||
TmdbPreviewSeason,
|
||
} from "@/types";
|
||
|
||
const WATCH_STATUSES = [
|
||
{
|
||
value: "plan_to_watch",
|
||
label: "Plan to Watch",
|
||
color:
|
||
"bg-slate-500/15 border-slate-500/30 text-slate-600 dark:text-slate-300",
|
||
},
|
||
{
|
||
value: "watching",
|
||
label: "Watching",
|
||
color: "bg-blue-500/15 border-blue-500/30 text-blue-600 dark:text-blue-300",
|
||
},
|
||
{
|
||
value: "completed",
|
||
label: "Completed",
|
||
color:
|
||
"bg-green-500/15 border-green-500/30 text-green-600 dark:text-green-300",
|
||
},
|
||
{
|
||
value: "on_hold",
|
||
label: "On Hold",
|
||
color:
|
||
"bg-amber-500/15 border-amber-500/30 text-amber-600 dark:text-amber-300",
|
||
},
|
||
{
|
||
value: "dropped",
|
||
label: "Dropped",
|
||
color: "bg-red-500/15 border-red-500/30 text-red-600 dark:text-red-300",
|
||
},
|
||
];
|
||
|
||
function getWatchStatusInfo(value: string | null | undefined) {
|
||
return WATCH_STATUSES.find((s) => s.value === value);
|
||
}
|
||
|
||
const formatMoney = (value: number) =>
|
||
new Intl.NumberFormat("en-US", {
|
||
style: "currency",
|
||
currency: "USD",
|
||
notation: "compact",
|
||
maximumFractionDigits: 1,
|
||
}).format(value);
|
||
|
||
const formatCount = (value: number) =>
|
||
new Intl.NumberFormat("en-US", { notation: "compact" }).format(value);
|
||
|
||
const languageName = (() => {
|
||
try {
|
||
const names = new Intl.DisplayNames(["en"], { type: "language" });
|
||
return (code: string) => names.of(code) ?? code;
|
||
} catch {
|
||
return (code: string) => code;
|
||
}
|
||
})();
|
||
|
||
/**
|
||
* Entry details for both sources:
|
||
* - `/entry/:id`: a library entry, loaded from the local DB.
|
||
* - `/entry/tmdb/:type/:tmdbId`: not in the library; everything comes from
|
||
* the TMDB preview (same shape), and library-only actions are hidden. If
|
||
* the title is already in the library, redirect to its page.
|
||
*/
|
||
export function EntryDetailsPage() {
|
||
const { id, type, tmdbId } = useParams<{
|
||
id?: string;
|
||
type?: string;
|
||
tmdbId?: string;
|
||
}>();
|
||
const entryId = id ? parseInt(id, 10) : 0;
|
||
const isLibrary = !!entryId;
|
||
const previewTmdbId = !isLibrary && tmdbId ? parseInt(tmdbId, 10) : 0;
|
||
const previewType = type === "tv" ? "tv" : "movie";
|
||
const navigate = useNavigate();
|
||
|
||
// Library queries are disabled when entryId is 0, the preview when tmdbId is 0
|
||
const { data: entry, isLoading } = useEntry(entryId);
|
||
const { data: seasons } = useEntrySeasons(entryId);
|
||
const { data: allCredits = [] } = useEntryCredits(entryId);
|
||
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
|
||
const {
|
||
data: preview,
|
||
isLoading: previewLoading,
|
||
isError: previewError,
|
||
} = useTmdbPreview(previewTmdbId, previewType);
|
||
const updateEntry = useUpdateEntry();
|
||
const refreshEntry = useRefreshEntry();
|
||
const deleteEntrySeen = useDeleteEntrySeen();
|
||
const deleteEntry = useDeleteEntry();
|
||
const createEntry = useCreateEntry();
|
||
|
||
// Merge library entry with detail entry so we get both library flags AND full details (credits, etc.)
|
||
const libraryEntry = useLibraryStore((s) => s.entries.get(entryId));
|
||
const libraryMatch = useLibraryStore((s) => {
|
||
if (!previewTmdbId) return null;
|
||
for (const le of s.entries.values()) {
|
||
if (le.entryIds?.tmdb_id === previewTmdbId) return le;
|
||
}
|
||
return null;
|
||
});
|
||
const displayEntry: Entry | undefined = isLibrary
|
||
? libraryEntry && entry
|
||
? { ...libraryEntry, ...entry, isInLibrary: true }
|
||
: entry || libraryEntry
|
||
: preview?.entry;
|
||
|
||
// Already in the library: show the library page instead of the preview
|
||
useEffect(() => {
|
||
if (libraryMatch) navigate(`/entry/${libraryMatch.id}`, { replace: true });
|
||
}, [libraryMatch, navigate]);
|
||
|
||
const [showSettings, setShowSettings] = useState(false);
|
||
const [showSeenDialog, setShowSeenDialog] = useState(false);
|
||
const [showMediaDialog, setShowMediaDialog] = useState(false);
|
||
const [showCollectionDialog, setShowCollectionDialog] = useState(false);
|
||
const [showRatingDialog, setShowRatingDialog] = useState(false);
|
||
const [showWatchHistoryDialog, setShowWatchHistoryDialog] = useState(false);
|
||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||
const [showStatusDialog, setShowStatusDialog] = useState(false);
|
||
const [showPosterDialog, setShowPosterDialog] = useState(false);
|
||
const [showTrailer, setShowTrailer] = useState(false);
|
||
const [editSeenRecord, setEditSeenRecord] = useState<EntrySeen | null>(null);
|
||
|
||
// Track recently viewed for command palette
|
||
const addRecentlyViewed = useCommandPaletteStore((s) => s.addRecentlyViewed);
|
||
useEffect(() => {
|
||
if (displayEntry) {
|
||
addRecentlyViewed({
|
||
id: isLibrary ? `lib-${entryId}` : `tmdb-${previewTmdbId}`,
|
||
title: displayEntry.title,
|
||
type: displayEntry.is_tvseries ? "tv" : "movie",
|
||
poster_path: displayEntry.poster_path,
|
||
libraryId: isLibrary ? entryId : undefined,
|
||
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
|
||
});
|
||
}
|
||
}, [entryId, previewTmdbId, displayEntry?.title]);
|
||
|
||
if (!isLibrary && previewError) {
|
||
return (
|
||
<div className="flex flex-col items-center justify-center gap-4 py-20">
|
||
<p className="text-muted-foreground">Could not load entry from TMDB.</p>
|
||
<Button variant="outline" onClick={() => navigate(-1)}>
|
||
Go back
|
||
</Button>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
if (
|
||
(isLibrary ? isLoading : previewLoading) ||
|
||
!displayEntry ||
|
||
libraryMatch
|
||
) {
|
||
return <EntryDetailsSkeleton />;
|
||
}
|
||
|
||
const e = displayEntry;
|
||
// Library: useEntryCredits (allCredits) includes both cast AND crew (director);
|
||
// e.credits from useEntry is a limited preview (10 items).
|
||
// Preview: the TMDB preview's cast + directors, linked by TMDB id.
|
||
const credits: Credit[] = isLibrary
|
||
? allCredits.length > 0
|
||
? allCredits
|
||
: e.credits || []
|
||
: ((preview?.credits ?? []) as unknown as Credit[]);
|
||
const previewSeasons = isLibrary ? [] : (preview?.seasons ?? []);
|
||
const seasonCount = isLibrary
|
||
? (seasons?.length ?? 0)
|
||
: previewSeasons.length;
|
||
const tmdbType = e.is_tvseries ? "tv" : "movie";
|
||
|
||
const addToLibrary = () => {
|
||
createEntry.mutate(
|
||
{ tmdb_id: previewTmdbId, is_tvserie: e.is_tvseries },
|
||
{
|
||
onSuccess: (newEntry) =>
|
||
navigate(`/entry/${newEntry.id}`, { replace: true }),
|
||
},
|
||
);
|
||
};
|
||
const backdrop = getBackdropUrl(e);
|
||
const poster = getPosterUrl(e);
|
||
const director = credits.find(
|
||
(c) => c.cast_type === "crew" && c.job === "Director",
|
||
);
|
||
const watchStatus = e.is_tvseries
|
||
? getWatchStatusInfo(e.watch_status)
|
||
: undefined;
|
||
const userRating = e.entryRatings?.user_rating ?? 0;
|
||
const videos = e.tmdb_videos ?? [];
|
||
const nextEpisode = e.is_tvseries ? e.next_episode_to_air : null;
|
||
const socialLinks = [
|
||
e.homepage && { label: "Website", href: e.homepage },
|
||
e.entryIds?.wikidata_id && {
|
||
label: "Wikidata",
|
||
href: `https://www.wikidata.org/wiki/${e.entryIds.wikidata_id}`,
|
||
},
|
||
e.entryIds?.instagram_id && {
|
||
label: "Instagram",
|
||
href: `https://www.instagram.com/${e.entryIds.instagram_id}`,
|
||
},
|
||
e.entryIds?.twitter_id && {
|
||
label: "X",
|
||
href: `https://x.com/${e.entryIds.twitter_id}`,
|
||
},
|
||
e.entryIds?.facebook_id && {
|
||
label: "Facebook",
|
||
href: `https://www.facebook.com/${e.entryIds.facebook_id}`,
|
||
},
|
||
].filter(Boolean) as { label: string; href: string }[];
|
||
const lastSeen =
|
||
watchHistory
|
||
.map((wh) => wh.date_seen)
|
||
.filter(Boolean)
|
||
.sort()
|
||
.at(-1) ?? null;
|
||
|
||
const toggleFavorite = () => {
|
||
updateEntry.mutate({ id: e.id, data: { favorit: !e.favorit } });
|
||
};
|
||
|
||
return (
|
||
<div className="animate-page-enter">
|
||
{/* ── Hero ── */}
|
||
<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" />
|
||
)}
|
||
{/* Fade into the page at the bottom and behind the text on the left */}
|
||
<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-28 md:px-6 sm:pt-44">
|
||
<div className="flex flex-col items-center gap-6 sm:flex-row sm:items-end sm:gap-8">
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowPosterDialog(true)}
|
||
className="group relative w-40 shrink-0 cursor-zoom-in rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:w-52 lg:w-60"
|
||
aria-label="View full-size poster"
|
||
>
|
||
<img
|
||
src={poster}
|
||
alt={e.title}
|
||
className="aspect-2/3 w-full rounded-xl object-cover shadow-2xl shadow-black/50 ring-1 ring-white/10 transition-transform duration-300 group-hover:scale-[1.02]"
|
||
/>
|
||
</button>
|
||
|
||
<div className="min-w-0 flex-1 space-y-4 text-center sm:text-left">
|
||
{/* Eyebrow: type + status */}
|
||
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
|
||
<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">
|
||
{e.is_tvseries ? (
|
||
<Tv className="h-3 w-3" />
|
||
) : (
|
||
<Film className="h-3 w-3" />
|
||
)}
|
||
{e.is_tvseries ? "TV Series" : "Movie"}
|
||
</span>
|
||
{e.certification && (
|
||
<span className="rounded border border-foreground/30 px-1.5 py-px text-xs font-semibold tracking-wide text-foreground/90">
|
||
{e.certification}
|
||
</span>
|
||
)}
|
||
{e.is_tvseries && e.status && (
|
||
<span className="rounded-full border border-border/60 bg-background/60 px-2.5 py-0.5 text-xs font-medium text-muted-foreground backdrop-blur">
|
||
{e.status}
|
||
</span>
|
||
)}
|
||
{e.is_tvseries && isLibrary && (
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowStatusDialog(true)}
|
||
className={`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-xs font-medium transition-colors ${
|
||
watchStatus?.color ??
|
||
"border-dashed border-border text-muted-foreground hover:text-foreground"
|
||
}`}
|
||
>
|
||
<BookmarkCheck className="h-3 w-3" />
|
||
{watchStatus?.label ?? "Set status"}
|
||
</button>
|
||
)}
|
||
</div>
|
||
|
||
<div className="space-y-1.5">
|
||
<h1 className="select-text text-4xl font-extrabold leading-[1.05] tracking-tight text-balance sm:text-5xl">
|
||
{e.title}
|
||
</h1>
|
||
{e.tagline && (
|
||
<p className="select-text text-base italic text-foreground/70">
|
||
{e.tagline}
|
||
</p>
|
||
)}
|
||
{e.original_title && e.original_title !== e.title && (
|
||
<p className="select-text text-sm text-muted-foreground italic">
|
||
{e.original_title}
|
||
</p>
|
||
)}
|
||
</div>
|
||
|
||
{/* Meta */}
|
||
<div className="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 text-sm text-muted-foreground sm:justify-start">
|
||
{e.release_date && (
|
||
<Tooltip>
|
||
<TooltipTrigger
|
||
render={
|
||
<span className="cursor-default font-medium text-foreground/90" />
|
||
}
|
||
>
|
||
{getYear(e.release_date)}
|
||
</TooltipTrigger>
|
||
<TooltipContent>
|
||
{formatDate(e.release_date)}
|
||
</TooltipContent>
|
||
</Tooltip>
|
||
)}
|
||
{e.runtime && !e.is_tvseries && (
|
||
<MetaItem>{formatRuntime(e.runtime)}</MetaItem>
|
||
)}
|
||
{e.is_tvseries && seasonCount > 0 && (
|
||
<MetaItem>
|
||
{seasonCount} {seasonCount === 1 ? "season" : "seasons"}
|
||
</MetaItem>
|
||
)}
|
||
{e.is_tvseries && e.created_by && e.created_by.length > 0 && (
|
||
<MetaItem>
|
||
Created by{" "}
|
||
{e.created_by.map((c, i) => (
|
||
<span key={c.id}>
|
||
{i > 0 && ", "}
|
||
<Link
|
||
to={`/people/tmdb/${c.id}`}
|
||
className="font-medium text-foreground hover:underline"
|
||
>
|
||
{c.name}
|
||
</Link>
|
||
</span>
|
||
))}
|
||
</MetaItem>
|
||
)}
|
||
{director?.people?.name && (
|
||
<MetaItem>
|
||
Directed by{" "}
|
||
<Link
|
||
to={
|
||
isLibrary
|
||
? `/people/${director.people_id}`
|
||
: `/people/tmdb/${director.people_id}`
|
||
}
|
||
className="font-medium text-foreground hover:underline"
|
||
>
|
||
{director.people.name}
|
||
</Link>
|
||
</MetaItem>
|
||
)}
|
||
</div>
|
||
|
||
{/* Genres */}
|
||
{e.genres && e.genres.length > 0 && (
|
||
<div className="flex flex-wrap justify-center gap-1.5 sm:justify-start">
|
||
{e.genres.map((g) => (
|
||
<Link
|
||
key={g.id}
|
||
to={`/library?genre=${encodeURIComponent(g.name)}`}
|
||
className="rounded-full bg-foreground/5 px-3 py-1 text-xs font-medium text-foreground/80 ring-1 ring-border/60 backdrop-blur transition-colors hover:bg-foreground/10 hover:text-foreground"
|
||
>
|
||
{g.name}
|
||
</Link>
|
||
))}
|
||
</div>
|
||
)}
|
||
|
||
{/* Actions */}
|
||
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
|
||
{isLibrary ? (
|
||
<StreamingSection entry={e} seasons={seasons} />
|
||
) : (
|
||
<Button
|
||
size="lg"
|
||
onClick={addToLibrary}
|
||
disabled={createEntry.isPending}
|
||
className="h-11 gap-2 px-6 text-sm font-medium"
|
||
>
|
||
{createEntry.isPending ? (
|
||
<Loader2 className="h-4 w-4 animate-spin" />
|
||
) : (
|
||
<Plus className="h-4 w-4" />
|
||
)}
|
||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||
</Button>
|
||
)}
|
||
{videos.length > 0 ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowTrailer(true)}
|
||
className="inline-flex h-11 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-5 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
|
||
>
|
||
<Play className="h-4 w-4" />
|
||
Trailer
|
||
</button>
|
||
) : (
|
||
<a
|
||
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className="inline-flex h-11 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-5 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
|
||
>
|
||
<Play className="h-4 w-4" />
|
||
Trailer
|
||
</a>
|
||
)}
|
||
|
||
{isLibrary && (
|
||
<div className="flex items-center gap-1.5">
|
||
<IconAction
|
||
label="Mark as watched"
|
||
onClick={() => setShowSeenDialog(true)}
|
||
>
|
||
<Eye className="h-4 w-4" />
|
||
</IconAction>
|
||
<IconAction
|
||
label={userRating > 0 ? "Change rating" : "Rate this"}
|
||
onClick={() => setShowRatingDialog(true)}
|
||
active={userRating > 0}
|
||
>
|
||
<Star
|
||
className={`h-4 w-4 ${userRating > 0 ? "fill-yellow-400 text-yellow-400" : ""}`}
|
||
/>
|
||
</IconAction>
|
||
<IconAction
|
||
label={
|
||
e.favorit ? "Remove from favorites" : "Add to favorites"
|
||
}
|
||
onClick={toggleFavorite}
|
||
disabled={updateEntry.isPending}
|
||
active={e.favorit}
|
||
>
|
||
<Heart
|
||
className={`h-4 w-4 ${e.favorit ? "fill-red-500 text-red-500" : ""}`}
|
||
/>
|
||
</IconAction>
|
||
<IconAction
|
||
label="Add to collection"
|
||
onClick={() => setShowCollectionDialog(true)}
|
||
>
|
||
<FolderPlus 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-56">
|
||
{e.is_tvseries ? (
|
||
<DropdownMenuItem
|
||
onClick={() => setShowStatusDialog(true)}
|
||
>
|
||
<BookmarkCheck className="mr-2 h-4 w-4" />
|
||
Set status
|
||
</DropdownMenuItem>
|
||
) : (
|
||
<DropdownMenuItem
|
||
onClick={() => setShowWatchHistoryDialog(true)}
|
||
>
|
||
<History className="mr-2 h-4 w-4" />
|
||
Watch history
|
||
</DropdownMenuItem>
|
||
)}
|
||
<DropdownMenuItem
|
||
onClick={() =>
|
||
updateEntry.mutate({
|
||
id: e.id,
|
||
data: { hidden: !e.hidden },
|
||
})
|
||
}
|
||
>
|
||
<EyeOff className="mr-2 h-4 w-4" />
|
||
{e.hidden ? "Unhide" : "Hide"}
|
||
</DropdownMenuItem>
|
||
<DropdownMenuSeparator />
|
||
<DropdownMenuItem
|
||
onClick={() => refreshEntry.mutate(e.id)}
|
||
disabled={refreshEntry.isPending}
|
||
>
|
||
<RefreshCw
|
||
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? "animate-spin" : ""}`}
|
||
/>
|
||
{refreshEntry.isPending
|
||
? "Refreshing..."
|
||
: "Refresh details"}
|
||
</DropdownMenuItem>
|
||
<DropdownMenuItem
|
||
onClick={() => setShowMediaDialog(true)}
|
||
>
|
||
<ImageIcon className="mr-2 h-4 w-4" />
|
||
Manage media
|
||
</DropdownMenuItem>
|
||
<DropdownMenuItem onClick={() => setShowSettings(true)}>
|
||
<Settings className="mr-2 h-4 w-4" />
|
||
Settings
|
||
</DropdownMenuItem>
|
||
<DropdownMenuSeparator />
|
||
<DropdownMenuItem
|
||
className="text-destructive focus:text-destructive"
|
||
onClick={() => setShowDeleteConfirm(true)}
|
||
>
|
||
<Trash2 className="mr-2 h-4 w-4" />
|
||
Delete entry
|
||
</DropdownMenuItem>
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
{/* ── Body ── */}
|
||
<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">
|
||
{e.storyline && (
|
||
<Section title="Overview">
|
||
<p className="select-text max-w-prose text-[15px] leading-relaxed text-foreground/85">
|
||
{e.storyline}
|
||
</p>
|
||
</Section>
|
||
)}
|
||
|
||
{e.keywords && e.keywords.length > 0 && (
|
||
<Section title="Keywords">
|
||
<div className="flex flex-wrap gap-1.5">
|
||
{e.keywords.map((k) => (
|
||
<span
|
||
key={k}
|
||
className="rounded-md bg-muted px-2 py-0.5 text-xs text-muted-foreground"
|
||
>
|
||
{k}
|
||
</span>
|
||
))}
|
||
</div>
|
||
</Section>
|
||
)}
|
||
|
||
{credits.length > 0 && (
|
||
<CastList
|
||
credits={credits}
|
||
entryId={isLibrary ? e.id : undefined}
|
||
isTvSeries={e.is_tvseries}
|
||
maxItems={12}
|
||
allCastHref={
|
||
isLibrary
|
||
? undefined
|
||
: `/entry/tmdb/${tmdbType}/${previewTmdbId}/cast`
|
||
}
|
||
/>
|
||
)}
|
||
|
||
{isLibrary && e.is_tvseries && seasons && seasons.length > 0 && (
|
||
<SeasonsContainer seasons={seasons} entryId={e.id} />
|
||
)}
|
||
{!isLibrary && e.is_tvseries && previewSeasons.length > 0 && (
|
||
<TmdbSeasonsStrip seasons={previewSeasons} />
|
||
)}
|
||
|
||
{isLibrary && <EntryCollectionsSection entryId={e.id} />}
|
||
|
||
<RecommendationsSection
|
||
entryId={isLibrary ? e.id : 0}
|
||
tmdbId={isLibrary ? 0 : previewTmdbId}
|
||
isTvSeries={e.is_tvseries}
|
||
/>
|
||
|
||
<ArtworkSection
|
||
entryId={isLibrary ? e.id : 0}
|
||
tmdbId={isLibrary ? 0 : previewTmdbId}
|
||
isTvSeries={e.is_tvseries}
|
||
originalLanguage={e.original_language}
|
||
/>
|
||
</div>
|
||
|
||
{/* ── Sidebar ── */}
|
||
<aside className="space-y-4 lg:sticky lg:top-6 lg:self-start">
|
||
<div
|
||
className={`grid gap-2 ${isLibrary ? "grid-cols-3" : "grid-cols-2"}`}
|
||
>
|
||
<RatingTile
|
||
label="IMDb"
|
||
value={
|
||
e.entryRatings?.imdb_rating
|
||
? e.entryRatings.imdb_rating.toFixed(1)
|
||
: null
|
||
}
|
||
accent="text-yellow-500"
|
||
/>
|
||
<RatingTile
|
||
label="TMDB"
|
||
value={
|
||
e.entryRatings?.tmdb_rating
|
||
? e.entryRatings.tmdb_rating.toFixed(1)
|
||
: null
|
||
}
|
||
accent="text-sky-500"
|
||
sub={
|
||
e.entryRatings?.tmdb_vote_count
|
||
? `${formatCount(e.entryRatings.tmdb_vote_count)} votes`
|
||
: undefined
|
||
}
|
||
/>
|
||
{isLibrary && (
|
||
<RatingTile
|
||
label="You"
|
||
value={userRating > 0 ? String(userRating) : null}
|
||
accent="text-primary"
|
||
emptyLabel="Rate"
|
||
onClick={() => setShowRatingDialog(true)}
|
||
/>
|
||
)}
|
||
</div>
|
||
|
||
<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">
|
||
Details
|
||
</h3>
|
||
<dl className="space-y-2.5 text-sm">
|
||
{e.release_date && (
|
||
<DetailRow icon={<CalendarDays />} label="Released">
|
||
{formatDate(e.release_date)}
|
||
</DetailRow>
|
||
)}
|
||
{e.runtime && !e.is_tvseries && (
|
||
<DetailRow icon={<Clock />} label="Runtime">
|
||
{formatRuntime(e.runtime)}
|
||
</DetailRow>
|
||
)}
|
||
{e.is_tvseries &&
|
||
(e.number_of_seasons || e.number_of_episodes) && (
|
||
<DetailRow icon={<ListVideo />} label="Episodes">
|
||
{[
|
||
e.number_of_seasons &&
|
||
`${e.number_of_seasons} ${e.number_of_seasons === 1 ? "season" : "seasons"}`,
|
||
e.number_of_episodes && `${e.number_of_episodes} eps`,
|
||
]
|
||
.filter(Boolean)
|
||
.join(" · ")}
|
||
</DetailRow>
|
||
)}
|
||
{e.is_tvseries && e.last_air_date && (
|
||
<DetailRow icon={<CalendarDays />} label="Last aired">
|
||
{formatDate(e.last_air_date)}
|
||
</DetailRow>
|
||
)}
|
||
{nextEpisode && (
|
||
<DetailRow icon={<CircleDot />} label="Next episode">
|
||
<span className="block">
|
||
S{nextEpisode.season_number}E{nextEpisode.episode_number}
|
||
{nextEpisode.air_date &&
|
||
` · ${formatDate(nextEpisode.air_date)}`}
|
||
</span>
|
||
<span className="block text-xs font-normal text-muted-foreground">
|
||
{nextEpisode.name}
|
||
</span>
|
||
</DetailRow>
|
||
)}
|
||
{e.is_tvseries && e.networks && e.networks.length > 0 && (
|
||
<DetailRow icon={<Tv />} label="Network">
|
||
<span className="inline-flex flex-wrap justify-end gap-2">
|
||
{e.networks.map((n) =>
|
||
n.logo_path ? (
|
||
<img
|
||
key={n.id}
|
||
src={getTmdbImageUrl(n.logo_path, "w92")}
|
||
alt={n.name}
|
||
title={n.name}
|
||
className="h-4 max-w-20 object-contain dark:invert dark:brightness-200"
|
||
/>
|
||
) : (
|
||
<span key={n.id}>{n.name}</span>
|
||
),
|
||
)}
|
||
</span>
|
||
</DetailRow>
|
||
)}
|
||
{e.tv_type && (
|
||
<DetailRow icon={<Film />} label="Type">
|
||
{e.tv_type}
|
||
</DetailRow>
|
||
)}
|
||
{e.original_language && (
|
||
<DetailRow icon={<Languages />} label="Language">
|
||
{languageName(e.original_language)}
|
||
</DetailRow>
|
||
)}
|
||
{!e.is_tvseries && e.budget ? (
|
||
<DetailRow icon={<DollarSign />} label="Budget">
|
||
{formatMoney(e.budget)}
|
||
</DetailRow>
|
||
) : null}
|
||
{!e.is_tvseries && e.revenue ? (
|
||
<DetailRow icon={<DollarSign />} label="Box office">
|
||
{formatMoney(e.revenue)}
|
||
</DetailRow>
|
||
) : null}
|
||
{e.production_companies && e.production_companies.length > 0 && (
|
||
<DetailRow icon={<Building2 />} label="Studio">
|
||
{e.production_companies
|
||
.slice(0, 3)
|
||
.map((c) => c.name)
|
||
.join(", ")}
|
||
</DetailRow>
|
||
)}
|
||
{e.country && (
|
||
<DetailRow icon={<Film />} label="Country">
|
||
{e.country}
|
||
</DetailRow>
|
||
)}
|
||
{isLibrary && !e.is_tvseries && (
|
||
<DetailRow icon={<Eye />} label="Watched">
|
||
{watchHistory.length > 0 ? (
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowWatchHistoryDialog(true)}
|
||
className="text-right hover:underline"
|
||
>
|
||
{watchHistory.length === 1
|
||
? formatDate(lastSeen)
|
||
: `${watchHistory.length}× · last ${formatDate(lastSeen)}`}
|
||
</button>
|
||
) : (
|
||
<button
|
||
type="button"
|
||
onClick={() => setShowSeenDialog(true)}
|
||
className="text-muted-foreground hover:text-foreground hover:underline"
|
||
>
|
||
Not yet — mark
|
||
</button>
|
||
)}
|
||
</DetailRow>
|
||
)}
|
||
</dl>
|
||
|
||
{(e.entryIds?.tmdb_id ||
|
||
e.entryIds?.imdb_id ||
|
||
socialLinks.length > 0) && (
|
||
<div className="mt-4 flex flex-wrap gap-2 border-t border-border/60 pt-4">
|
||
{e.entryIds?.tmdb_id && (
|
||
<ExternalChip
|
||
href={`https://www.themoviedb.org/${e.is_tvseries ? "tv" : "movie"}/${e.entryIds.tmdb_id}`}
|
||
>
|
||
TMDB
|
||
</ExternalChip>
|
||
)}
|
||
{e.entryIds?.imdb_id && (
|
||
<ExternalChip
|
||
href={`https://www.imdb.com/title/${e.entryIds.imdb_id}`}
|
||
>
|
||
IMDb
|
||
</ExternalChip>
|
||
)}
|
||
{socialLinks.map((l) => (
|
||
<ExternalChip key={l.label} href={l.href}>
|
||
{l.label === "Website" ? (
|
||
<span className="inline-flex items-center gap-1">
|
||
<Globe className="h-3 w-3" />
|
||
Website
|
||
</span>
|
||
) : (
|
||
l.label
|
||
)}
|
||
</ExternalChip>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<WatchProvidersCard providers={e.watch_providers} />
|
||
</aside>
|
||
</div>
|
||
|
||
{/* Dialogs */}
|
||
{showSettings && (
|
||
<EntrySettingsDialog
|
||
open={showSettings}
|
||
onOpenChange={setShowSettings}
|
||
entry={e}
|
||
/>
|
||
)}
|
||
{showSeenDialog && (
|
||
<EntrySeenDialog
|
||
open={showSeenDialog}
|
||
onOpenChange={setShowSeenDialog}
|
||
entry={e}
|
||
seasons={seasons}
|
||
mode="add"
|
||
/>
|
||
)}
|
||
{showMediaDialog && (
|
||
<EntryMediaDialog
|
||
open={showMediaDialog}
|
||
onOpenChange={setShowMediaDialog}
|
||
entryId={e.id}
|
||
medias={e.medias || []}
|
||
/>
|
||
)}
|
||
{showCollectionDialog && (
|
||
<AddEntryToCollectionDialog
|
||
open={showCollectionDialog}
|
||
onOpenChange={setShowCollectionDialog}
|
||
entryId={e.id}
|
||
/>
|
||
)}
|
||
{showRatingDialog && (
|
||
<RatingDialog
|
||
open={showRatingDialog}
|
||
onOpenChange={setShowRatingDialog}
|
||
entry={e}
|
||
/>
|
||
)}
|
||
{showWatchHistoryDialog && (
|
||
<MovieWatchHistoryDialog
|
||
open={showWatchHistoryDialog}
|
||
onOpenChange={setShowWatchHistoryDialog}
|
||
entryId={e.id}
|
||
watchHistory={watchHistory}
|
||
onDelete={(seenId) =>
|
||
deleteEntrySeen.mutate({ id: seenId, entryId: e.id })
|
||
}
|
||
onEdit={(record) => {
|
||
setEditSeenRecord(record);
|
||
setShowWatchHistoryDialog(false);
|
||
}}
|
||
/>
|
||
)}
|
||
|
||
{editSeenRecord && (
|
||
<EntrySeenDialog
|
||
open={!!editSeenRecord}
|
||
onOpenChange={(open) => {
|
||
if (!open) setEditSeenRecord(null);
|
||
}}
|
||
entry={e}
|
||
seasons={seasons}
|
||
mode="edit"
|
||
editRecord={editSeenRecord}
|
||
/>
|
||
)}
|
||
<ConfirmDialog
|
||
open={showDeleteConfirm}
|
||
onOpenChange={setShowDeleteConfirm}
|
||
title="Delete Entry"
|
||
description={`Are you sure you want to delete "${e.title}" from your library? This action cannot be undone.`}
|
||
confirmLabel="Delete"
|
||
variant="destructive"
|
||
onConfirm={() => {
|
||
deleteEntry.mutate(e.id, {
|
||
onSuccess: () => navigate("/library"),
|
||
});
|
||
setShowDeleteConfirm(false);
|
||
}}
|
||
/>
|
||
|
||
{showTrailer && videos.length > 0 && (
|
||
<TrailerDialog
|
||
open={showTrailer}
|
||
onOpenChange={setShowTrailer}
|
||
title={e.title}
|
||
videos={videos}
|
||
/>
|
||
)}
|
||
|
||
<Dialog open={showPosterDialog} onOpenChange={setShowPosterDialog}>
|
||
<DialogContent className="w-auto max-w-[calc(100%-2rem)] sm:max-w-[calc(100%-2rem)] p-0 bg-transparent ring-0 overflow-hidden">
|
||
<DialogTitle className="sr-only">{e.title} poster</DialogTitle>
|
||
<img
|
||
src={getFullPosterUrl(e)}
|
||
alt={e.title}
|
||
className="max-h-[90vh] max-w-full w-auto rounded-xl object-contain shadow-2xl"
|
||
/>
|
||
</DialogContent>
|
||
</Dialog>
|
||
|
||
<Dialog open={showStatusDialog} onOpenChange={setShowStatusDialog}>
|
||
<DialogContent className="sm:max-w-xs">
|
||
<DialogHeader>
|
||
<DialogTitle>Set Watch Status</DialogTitle>
|
||
</DialogHeader>
|
||
<div className="space-y-1">
|
||
{WATCH_STATUSES.map((s) => (
|
||
<button
|
||
key={s.value}
|
||
onClick={() => {
|
||
updateEntry.mutate({
|
||
id: e.id,
|
||
data: { watch_status: s.value },
|
||
});
|
||
setShowStatusDialog(false);
|
||
}}
|
||
className={`w-full flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-accent ${
|
||
e.watch_status === s.value ? "bg-accent font-medium" : ""
|
||
}`}
|
||
>
|
||
<BookmarkCheck className="h-4 w-4" />
|
||
{s.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</DialogContent>
|
||
</Dialog>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/* ---------- Small building blocks ---------- */
|
||
|
||
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>
|
||
);
|
||
}
|
||
|
||
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>
|
||
);
|
||
}
|
||
|
||
function Section({ title, children }: { title: string; children: ReactNode }) {
|
||
return (
|
||
<section className="space-y-3">
|
||
<h3 className="text-lg font-semibold">{title}</h3>
|
||
{children}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function RatingTile({
|
||
label,
|
||
value,
|
||
accent,
|
||
emptyLabel = "—",
|
||
sub,
|
||
onClick,
|
||
}: {
|
||
label: string;
|
||
value: string | null;
|
||
accent: string;
|
||
emptyLabel?: string;
|
||
sub?: string;
|
||
onClick?: () => void;
|
||
}) {
|
||
const content = (
|
||
<>
|
||
<span className="text-[11px] font-semibold uppercase tracking-wider text-muted-foreground">
|
||
{label}
|
||
</span>
|
||
{value ? (
|
||
<span className="flex items-baseline gap-0.5">
|
||
<span className={`text-2xl font-bold tabular-nums ${accent}`}>
|
||
{value}
|
||
</span>
|
||
<span className="text-xs text-muted-foreground">/10</span>
|
||
</span>
|
||
) : (
|
||
<span className="text-2xl font-bold text-muted-foreground/40">
|
||
{emptyLabel}
|
||
</span>
|
||
)}
|
||
{sub && (
|
||
<span className="text-[10px] text-muted-foreground tabular-nums">
|
||
{sub}
|
||
</span>
|
||
)}
|
||
</>
|
||
);
|
||
const className =
|
||
"flex flex-col items-center gap-1 rounded-xl border border-border/60 bg-card/50 px-2 py-3";
|
||
|
||
return onClick ? (
|
||
<button
|
||
type="button"
|
||
onClick={onClick}
|
||
className={`${className} transition-colors hover:bg-accent`}
|
||
>
|
||
{content}
|
||
</button>
|
||
) : (
|
||
<div className={className}>{content}</div>
|
||
);
|
||
}
|
||
|
||
function DetailRow({
|
||
icon,
|
||
label,
|
||
children,
|
||
}: {
|
||
icon: ReactNode;
|
||
label: string;
|
||
children: ReactNode;
|
||
}) {
|
||
return (
|
||
<div className="flex items-start justify-between gap-4">
|
||
<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>
|
||
);
|
||
}
|
||
|
||
function ExternalChip({
|
||
href,
|
||
children,
|
||
}: {
|
||
href: string;
|
||
children: ReactNode;
|
||
}) {
|
||
return (
|
||
<a
|
||
href={href}
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
className="inline-flex items-center gap-1.5 rounded-md border border-border/60 px-2.5 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||
>
|
||
<ExternalLink className="h-3 w-3" />
|
||
{children}
|
||
</a>
|
||
);
|
||
}
|
||
|
||
/* ---------- TMDB seasons (entries not in the library) ---------- */
|
||
function TmdbSeasonsStrip({ seasons }: { seasons: TmdbPreviewSeason[] }) {
|
||
return (
|
||
<Section title="Seasons">
|
||
<ScrollArea className="w-full">
|
||
<div className="flex gap-3 pb-4">
|
||
{seasons.map((s) => (
|
||
<div key={s.id} className="w-32 shrink-0 space-y-1.5">
|
||
<div className="aspect-2/3 overflow-hidden rounded-lg bg-muted ring-1 ring-border/60">
|
||
{s.poster_path && (
|
||
<img
|
||
src={getTmdbImageUrl(s.poster_path, "w342")}
|
||
alt={s.name}
|
||
loading="lazy"
|
||
className="h-full w-full object-cover"
|
||
/>
|
||
)}
|
||
</div>
|
||
<p className="line-clamp-1 text-sm font-medium">{s.name}</p>
|
||
<p className="text-xs text-muted-foreground">
|
||
{s.episode_count} eps
|
||
{s.air_date && ` · ${getYear(s.air_date)}`}
|
||
</p>
|
||
</div>
|
||
))}
|
||
</div>
|
||
<ScrollBar orientation="horizontal" />
|
||
</ScrollArea>
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
/* ---------- Collections section ---------- */
|
||
function EntryCollectionsSection({ entryId }: { entryId: number }) {
|
||
const { data: allCollections = [], isLoading } = useCollections();
|
||
|
||
const collections = allCollections.filter((col: Collection) =>
|
||
col.entries?.some((e: Entry) => e.id === entryId),
|
||
);
|
||
|
||
if (isLoading || collections.length === 0) return null;
|
||
|
||
return (
|
||
<Section title="In Collections">
|
||
<ScrollArea className="w-full">
|
||
<div className="flex gap-4 pb-4">
|
||
{collections.map((col: Collection) => (
|
||
<Link
|
||
key={col.id}
|
||
to={`/collections/${col.id}`}
|
||
className="group relative block w-56 shrink-0 overflow-hidden rounded-xl ring-1 ring-border/60"
|
||
>
|
||
<div className="aspect-video w-full overflow-hidden bg-muted">
|
||
<img
|
||
src={getCollectionBackdropUrl(col)}
|
||
alt={col.name}
|
||
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||
/>
|
||
</div>
|
||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/20 to-transparent" />
|
||
<div className="absolute bottom-0 left-0 right-0 p-3">
|
||
<p className="line-clamp-2 text-sm font-semibold leading-tight text-white">
|
||
{col.name}
|
||
</p>
|
||
{col.entries && (
|
||
<p className="mt-0.5 text-xs text-white/70">
|
||
{col.entries.length}{" "}
|
||
{col.entries.length === 1 ? "title" : "titles"}
|
||
</p>
|
||
)}
|
||
</div>
|
||
</Link>
|
||
))}
|
||
</div>
|
||
<ScrollBar orientation="horizontal" />
|
||
</ScrollArea>
|
||
</Section>
|
||
);
|
||
}
|