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
@@ -6,6 +6,9 @@ import type {
|
||||
TmdbPreview,
|
||||
TmdbEntry,
|
||||
TmdbPaginatedResponse,
|
||||
ArtworkResponse,
|
||||
ArtworkType,
|
||||
Media,
|
||||
} from "@/types";
|
||||
|
||||
export const entriesApi = {
|
||||
@@ -69,6 +72,24 @@ export const entriesApi = {
|
||||
.get<TmdbPaginatedResponse<TmdbEntry>>(`/entries/${id}/recommendations`)
|
||||
.then((r) => r.data),
|
||||
|
||||
getTmdbRecommendations: (type: "movie" | "tv", tmdbId: number) =>
|
||||
api
|
||||
.get<TmdbPaginatedResponse<TmdbEntry>>(
|
||||
`/entries/tmdb/recommendations/${type}/${tmdbId}`,
|
||||
)
|
||||
.then((r) => r.data),
|
||||
|
||||
getArtwork: (id: number) =>
|
||||
api.get<ArtworkResponse>(`/entries/${id}/artwork`).then((r) => r.data),
|
||||
|
||||
getTmdbArtwork: (type: "movie" | "tv", tmdbId: number) =>
|
||||
api
|
||||
.get<ArtworkResponse>(`/entries/tmdb/artwork/${type}/${tmdbId}`)
|
||||
.then((r) => r.data),
|
||||
|
||||
addArtwork: (id: number, data: { type: ArtworkType; file_path: string }) =>
|
||||
api.post<Media>(`/entries/${id}/artwork`, data).then((r) => r.data),
|
||||
|
||||
syncSeries: () => api.get("/entries/sync-series").then((r) => r.data),
|
||||
|
||||
previewTmdb: (tmdbId: number, type: "movie" | "tv") =>
|
||||
|
||||
@@ -0,0 +1,445 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Check, Download, Loader2, Star } from "lucide-react";
|
||||
import { useAddArtwork, useArtwork } from "@/hooks/useEntries";
|
||||
import { getMediaUrl, getTmdbImageUrl } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
import type { ArtworkItem, ArtworkType } from "@/types";
|
||||
|
||||
// Rows shown at first and added per "Show more"
|
||||
const ROWS_STEP = 2;
|
||||
// Checkerboard behind logos so transparent/dark logos stay visible
|
||||
const CHECKER =
|
||||
"bg-[repeating-conic-gradient(#8883_0_25%,transparent_0_50%)] bg-size-[16px_16px]";
|
||||
|
||||
const TYPES: {
|
||||
type: ArtworkType;
|
||||
key: "posters" | "backdrops" | "logos";
|
||||
label: string;
|
||||
thumbSize: string;
|
||||
grid: string;
|
||||
/** Columns per breakpoint; must match `grid` */
|
||||
cols: { base: number; sm?: number; md?: number; xl?: number };
|
||||
aspect: string;
|
||||
}[] = [
|
||||
{
|
||||
type: "poster",
|
||||
key: "posters",
|
||||
label: "Posters",
|
||||
thumbSize: "w342",
|
||||
grid: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5 xl:grid-cols-6",
|
||||
cols: { base: 3, sm: 4, md: 5, xl: 6 },
|
||||
aspect: "aspect-2/3",
|
||||
},
|
||||
{
|
||||
type: "backdrop",
|
||||
key: "backdrops",
|
||||
label: "Backdrops",
|
||||
thumbSize: "w780",
|
||||
grid: "grid-cols-1 sm:grid-cols-2 xl:grid-cols-3",
|
||||
cols: { base: 1, sm: 2, xl: 3 },
|
||||
aspect: "aspect-video",
|
||||
},
|
||||
{
|
||||
type: "logo",
|
||||
key: "logos",
|
||||
label: "Logos",
|
||||
thumbSize: "w500",
|
||||
grid: "grid-cols-2 sm:grid-cols-3 xl:grid-cols-4",
|
||||
cols: { base: 2, sm: 3, xl: 4 },
|
||||
aspect: "aspect-[2/1]",
|
||||
},
|
||||
];
|
||||
|
||||
const languageName = (() => {
|
||||
try {
|
||||
const names = new Intl.DisplayNames(["en"], { type: "language" });
|
||||
return (code: string) => names.of(code) ?? code;
|
||||
} catch {
|
||||
return (code: string) => code;
|
||||
}
|
||||
})();
|
||||
|
||||
function imageUrls(item: ArtworkItem, type: ArtworkType, thumbSize: string) {
|
||||
if (item.file_path) {
|
||||
return {
|
||||
thumb: getTmdbImageUrl(item.file_path, thumbSize),
|
||||
full: getTmdbImageUrl(item.file_path, "original"),
|
||||
};
|
||||
}
|
||||
const folder = `${type}s`;
|
||||
return {
|
||||
thumb: getMediaUrl("entries", folder, "preview", item.media_path!),
|
||||
full: getMediaUrl("entries", folder, "full", item.media_path!),
|
||||
};
|
||||
}
|
||||
|
||||
const BREAKPOINTS = [
|
||||
["xl", 1280],
|
||||
["md", 768],
|
||||
["sm", 640],
|
||||
] as const;
|
||||
|
||||
/** Current column count for a grid, following the Tailwind breakpoints. */
|
||||
function useGridColumns(cols: {
|
||||
base: number;
|
||||
sm?: number;
|
||||
md?: number;
|
||||
xl?: number;
|
||||
}) {
|
||||
const compute = () => {
|
||||
for (const [bp, minWidth] of BREAKPOINTS) {
|
||||
const value = cols[bp];
|
||||
if (value && window.matchMedia(`(min-width: ${minWidth}px)`).matches) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return cols.base;
|
||||
};
|
||||
const [columns, setColumns] = useState(compute);
|
||||
|
||||
useEffect(() => {
|
||||
const update = () => setColumns(compute());
|
||||
update();
|
||||
const queries = BREAKPOINTS.map(([, w]) =>
|
||||
window.matchMedia(`(min-width: ${w}px)`),
|
||||
);
|
||||
queries.forEach((q) => q.addEventListener("change", update));
|
||||
return () =>
|
||||
queries.forEach((q) => q.removeEventListener("change", update));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [cols.base, cols.sm, cols.md, cols.xl]);
|
||||
|
||||
return columns;
|
||||
}
|
||||
|
||||
const itemKey = (item: ArtworkItem) =>
|
||||
item.file_path ?? `media-${item.media_id}`;
|
||||
|
||||
/**
|
||||
* Posters, backdrops and logos from TMDB merged with the entry's media table.
|
||||
* For library entries, TMDB images can be added (downloaded) to the library.
|
||||
*/
|
||||
export function ArtworkSection({
|
||||
entryId = 0,
|
||||
tmdbId = 0,
|
||||
isTvSeries,
|
||||
originalLanguage,
|
||||
}: {
|
||||
entryId?: number;
|
||||
tmdbId?: number;
|
||||
isTvSeries: boolean;
|
||||
originalLanguage?: string | null;
|
||||
}) {
|
||||
const isLibrary = !!entryId;
|
||||
const { data, isLoading, isError } = useArtwork(
|
||||
isLibrary ? { entryId } : { tmdbId, type: isTvSeries ? "tv" : "movie" },
|
||||
);
|
||||
const addArtwork = useAddArtwork(entryId);
|
||||
|
||||
const [activeType, setActiveType] = useState<ArtworkType>("poster");
|
||||
const [language, setLanguage] = useState("all");
|
||||
const [libraryOnly, setLibraryOnly] = useState(false);
|
||||
const [rows, setRows] = useState(ROWS_STEP);
|
||||
const [pendingPath, setPendingPath] = useState<string | null>(null);
|
||||
const [viewing, setViewing] = useState<ArtworkItem | null>(null);
|
||||
|
||||
const config = TYPES.find((t) => t.type === activeType)!;
|
||||
const columns = useGridColumns(config.cols);
|
||||
const visible = columns * rows;
|
||||
const items = useMemo(() => data?.[config.key] ?? [], [data, config.key]);
|
||||
|
||||
// Languages present for this type, most common first ("none" = no text)
|
||||
const languages = useMemo(() => {
|
||||
const counts = new Map<string, number>();
|
||||
for (const item of items) {
|
||||
if (!item.file_path) continue;
|
||||
const lang = item.language ?? "none";
|
||||
counts.set(lang, (counts.get(lang) ?? 0) + 1);
|
||||
}
|
||||
const preferred = ["none", "en", originalLanguage].filter(Boolean);
|
||||
return [...counts.entries()].sort(([a, ca], [b, cb]) => {
|
||||
const pa = preferred.indexOf(a);
|
||||
const pb = preferred.indexOf(b);
|
||||
if (pa !== -1 || pb !== -1)
|
||||
return (pa === -1 ? 99 : pa) - (pb === -1 ? 99 : pb);
|
||||
return cb - ca;
|
||||
});
|
||||
}, [items, originalLanguage]);
|
||||
|
||||
const filtered = items.filter((item) => {
|
||||
if (libraryOnly && !item.in_library) return false;
|
||||
if (language === "all" || !item.file_path) return true;
|
||||
return (item.language ?? "none") === language;
|
||||
});
|
||||
|
||||
const changeType = (type: ArtworkType) => {
|
||||
setActiveType(type);
|
||||
setLanguage("all");
|
||||
setRows(ROWS_STEP);
|
||||
};
|
||||
|
||||
const add = (item: ArtworkItem) => {
|
||||
if (!item.file_path) return;
|
||||
setPendingPath(item.file_path);
|
||||
addArtwork.mutate(
|
||||
{ type: activeType, file_path: item.file_path },
|
||||
{
|
||||
onSuccess: () =>
|
||||
setViewing((v) =>
|
||||
v?.file_path === item.file_path ? { ...v, in_library: true } : v,
|
||||
),
|
||||
onSettled: () => setPendingPath(null),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
if (isError) return null;
|
||||
|
||||
const total = data
|
||||
? data.posters.length + data.backdrops.length + data.logos.length
|
||||
: 0;
|
||||
if (!isLoading && total === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<h3 className="text-lg font-semibold">Artwork</h3>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<select
|
||||
value={language}
|
||||
onChange={(e) => {
|
||||
setLanguage(e.target.value);
|
||||
setRows(ROWS_STEP);
|
||||
}}
|
||||
className="h-8 rounded-md border border-border/60 bg-background px-2 text-xs"
|
||||
aria-label="Language"
|
||||
>
|
||||
<option value="all">All languages</option>
|
||||
{languages.map(([lang, count]) => (
|
||||
<option key={lang} value={lang}>
|
||||
{lang === "none" ? "No text" : languageName(lang)} ({count})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{isLibrary && (
|
||||
<Button
|
||||
variant={libraryOnly ? "default" : "outline"}
|
||||
size="sm"
|
||||
aria-pressed={libraryOnly}
|
||||
onClick={() => {
|
||||
setLibraryOnly((v) => !v);
|
||||
setRows(ROWS_STEP);
|
||||
}}
|
||||
>
|
||||
<Check />
|
||||
In library
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Tabs
|
||||
value={activeType}
|
||||
onValueChange={(v) => changeType(v as ArtworkType)}
|
||||
>
|
||||
<TabsList>
|
||||
{TYPES.map((t) => (
|
||||
<TabsTrigger key={t.type} value={t.type}>
|
||||
{t.label}
|
||||
{data && (
|
||||
<span className="ml-1 text-muted-foreground tabular-nums">
|
||||
{data[t.key].length}
|
||||
</span>
|
||||
)}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
|
||||
{isLoading ? (
|
||||
<div className={`grid gap-3 ${config.grid}`}>
|
||||
{Array.from({ length: columns * ROWS_STEP }).map((_, i) => (
|
||||
<Skeleton key={i} className={`${config.aspect} rounded-lg`} />
|
||||
))}
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No {config.label.toLowerCase()} match these filters.
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<div className={`grid gap-3 ${config.grid}`}>
|
||||
{filtered.slice(0, visible).map((item) => (
|
||||
<ArtworkTile
|
||||
key={itemKey(item)}
|
||||
item={item}
|
||||
type={activeType}
|
||||
thumbSize={config.thumbSize}
|
||||
aspect={config.aspect}
|
||||
canAdd={isLibrary}
|
||||
adding={pendingPath === item.file_path}
|
||||
onAdd={() => add(item)}
|
||||
onOpen={() => setViewing(item)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{filtered.length > visible && (
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setRows((r) => r + ROWS_STEP)}
|
||||
>
|
||||
Show more ({filtered.length - visible} left)
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<Dialog
|
||||
open={!!viewing}
|
||||
onOpenChange={(open) => !open && setViewing(null)}
|
||||
>
|
||||
<DialogContent className="w-auto max-w-[calc(100%-2rem)] sm:max-w-[calc(100%-2rem)] gap-3 p-3">
|
||||
<DialogTitle className="sr-only">{config.label} preview</DialogTitle>
|
||||
{viewing && (
|
||||
<>
|
||||
<img
|
||||
src={imageUrls(viewing, activeType, config.thumbSize).full}
|
||||
alt=""
|
||||
className={`max-h-[80vh] max-w-full rounded-lg object-contain ${
|
||||
activeType === "logo" ? `${CHECKER} p-4` : ""
|
||||
}`}
|
||||
/>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground">
|
||||
<span>
|
||||
{viewing.width && viewing.height
|
||||
? `${viewing.width}×${viewing.height}`
|
||||
: "Local file"}
|
||||
{viewing.file_path &&
|
||||
` · ${viewing.language ? languageName(viewing.language) : "No text"}`}
|
||||
</span>
|
||||
{viewing.in_library ? (
|
||||
<LibraryBadge selected={viewing.is_selected} />
|
||||
) : (
|
||||
isLibrary &&
|
||||
viewing.file_path && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => add(viewing)}
|
||||
disabled={pendingPath === viewing.file_path}
|
||||
>
|
||||
{pendingPath === viewing.file_path ? (
|
||||
<Loader2 className="animate-spin" />
|
||||
) : (
|
||||
<Download />
|
||||
)}
|
||||
Add to library
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function LibraryBadge({ selected }: { selected?: boolean }) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-emerald-500/90 px-2 py-0.5 text-[10px] font-semibold text-white shadow">
|
||||
<Check className="h-3 w-3" />
|
||||
{selected ? "Selected" : "In library"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function ArtworkTile({
|
||||
item,
|
||||
type,
|
||||
thumbSize,
|
||||
aspect,
|
||||
canAdd,
|
||||
adding,
|
||||
onAdd,
|
||||
onOpen,
|
||||
}: {
|
||||
item: ArtworkItem;
|
||||
type: ArtworkType;
|
||||
thumbSize: string;
|
||||
aspect: string;
|
||||
canAdd: boolean;
|
||||
adding: boolean;
|
||||
onAdd: () => void;
|
||||
onOpen: () => void;
|
||||
}) {
|
||||
const { thumb } = imageUrls(item, type, thumbSize);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`group relative overflow-hidden rounded-lg bg-muted ring-1 ${
|
||||
item.in_library ? "ring-emerald-500/60" : "ring-border/60"
|
||||
} ${aspect}`}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpen}
|
||||
className="block h-full w-full cursor-zoom-in"
|
||||
aria-label="View full size"
|
||||
>
|
||||
<img
|
||||
src={thumb}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className={`h-full w-full transition-transform duration-300 group-hover:scale-[1.03] ${
|
||||
type === "logo" ? `${CHECKER} object-contain p-3` : "object-cover"
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{/* Top: library badge / language */}
|
||||
<div className="pointer-events-none absolute inset-x-1.5 top-1.5 flex items-start justify-between gap-1">
|
||||
{item.in_library ? (
|
||||
<LibraryBadge selected={item.is_selected} />
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
{item.file_path && item.language && (
|
||||
<span className="rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium uppercase text-white">
|
||||
{item.language}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Bottom: votes + add */}
|
||||
<div className="absolute inset-x-1.5 bottom-1.5 flex items-end justify-between gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
{item.vote_count > 0 ? (
|
||||
<span className="inline-flex items-center gap-0.5 rounded bg-black/60 px-1.5 py-0.5 text-[10px] text-white tabular-nums">
|
||||
<Star className="h-2.5 w-2.5 fill-yellow-400 text-yellow-400" />
|
||||
{item.vote_average.toFixed(1)}
|
||||
</span>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
{canAdd && !item.in_library && item.file_path && (
|
||||
<Button
|
||||
size="xs"
|
||||
onClick={onAdd}
|
||||
disabled={adding}
|
||||
className="shadow"
|
||||
aria-label="Add to library"
|
||||
>
|
||||
{adding ? <Loader2 className="animate-spin" /> : <Download />}
|
||||
Add
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import { useEntryRecommendations } from "@/hooks/useEntries";
|
||||
import {
|
||||
useEntryRecommendations,
|
||||
useTmdbRecommendations,
|
||||
} from "@/hooks/useEntries";
|
||||
import { EntryCard } from "@/components/entries/EntryCard";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
@@ -6,15 +9,23 @@ const GRID =
|
||||
"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 xl:grid-cols-6";
|
||||
const MAX_ITEMS = 12;
|
||||
|
||||
/** "More like this": live TMDB recommendations for a library entry. */
|
||||
/**
|
||||
* "More like this": live TMDB recommendations. Pass `entryId` for a library
|
||||
* entry, or `tmdbId` for one that is not in the library.
|
||||
*/
|
||||
export function RecommendationsSection({
|
||||
entryId,
|
||||
entryId = 0,
|
||||
tmdbId = 0,
|
||||
isTvSeries,
|
||||
}: {
|
||||
entryId: number;
|
||||
entryId?: number;
|
||||
tmdbId?: number;
|
||||
isTvSeries: boolean;
|
||||
}) {
|
||||
const { data, isLoading, isError } = useEntryRecommendations(entryId);
|
||||
const type = isTvSeries ? "tv" : "movie";
|
||||
const library = useEntryRecommendations(entryId);
|
||||
const tmdb = useTmdbRecommendations(entryId ? 0 : tmdbId, type);
|
||||
const { data, isLoading, isError } = entryId ? library : tmdb;
|
||||
|
||||
if (isError) return null;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { entriesApi } from "@/api/entries";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import type { Entry } from "@/types";
|
||||
import type { ArtworkType, Entry } from "@/types";
|
||||
|
||||
export const entryKeys = {
|
||||
all: ["entries"] as const,
|
||||
@@ -10,6 +10,11 @@ export const entryKeys = {
|
||||
seasons: (id: number) => ["entries", id, "seasons"] as const,
|
||||
credits: (id: number) => ["entries", id, "credits"] as const,
|
||||
recommendations: (id: number) => ["entries", id, "recommendations"] as const,
|
||||
artwork: (id: number) => ["entries", id, "artwork"] as const,
|
||||
tmdbArtwork: (tmdbId: number, type: string) =>
|
||||
["entries", "tmdb-artwork", type, tmdbId] as const,
|
||||
tmdbRecommendations: (tmdbId: number, type: string) =>
|
||||
["entries", "tmdb-recommendations", type, tmdbId] as const,
|
||||
tmdbPreview: (tmdbId: number, type: string) =>
|
||||
["entries", "tmdb-preview", type, tmdbId] as const,
|
||||
};
|
||||
@@ -53,6 +58,52 @@ export function useEntryRecommendations(id: number) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useTmdbRecommendations(
|
||||
tmdbId: number,
|
||||
type: "movie" | "tv",
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: entryKeys.tmdbRecommendations(tmdbId, type),
|
||||
queryFn: () => entriesApi.getTmdbRecommendations(type, tmdbId),
|
||||
enabled: !!tmdbId,
|
||||
staleTime: 30 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
/** Artwork for a library entry (TMDB + media table), or by TMDB id otherwise. */
|
||||
export function useArtwork(
|
||||
source: { entryId: number } | { tmdbId: number; type: "movie" | "tv" },
|
||||
) {
|
||||
const isLibrary = "entryId" in source;
|
||||
return useQuery({
|
||||
queryKey: isLibrary
|
||||
? entryKeys.artwork(source.entryId)
|
||||
: entryKeys.tmdbArtwork(source.tmdbId, source.type),
|
||||
queryFn: () =>
|
||||
isLibrary
|
||||
? entriesApi.getArtwork(source.entryId)
|
||||
: entriesApi.getTmdbArtwork(source.type, source.tmdbId),
|
||||
enabled: isLibrary ? !!source.entryId : !!source.tmdbId,
|
||||
staleTime: 10 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAddArtwork(entryId: number) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { type: ArtworkType; file_path: string }) =>
|
||||
entriesApi.addArtwork(entryId, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: entryKeys.artwork(entryId) });
|
||||
queryClient.invalidateQueries({ queryKey: entryKeys.detail(entryId) });
|
||||
queryClient.invalidateQueries({ queryKey: entryKeys.all, exact: true });
|
||||
},
|
||||
onError: () => {
|
||||
toast.error("Failed to add artwork");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEntryCredits(id: number) {
|
||||
return useQuery({
|
||||
queryKey: entryKeys.credits(id),
|
||||
|
||||
@@ -14,7 +14,7 @@ interface TmdbEntryLink {
|
||||
/**
|
||||
* Resolves the correct navigation link for a TmdbEntry.
|
||||
* If the entry is already in the library, links directly to EntryDetailsPage.
|
||||
* Otherwise, links to the TmdbPreviewPage.
|
||||
* Otherwise, links to the TMDB preview of the entry details page.
|
||||
*/
|
||||
export function useTmdbEntryLink(entry: TmdbEntry): TmdbEntryLink {
|
||||
const libraryEntries = useLibraryStore((s) => s.entries);
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -53,11 +53,6 @@ const EntryDetailsPage = lazy(() =>
|
||||
default: m.EntryDetailsPage,
|
||||
})),
|
||||
);
|
||||
const TmdbPreviewPage = lazy(() =>
|
||||
import("@/pages/TmdbPreviewPage").then((m) => ({
|
||||
default: m.TmdbPreviewPage,
|
||||
})),
|
||||
);
|
||||
const TmdbCastsPage = lazy(() =>
|
||||
import("@/pages/TmdbCastsPage").then((m) => ({
|
||||
default: m.TmdbCastsPage,
|
||||
@@ -226,7 +221,7 @@ export const router = createRouter([
|
||||
path: "/entry/tmdb/:type/:tmdbId",
|
||||
element: (
|
||||
<SuspensePage fallback={<EntryDetailsSkeleton />}>
|
||||
<TmdbPreviewPage />
|
||||
<EntryDetailsPage />
|
||||
</SuspensePage>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -426,4 +426,43 @@ export interface TmdbPreview {
|
||||
homepage: string | null;
|
||||
imdb_id: string | null;
|
||||
credits: TmdbPreviewCredit[];
|
||||
/** Same shape as a library Entry, built from the TMDB data */
|
||||
entry?: Entry;
|
||||
seasons?: TmdbPreviewSeason[];
|
||||
}
|
||||
|
||||
export interface TmdbPreviewSeason {
|
||||
id: number;
|
||||
name: string;
|
||||
season_number: number;
|
||||
episode_count: number;
|
||||
air_date: string | null;
|
||||
poster_path: string | null;
|
||||
overview: string | null;
|
||||
tmdb_rating: number | null;
|
||||
}
|
||||
|
||||
/* ---------- Artwork (TMDB images merged with the media table) ---------- */
|
||||
export type ArtworkType = "poster" | "backdrop" | "logo";
|
||||
|
||||
export interface ArtworkItem {
|
||||
/** TMDB file path; null for local-only media (custom uploads, old downloads) */
|
||||
file_path: string | null;
|
||||
width: number | null;
|
||||
height: number | null;
|
||||
aspect_ratio: number | null;
|
||||
language: string | null;
|
||||
vote_average: number;
|
||||
vote_count: number;
|
||||
in_library: boolean;
|
||||
media_id?: number | null;
|
||||
media_path?: string | null;
|
||||
is_selected?: boolean;
|
||||
is_custom?: boolean;
|
||||
}
|
||||
|
||||
export interface ArtworkResponse {
|
||||
posters: ArtworkItem[];
|
||||
backdrops: ArtworkItem[];
|
||||
logos: ArtworkItem[];
|
||||
}
|
||||
Reference in new issue
Block a user