- Collection edit dialog shows the current poster and backdrop when available - Entry details: title is selectable (action row no longer overlays it) - Entry details: clicking the poster opens it full size in a dialog - Library: Favorites and Hidden are toggles that combine with the type tabs
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { getMediaUrl, getTmdbImageUrl } from "@/lib/api";
|
|
import { getBackdropUrl, getPosterUrl } from "@/lib/media-utils";
|
|
import type { Collection, Media } from "@/types";
|
|
|
|
export 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;
|
|
}
|