Files
Showy/react_frontend/src/pages/EntryDetailsPage.tsx
T
X4Lo 834e02e76b Add poster popup, selectable title, collection media previews and library toggles
- Collection edit dialog shows the current poster and backdrop when available
- Entry details: title is selectable (action row no longer overlays it)
- Entry details: clicking the poster opens it full size in a dialog
- Library: Favorites and Hidden are toggles that combine with the type tabs
2026-11-03 18:39:03 +00:00

752 lines
28 KiB
TypeScript

import { useState, useEffect } from "react";
import { useParams, Link, useNavigate } from "react-router-dom";
import {
useEntry,
useEntrySeasons,
useRefreshEntry,
useEntryCredits,
} 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 { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
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,
} from "lucide-react";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { CastList } from "@/components/entries/CastList";
import { SeasonsContainer } from "@/components/entries/SeasonsContainer";
import { StreamingSection } from "@/components/streaming/StreamingSection";
// EpisodeWatchHistory is available for future use
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 {
getPosterUrl,
getFullPosterUrl,
getBackdropUrl,
getCollectionBackdropUrl,
getYear,
formatRuntime,
formatDate,
} from "@/lib/media-utils";
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
import type { Collection, Entry, EntrySeen } 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-400",
},
{
value: "watching",
label: "Watching",
color: "bg-blue-500/15 border-blue-500/30 text-blue-600 dark:text-blue-400",
},
{
value: "completed",
label: "Completed",
color:
"bg-green-500/15 border-green-500/30 text-green-600 dark:text-green-400",
},
{
value: "on_hold",
label: "On Hold",
color:
"bg-amber-500/15 border-amber-500/30 text-amber-600 dark:text-amber-400",
},
{
value: "dropped",
label: "Dropped",
color: "bg-red-500/15 border-red-500/30 text-red-600 dark:text-red-400",
},
];
function getWatchStatusInfo(value: string | null | undefined) {
return WATCH_STATUSES.find((s) => s.value === value);
}
export function EntryDetailsPage() {
const { id } = useParams<{ id: string }>();
const entryId = parseInt(id!, 10);
const navigate = useNavigate();
const { data: entry, isLoading } = useEntry(entryId);
const { data: seasons } = useEntrySeasons(entryId);
const { data: allCredits = [] } = useEntryCredits(entryId);
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
const updateEntry = useUpdateEntry();
const refreshEntry = useRefreshEntry();
const deleteEntrySeen = useDeleteEntrySeen();
const deleteEntry = useDeleteEntry();
// 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 displayEntry =
libraryEntry && entry
? { ...libraryEntry, ...entry, isInLibrary: true }
: entry || libraryEntry;
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 [editSeenRecord, setEditSeenRecord] = useState<EntrySeen | null>(null);
// Track recently viewed for command palette
const addRecentlyViewed = useCommandPaletteStore((s) => s.addRecentlyViewed);
useEffect(() => {
if (displayEntry) {
addRecentlyViewed({
id: `lib-${entryId}`,
title: displayEntry.title,
type: displayEntry.is_tvseries ? "tv" : "movie",
poster_path: displayEntry.poster_path,
libraryId: entryId,
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
});
}
}, [entryId, displayEntry?.title]);
if (isLoading || !displayEntry) {
return <EntryDetailsSkeleton />;
}
const e = displayEntry;
// Use useEntryCredits (allCredits) which includes both cast AND crew (director).
// e.credits from useEntry is a limited preview (10 items).
const credits = allCredits.length > 0 ? allCredits : e.credits || [];
const backdrop = getBackdropUrl(e);
const poster = getPosterUrl(e);
const director = credits.find(
(c) => c.cast_type === "crew" && c.job === "Director",
);
const toggleFavorite = () => {
updateEntry.mutate({ id: e.id, data: { favorit: !e.favorit } });
};
return (
<div>
{/* Backdrop banner */}
<div className="relative -mx-6 -mt-6 h-52 overflow-hidden">
{backdrop ? (
<img
src={backdrop}
alt=""
className="h-full w-full object-cover opacity-25 blur-sm scale-105"
/>
) : (
<div className="h-full w-full bg-linear-to-br from-primary/15 to-primary/5" />
)}
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
</div>
{/* Main content */}
<div className="mx-auto max-w-4xl">
{/* Action buttons — top right. The row overlaps the title below, so
only the button itself takes pointer events. */}
<div className="flex justify-end gap-1 -mt-10 relative z-10 mb-2 pointer-events-none">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-9 w-9 pointer-events-auto"
>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
{/* Watch & Rate */}
<DropdownMenuItem onClick={() => setShowSeenDialog(true)}>
<Eye className="mr-2 h-4 w-4" />
Mark as watched
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setShowRatingDialog(true)}>
<Star className="mr-2 h-4 w-4" />
Rate this
</DropdownMenuItem>
{e.is_tvseries && <DropdownMenuSeparator />}
{e.is_tvseries && (
<DropdownMenuItem onClick={() => setShowStatusDialog(true)}>
<BookmarkCheck className="mr-2 h-4 w-4" />
Set Status
</DropdownMenuItem>
)}
{!e.is_tvseries && (
<DropdownMenuItem
onClick={() => setShowWatchHistoryDialog(true)}
>
<History className="mr-2 h-4 w-4" />
Watch History
</DropdownMenuItem>
)}
<DropdownMenuSeparator />
{/* Organize */}
<DropdownMenuItem
onClick={toggleFavorite}
disabled={updateEntry.isPending}
>
<Heart
className={`mr-2 h-4 w-4 ${e.favorit ? "fill-current" : ""}`}
/>
{e.favorit ? "Unfavorite" : "Favorite"}
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setShowCollectionDialog(true)}>
<FolderPlus className="mr-2 h-4 w-4" />
Add to collection
</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 />
{/* Manage */}
<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 />
{/* Danger */}
<DropdownMenuItem
className="text-destructive focus:text-destructive"
onClick={() => setShowDeleteConfirm(true)}
>
<Trash2 className="mr-2 h-4 w-4" />
Delete entry
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
{/* Two-column header: sticky poster | info */}
<div className="flex flex-col gap-6 relative items-start sm:flex-row sm:gap-8 sm:-mt-8">
{/* LEFT: Sticky poster */}
<div className="sm:sticky sm:top-20 w-32 sm:w-44 shrink-0 self-start mx-auto sm:mx-0">
<button
type="button"
onClick={() => setShowPosterDialog(true)}
className="relative block w-full cursor-zoom-in rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
aria-label="View full-size poster"
>
<img
src={poster}
alt={e.title}
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
/>
</button>
{/* External links */}
{e.entryIds && (
<div className="flex items-center justify-center gap-3 mt-3">
{e.entryIds.tmdb_id && (
<a
href={`https://www.themoviedb.org/${e.is_tvseries ? "tv" : "movie"}/${e.entryIds.tmdb_id}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
>
<ExternalLink className="h-3 w-3" />
TMDB
</a>
)}
{e.entryIds.imdb_id && (
<a
href={`https://www.imdb.com/title/${e.entryIds.imdb_id}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
>
<ExternalLink className="h-3 w-3" />
IMDb
</a>
)}
</div>
)}
</div>
{/* RIGHT: Entry info */}
<div className="flex-1 min-w-0 space-y-4">
{/* Title + director */}
<div className="space-y-1">
<h1 className="text-3xl font-bold leading-tight select-text">
{e.title}
</h1>
{director?.people?.name && (
<p className="text-sm text-muted-foreground">
by{" "}
<Link
to={`/people/${director.people_id}`}
className="font-medium text-foreground hover:underline"
>
{director.people.name}
</Link>
</p>
)}
</div>
{/* Meta */}
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
{e.release_date && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="cursor-default underline decoration-dotted">
{getYear(e.release_date)}
</span>
</TooltipTrigger>
<TooltipContent>
<p>{formatDate(e.release_date)}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
{e.is_tvseries && e.status && (
<>
<span>•</span>
<span>{e.status}</span>
</>
)}
{e.runtime && !e.is_tvseries && (
<>
<span>•</span>
<span>{formatRuntime(e.runtime)}</span>
</>
)}
{!e.is_tvseries && watchHistory.length > 0 && (
<>
<span>•</span>
{watchHistory.length === 1 ? (
<span>Seen {formatDate(watchHistory[0].date_seen)}</span>
) : (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="cursor-default underline decoration-dotted">
Seen {watchHistory.length} times
</span>
</TooltipTrigger>
<TooltipContent>
<div className="space-y-0.5 text-xs">
{watchHistory.map((wh) => (
<p key={wh.id}>{formatDate(wh.date_seen)}</p>
))}
</div>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</>
)}
{!e.is_tvseries && watchHistory.length === 0 && (
<>
<span>•</span>
<button
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors underline decoration-dotted cursor-pointer"
onClick={() => setShowSeenDialog(true)}
>
<Eye className="h-3 w-3" />
Mark as watched
</button>
</>
)}
</div>
{/* Genres */}
{e.genres && e.genres.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{e.genres.map((g) => (
<Link
key={g.id}
to={`/library?genre=${encodeURIComponent(g.name)}`}
>
<Badge
variant="outline"
className="text-xs cursor-pointer hover:bg-accent transition-colors"
>
{g.name}
</Badge>
</Link>
))}
</div>
)}
{/* Ratings */}
<div className="flex flex-wrap items-center gap-2">
{e.entryRatings?.imdb_rating != null &&
e.entryRatings.imdb_rating > 0 && (
<span className="inline-flex items-center gap-1 rounded-full bg-yellow-500/10 border border-yellow-500/20 px-3 py-1 text-sm text-yellow-600 dark:text-yellow-400 font-medium">
<span className="font-bold">IMDb:</span>
{e.entryRatings.imdb_rating}/10
</span>
)}
{e.entryRatings?.tmdb_rating != null &&
e.entryRatings.tmdb_rating > 0 && (
<span className="inline-flex items-center gap-1 rounded-full bg-blue-500/10 border border-blue-500/20 px-3 py-1 text-sm text-blue-600 dark:text-blue-400 font-medium">
<span className="font-bold">TMDB:</span>
{e.entryRatings.tmdb_rating.toFixed(1)}/10
</span>
)}
{e.entryRatings?.user_rating != null &&
e.entryRatings.user_rating > 0 ? (
<button
className="inline-flex items-center gap-1 rounded-full bg-accent border border-border px-3 py-1 text-sm font-medium hover:bg-accent/80 transition-colors"
onClick={() => setShowRatingDialog(true)}
title="Click to change rating"
>
<Star className="h-3.5 w-3.5 fill-yellow-400 text-yellow-400" />
<span className="font-bold">You:</span>
{e.entryRatings.user_rating}/10
</button>
) : (
<button
className="inline-flex items-center gap-1.5 rounded-full border border-dashed border-border px-3 py-1 text-sm text-muted-foreground hover:border-border hover:text-foreground transition-colors"
onClick={() => setShowRatingDialog(true)}
>
<Star className="h-3.5 w-3.5" />
Rate
</button>
)}
{/* Favorite pill */}
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<button
onClick={toggleFavorite}
disabled={updateEntry.isPending}
className={`inline-flex items-center gap-1 rounded-full border px-3 py-1 text-sm font-medium transition-colors ${
e.favorit
? "bg-yellow-500/15 border-yellow-500/30 text-yellow-600 dark:text-yellow-400 hover:bg-yellow-500/25"
: "border-dashed border-border text-muted-foreground hover:border-yellow-500/40 hover:text-yellow-500"
}`}
>
<Star
className={`h-3.5 w-3.5 ${e.favorit ? "fill-yellow-400 text-yellow-400" : ""}`}
/>
Favorit
</button>
</TooltipTrigger>
<TooltipContent>
<p>
{e.favorit ? "Remove from favorites" : "Add to favorites"}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
{/* Watch status pill — TV only */}
{e.is_tvseries &&
e.watch_status &&
(() => {
const info = getWatchStatusInfo(e.watch_status);
return (
<button
onClick={() => setShowStatusDialog(true)}
className={`inline-flex items-center gap-1 rounded-full border px-3 py-1 text-sm font-medium transition-colors cursor-pointer ${info?.color ?? ""}`}
>
<BookmarkCheck className="h-3.5 w-3.5" />
{info?.label}
</button>
);
})()}
</div>
{/* Storyline */}
{e.storyline && (
<p className="text-sm text-muted-foreground leading-relaxed max-w-prose">
{e.storyline}
</p>
)}
</div>
</div>
{/* Sections */}
<div className="mt-10 space-y-8">
{/* Streaming player + Trailer */}
<div className="flex flex-wrap items-center justify-center gap-2">
<StreamingSection entry={e} seasons={seasons} />
<a
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 h-11 px-6 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors"
>
<Play className="h-4 w-4" />
Watch Trailer
</a>
</div>
{credits.length > 0 && (
<>
<Separator />
<CastList
credits={credits}
entryId={e.id}
isTvSeries={e.is_tvseries}
maxItems={12}
/>
</>
)}
<EntryCollectionsSection entryId={e.id} />
{e.is_tvseries && seasons && seasons.length > 0 && (
<>
<Separator />
<SeasonsContainer seasons={seasons} entryId={e.id} />
</>
)}
{/* {watchHistory.length > 0 && (
<>
<Separator />
<EpisodeWatchHistory
watchHistory={watchHistory}
onDelete={(seenId) =>
deleteEntrySeen.mutate({ id: seenId, entryId: e.id })
}
/>
</>
)} */}
</div>
</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);
}}
/>
<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>
);
}
/* ---------- 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 (
<>
<Separator />
<div className="space-y-3">
<h3 className="text-lg font-semibold">In Collections</h3>
<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 shrink-0 w-56 overflow-hidden rounded-lg relative block"
>
<div className="aspect-video w-full overflow-hidden bg-muted rounded-lg">
<img
src={getCollectionBackdropUrl(col)}
alt={col.name}
className="h-full w-full object-cover transition-transform group-hover:scale-105"
/>
</div>
<div className="absolute inset-0 bg-linear-to-t from-black/70 via-black/20 to-transparent rounded-lg" />
<div className="absolute bottom-0 left-0 right-0 p-3">
<p className="text-sm font-medium text-white line-clamp-2 leading-tight">
{col.name}
</p>
{col.entries && (
<p className="text-xs text-white/70 mt-0.5">
{col.entries.length}{" "}
{col.entries.length === 1 ? "title" : "titles"}
</p>
)}
</div>
</Link>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</div>
</>
);
}