diff --git a/react_frontend/src/components/collections/CollectionsGrid.tsx b/react_frontend/src/components/collections/CollectionsGrid.tsx index bdc1594..9f85edd 100644 --- a/react_frontend/src/components/collections/CollectionsGrid.tsx +++ b/react_frontend/src/components/collections/CollectionsGrid.tsx @@ -1,6 +1,6 @@ import { useCallback, useRef, useEffect } from "react"; import { Link } from "react-router-dom"; -import { getCollectionPosterUrl } from "@/lib/media-utils"; +import { getCollectionDisplayPosterUrl } from "@/lib/collection-media"; import { Skeleton } from "@/components/ui/skeleton"; import type { Collection } from "@/types"; @@ -16,7 +16,7 @@ export function CollectionCard({ collection }: CollectionCardProps) { >
{collection.name} s.entries.get(entryProp.id)); + const entry = storeEntry ? { ...entryProp, ...storeEntry } : entryProp; const updateEntry = useUpdateEntry(); const updateRatings = useUpdateEntryRatings(); diff --git a/react_frontend/src/lib/collection-media.ts b/react_frontend/src/lib/collection-media.ts new file mode 100644 index 0000000..b08c1da --- /dev/null +++ b/react_frontend/src/lib/collection-media.ts @@ -0,0 +1,55 @@ +import { getMediaUrl, getTmdbImageUrl } from "@/lib/api"; +import { getBackdropUrl, getPosterUrl } from "@/lib/media-utils"; +import type { Collection, Media } from "@/types"; + +const DEFAULT_POSTER = "/images/default-poster.png"; + +/** + * Collection poster: uploaded poster, then the collection's own TMDB poster, + * then the poster of its first entry, then the default placeholder. + */ +export function getCollectionDisplayPosterUrl(collection: Collection): string { + const selectedPoster = collection.medias?.find( + (m: Media) => m.type === "poster" && m.is_selected, + ); + if (selectedPoster?.path) { + return getMediaUrl("collections", "posters", "preview", selectedPoster.path); + } + + if (collection.poster_path) { + return getTmdbImageUrl(collection.poster_path, "w342"); + } + + const firstEntry = collection.entries?.[0]; + if (firstEntry) { + return getPosterUrl({ ...firstEntry, isInLibrary: true }); + } + + return DEFAULT_POSTER; +} + +/** + * Collection backdrop: uploaded backdrop, then the collection's own TMDB + * backdrop, then the first entry that has one. Null when nothing is available. + */ +export function getCollectionDisplayBackdropUrl( + collection: Collection, +): string | null { + const selectedBackdrop = collection.medias?.find( + (m: Media) => m.type === "backdrop" && m.is_selected, + ); + if (selectedBackdrop?.path) { + return getMediaUrl("collections", "backdrops", "full", selectedBackdrop.path); + } + + if (collection.backdrop_path) { + return getTmdbImageUrl(collection.backdrop_path, "w1280"); + } + + for (const entry of collection.entries ?? []) { + const url = getBackdropUrl(entry); + if (url) return url; + } + + return null; +} diff --git a/react_frontend/src/pages/CollectionDetailsPage.tsx b/react_frontend/src/pages/CollectionDetailsPage.tsx index 58ac08b..dc54601 100644 --- a/react_frontend/src/pages/CollectionDetailsPage.tsx +++ b/react_frontend/src/pages/CollectionDetailsPage.tsx @@ -7,8 +7,10 @@ import { useRemoveEntryFromCollection, } from "@/hooks/useCollections"; import { EntryLibraryGrid } from "@/components/entries/EntryLibraryGrid"; -import { getCollectionPosterUrl, getBackdropUrl } from "@/lib/media-utils"; -import { getTmdbImageUrl } from "@/lib/api"; +import { + getCollectionDisplayBackdropUrl, + getCollectionDisplayPosterUrl, +} from "@/lib/collection-media"; import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button"; import { @@ -101,21 +103,11 @@ export function CollectionDetailsPage() { }); }, [entries, sortField, sortDir]); - // Fallback backdrop: use first entry's backdrop if collection has none - const backdropUrl = useMemo(() => { - if (collection?.backdrop_path) - return getTmdbImageUrl(collection.backdrop_path, "w1280"); - // Try to find a backdrop from one of the entries - const entryWithBackdrop = entries.find((e) => e.banner_path); - if (entryWithBackdrop?.banner_path) - return getTmdbImageUrl(entryWithBackdrop.banner_path, "w1280"); - // Try entry medias - for (const e of entries) { - const url = getBackdropUrl(e); - if (url) return url; - } - return null; - }, [collection?.backdrop_path, entries]); + // Uploaded backdrop wins, then TMDB backdrop, then the first entry's backdrop + const backdropUrl = useMemo( + () => (collection ? getCollectionDisplayBackdropUrl(collection) : null), + [collection], + ); const handleSort = (field: CollectionSortField) => { if (field === sortField) { @@ -254,7 +246,7 @@ export function CollectionDetailsPage() {
{collection.name}