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:
1 parent
a9ff2d089a
commit
28eee34548
19 files changed
+1190
-411
No files matched your search
@@ -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();
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useEffect } from "react";
|
||||
import { useTmdbPreview, useCreateEntry } from "@/hooks/useEntries";
|
||||
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 { Plus, Loader2, ExternalLink } from "lucide-react";
|
||||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
||||
import { CastList } from "@/components/entries/CastList";
|
||||
import { getYear, formatRuntime } from "@/lib/media-utils";
|
||||
import type { Credit } from "@/types";
|
||||
|
||||
const TMDB_IMG = "https://image.tmdb.org/t/p";
|
||||
|
||||
export function TmdbPreviewPage() {
|
||||
const { type, tmdbId } = useParams<{ type: string; tmdbId: string }>();
|
||||
const navigate = useNavigate();
|
||||
const tmdbIdNum = parseInt(tmdbId!, 10);
|
||||
const mediaType = type as "movie" | "tv";
|
||||
|
||||
const {
|
||||
data: preview,
|
||||
isLoading,
|
||||
isError,
|
||||
} = useTmdbPreview(tmdbIdNum, mediaType);
|
||||
const createEntry = useCreateEntry();
|
||||
|
||||
// Check if already in library
|
||||
const libraryEntry = useLibraryStore((s) => {
|
||||
for (const e of s.entries.values()) {
|
||||
if (e.entryIds?.tmdb_id === tmdbIdNum) return e;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// Redirect immediately if entry is already in library — skip the preview step
|
||||
useEffect(() => {
|
||||
if (libraryEntry) {
|
||||
navigate(`/entry/${libraryEntry.id}`, { replace: true });
|
||||
}
|
||||
}, [libraryEntry, navigate]);
|
||||
|
||||
// Track recently viewed for command palette
|
||||
const addRecentlyViewed = useCommandPaletteStore((s) => s.addRecentlyViewed);
|
||||
useEffect(() => {
|
||||
if (preview) {
|
||||
addRecentlyViewed({
|
||||
id: `tmdb-${tmdbIdNum}`,
|
||||
title: preview.title,
|
||||
type: mediaType,
|
||||
poster_path: preview.poster_path,
|
||||
libraryId: libraryEntry?.id,
|
||||
tmdbId: tmdbIdNum,
|
||||
});
|
||||
}
|
||||
}, [tmdbIdNum, preview?.title]);
|
||||
|
||||
if (isLoading || !preview) {
|
||||
return <EntryDetailsSkeleton />;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
||||
const backdrop = preview.backdrop_path
|
||||
? `${TMDB_IMG}/w1280${preview.backdrop_path}`
|
||||
: null;
|
||||
const poster = preview.poster_path
|
||||
? `${TMDB_IMG}/w500${preview.poster_path}`
|
||||
: "/images/default-poster.png";
|
||||
|
||||
const handleAddToLibrary = () => {
|
||||
createEntry.mutate(
|
||||
{ tmdb_id: preview.tmdb_id, is_tvserie: preview.is_tvseries },
|
||||
{
|
||||
onSuccess: (newEntry) =>
|
||||
navigate(`/entry/${newEntry.id}`, { replace: true }),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
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">
|
||||
{/* Add to Library button — top right */}
|
||||
<div className="flex justify-end gap-2 -mt-10 relative z-10 mb-2">
|
||||
{libraryEntry ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate(`/entry/${libraryEntry.id}`)}
|
||||
>
|
||||
Already in Library — View
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleAddToLibrary}
|
||||
disabled={createEntry.isPending}
|
||||
>
|
||||
{createEntry.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Two-column header: poster | info */}
|
||||
<div className="flex flex-col gap-6 relative items-start sm:flex-row sm:gap-8 sm:-mt-8">
|
||||
{/* LEFT: Poster */}
|
||||
<div className="w-32 sm:w-44 shrink-0 self-start mx-auto sm:mx-0">
|
||||
<img
|
||||
src={poster}
|
||||
alt={preview.title}
|
||||
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
|
||||
/>
|
||||
{/* External links */}
|
||||
<div className="flex items-center justify-center gap-3 mt-3">
|
||||
{preview.tmdb_id && (
|
||||
<a
|
||||
href={`https://www.themoviedb.org/${preview.is_tvseries ? "tv" : "movie"}/${preview.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>
|
||||
)}
|
||||
{preview.imdb_id && (
|
||||
<a
|
||||
href={`https://www.imdb.com/title/${preview.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: Info */}
|
||||
<div className="flex-1 min-w-0 space-y-4">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold leading-tight">
|
||||
{preview.title}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Meta */}
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
{preview.release_date && (
|
||||
<span>{getYear(preview.release_date)}</span>
|
||||
)}
|
||||
{preview.is_tvseries && preview.status && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{preview.status}</span>
|
||||
</>
|
||||
)}
|
||||
{preview.runtime && !preview.is_tvseries && (
|
||||
<>
|
||||
{preview.release_date && <span>•</span>}
|
||||
<span>{formatRuntime(preview.runtime)}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* TV series season count */}
|
||||
{preview.is_tvseries && preview.number_of_seasons != null && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Badge variant="secondary">
|
||||
{preview.number_of_seasons}{" "}
|
||||
{preview.number_of_seasons === 1 ? "Season" : "Seasons"}
|
||||
</Badge>
|
||||
{preview.number_of_episodes != null && (
|
||||
<span className="text-muted-foreground">
|
||||
({preview.number_of_episodes} episodes)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Genres */}
|
||||
{preview.genres.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{preview.genres.map((g) => (
|
||||
<Badge key={g.id} variant="outline" className="text-xs">
|
||||
{g.name}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Rating */}
|
||||
{preview.vote_average != null && preview.vote_average > 0 && (
|
||||
<div className="flex items-center gap-2">
|
||||
<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>
|
||||
{preview.vote_average.toFixed(1)}/10
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Storyline */}
|
||||
{preview.storyline && (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-prose">
|
||||
{preview.storyline}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sections */}
|
||||
<div className="mt-10 space-y-8">
|
||||
{preview.credits && preview.credits.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<CastList
|
||||
credits={preview.credits as unknown as Credit[]}
|
||||
maxItems={12}
|
||||
allCastHref={`/entry/tmdb/${mediaType}/${tmdbIdNum}/cast`}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user