Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72600cbc5d |
No files matched your search
@@ -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) {
|
||||
>
|
||||
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
||||
<img
|
||||
src={getCollectionPosterUrl(collection)}
|
||||
src={getCollectionDisplayPosterUrl(collection)}
|
||||
alt={collection.name}
|
||||
className="h-full w-full object-cover transition-transform group-hover:scale-105"
|
||||
loading="lazy"
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Switch } from "@/components/ui/switch";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { useUpdateEntry, useUpdateEntryRatings } from "@/hooks/useEntries";
|
||||
import { StarRating } from "@/components/ui/star-rating";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import type { Entry } from "@/types";
|
||||
|
||||
interface EntrySettingsDialogProps {
|
||||
@@ -20,8 +21,12 @@ interface EntrySettingsDialogProps {
|
||||
export function EntrySettingsDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entry,
|
||||
entry: entryProp,
|
||||
}: EntrySettingsDialogProps) {
|
||||
// The entry prop can be a stale snapshot (e.g. from a collection query), so
|
||||
// read the live copy from the library store, which updates on every mutation.
|
||||
const storeEntry = useLibraryStore((s) => s.entries.get(entryProp.id));
|
||||
const entry = storeEntry ? { ...entryProp, ...storeEntry } : entryProp;
|
||||
const updateEntry = useUpdateEntry();
|
||||
const updateRatings = useUpdateEntryRatings();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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() {
|
||||
<div className="absolute bottom-0 left-0 right-0 flex items-end p-6">
|
||||
<div className="flex items-end gap-4">
|
||||
<img
|
||||
src={getCollectionPosterUrl(collection)}
|
||||
src={getCollectionDisplayPosterUrl(collection)}
|
||||
alt={collection.name}
|
||||
className="h-32 w-auto rounded-lg shadow-lg sm:h-40"
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user