Unify entry page for TMDB previews and add artwork section

- 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
This commit is contained in:
X4Lo committed 2026-11-05 14:06:46 +00:00
1 parent a9ff2d089a
commit 28eee34548
19 files changed
+1190 -411

No files matched your search

+293 -136
View File
@@ -5,6 +5,8 @@ import {
useEntrySeasons,
useRefreshEntry,
useEntryCredits,
useTmdbPreview,
useCreateEntry,
} from "@/hooks/useEntries";
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
import { useCollections } from "@/hooks/useCollections";
@@ -44,6 +46,8 @@ import {
DollarSign,
ListVideo,
CircleDot,
Plus,
Loader2,
} from "lucide-react";
import {
Tooltip,
@@ -56,6 +60,7 @@ 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";
@@ -81,7 +86,13 @@ import {
formatDate,
} from "@/lib/media-utils";
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
import type { Collection, Entry, EntrySeen } from "@/types";
import type {
Collection,
Credit,
Entry,
EntrySeen,
TmdbPreviewSeason,
} from "@/types";
const WATCH_STATUSES = [
{
@@ -138,25 +149,60 @@ const languageName = (() => {
}
})();
/**
* 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 } = useParams<{ id: string }>();
const entryId = parseInt(id!, 10);
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 displayEntry =
libraryEntry && entry
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;
: 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);
@@ -175,24 +221,59 @@ export function EntryDetailsPage() {
useEffect(() => {
if (displayEntry) {
addRecentlyViewed({
id: `lib-${entryId}`,
id: isLibrary ? `lib-${entryId}` : `tmdb-${previewTmdbId}`,
title: displayEntry.title,
type: displayEntry.is_tvseries ? "tv" : "movie",
poster_path: displayEntry.poster_path,
libraryId: entryId,
libraryId: isLibrary ? entryId : undefined,
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
});
}
}, [entryId, displayEntry?.title]);
}, [entryId, previewTmdbId, displayEntry?.title]);
if (isLoading || !displayEntry) {
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;
// Use useEntryCredits (allCredits) which includes both cast AND crew (director).
// Library: useEntryCredits (allCredits) includes both cast AND crew (director);
// e.credits from useEntry is a limited preview (10 items).
const credits = allCredits.length > 0 ? allCredits : e.credits || [];
// 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(
@@ -289,7 +370,7 @@ export function EntryDetailsPage() {
{e.status}
</span>
)}
{e.is_tvseries && (
{e.is_tvseries && isLibrary && (
<button
type="button"
onClick={() => setShowStatusDialog(true)}
@@ -339,10 +420,9 @@ export function EntryDetailsPage() {
{e.runtime && !e.is_tvseries && (
<MetaItem>{formatRuntime(e.runtime)}</MetaItem>
)}
{e.is_tvseries && seasons && seasons.length > 0 && (
{e.is_tvseries && seasonCount > 0 && (
<MetaItem>
{seasons.length}{" "}
{seasons.length === 1 ? "season" : "seasons"}
{seasonCount} {seasonCount === 1 ? "season" : "seasons"}
</MetaItem>
)}
{e.is_tvseries && e.created_by && e.created_by.length > 0 && (
@@ -365,7 +445,11 @@ export function EntryDetailsPage() {
<MetaItem>
Directed by{" "}
<Link
to={`/people/${director.people_id}`}
to={
isLibrary
? `/people/${director.people_id}`
: `/people/tmdb/${director.people_id}`
}
className="font-medium text-foreground hover:underline"
>
{director.people.name}
@@ -391,7 +475,23 @@ export function EntryDetailsPage() {
{/* Actions */}
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
<StreamingSection entry={e} seasons={seasons} />
{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"
@@ -413,114 +513,116 @@ export function EntryDetailsPage() {
</a>
)}
<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"
/>
}
{isLibrary && (
<div className="flex items-center gap-1.5">
<IconAction
label="Mark as watched"
onClick={() => setShowSeenDialog(true)}
>
<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 },
})
<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"
/>
}
>
<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>
<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>
@@ -556,24 +658,45 @@ export function EntryDetailsPage() {
{credits.length > 0 && (
<CastList
credits={credits}
entryId={e.id}
entryId={isLibrary ? e.id : undefined}
isTvSeries={e.is_tvseries}
maxItems={12}
allCastHref={
isLibrary
? undefined
: `/entry/tmdb/${tmdbType}/${previewTmdbId}/cast`
}
/>
)}
{e.is_tvseries && seasons && seasons.length > 0 && (
{isLibrary && e.is_tvseries && seasons && seasons.length > 0 && (
<SeasonsContainer seasons={seasons} entryId={e.id} />
)}
{!isLibrary && e.is_tvseries && previewSeasons.length > 0 && (
<TmdbSeasonsStrip seasons={previewSeasons} />
)}
<EntryCollectionsSection entryId={e.id} />
{isLibrary && <EntryCollectionsSection entryId={e.id} />}
<RecommendationsSection entryId={e.id} isTvSeries={e.is_tvseries} />
<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 grid-cols-3 gap-2">
<div
className={`grid gap-2 ${isLibrary ? "grid-cols-3" : "grid-cols-2"}`}
>
<RatingTile
label="IMDb"
value={
@@ -597,13 +720,15 @@ export function EntryDetailsPage() {
: undefined
}
/>
<RatingTile
label="You"
value={userRating > 0 ? String(userRating) : null}
accent="text-primary"
emptyLabel="Rate"
onClick={() => setShowRatingDialog(true)}
/>
{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">
@@ -702,7 +827,7 @@ export function EntryDetailsPage() {
{e.country}
</DetailRow>
)}
{!e.is_tvseries && (
{isLibrary && !e.is_tvseries && (
<DetailRow icon={<Eye />} label="Watched">
{watchHistory.length > 0 ? (
<button
@@ -1048,6 +1173,38 @@ function ExternalChip({
);
}
/* ---------- 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();