Fix collection images and entry settings toggles
- Show the uploaded backdrop on the collection details page; it only looked at the TMDB backdrop and ignored the collection's media - Fall back to the first entry's poster for collections without a poster on both the collections grid and the details page - Read the live entry from the library store in EntrySettingsDialog so toggles reflect the new value instead of a stale prop snapshot
This commit is contained in:
1 parent
a9e4eea856
commit
72600cbc5d
4 files changed
+73
-21
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user