Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c74e54bc2a | ||
|
|
72600cbc5d |
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useRef, useEffect } from "react";
|
import { useCallback, useRef, useEffect } from "react";
|
||||||
import { Link } from "react-router-dom";
|
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 { Skeleton } from "@/components/ui/skeleton";
|
||||||
import type { Collection } from "@/types";
|
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">
|
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
||||||
<img
|
<img
|
||||||
src={getCollectionPosterUrl(collection)}
|
src={getCollectionDisplayPosterUrl(collection)}
|
||||||
alt={collection.name}
|
alt={collection.name}
|
||||||
className="h-full w-full object-cover transition-transform group-hover:scale-105"
|
className="h-full w-full object-cover transition-transform group-hover:scale-105"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Switch } from "@/components/ui/switch";
|
|||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { useUpdateEntry, useUpdateEntryRatings } from "@/hooks/useEntries";
|
import { useUpdateEntry, useUpdateEntryRatings } from "@/hooks/useEntries";
|
||||||
import { StarRating } from "@/components/ui/star-rating";
|
import { StarRating } from "@/components/ui/star-rating";
|
||||||
|
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||||
import type { Entry } from "@/types";
|
import type { Entry } from "@/types";
|
||||||
|
|
||||||
interface EntrySettingsDialogProps {
|
interface EntrySettingsDialogProps {
|
||||||
@@ -20,8 +21,12 @@ interface EntrySettingsDialogProps {
|
|||||||
export function EntrySettingsDialog({
|
export function EntrySettingsDialog({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
entry,
|
entry: entryProp,
|
||||||
}: EntrySettingsDialogProps) {
|
}: 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 updateEntry = useUpdateEntry();
|
||||||
const updateRatings = useUpdateEntryRatings();
|
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,
|
useRemoveEntryFromCollection,
|
||||||
} from "@/hooks/useCollections";
|
} from "@/hooks/useCollections";
|
||||||
import { EntryLibraryGrid } from "@/components/entries/EntryLibraryGrid";
|
import { EntryLibraryGrid } from "@/components/entries/EntryLibraryGrid";
|
||||||
import { getCollectionPosterUrl, getBackdropUrl } from "@/lib/media-utils";
|
import {
|
||||||
import { getTmdbImageUrl } from "@/lib/api";
|
getCollectionDisplayBackdropUrl,
|
||||||
|
getCollectionDisplayPosterUrl,
|
||||||
|
} from "@/lib/collection-media";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -101,21 +103,11 @@ export function CollectionDetailsPage() {
|
|||||||
});
|
});
|
||||||
}, [entries, sortField, sortDir]);
|
}, [entries, sortField, sortDir]);
|
||||||
|
|
||||||
// Fallback backdrop: use first entry's backdrop if collection has none
|
// Uploaded backdrop wins, then TMDB backdrop, then the first entry's backdrop
|
||||||
const backdropUrl = useMemo(() => {
|
const backdropUrl = useMemo(
|
||||||
if (collection?.backdrop_path)
|
() => (collection ? getCollectionDisplayBackdropUrl(collection) : null),
|
||||||
return getTmdbImageUrl(collection.backdrop_path, "w1280");
|
[collection],
|
||||||
// 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]);
|
|
||||||
|
|
||||||
const handleSort = (field: CollectionSortField) => {
|
const handleSort = (field: CollectionSortField) => {
|
||||||
if (field === sortField) {
|
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="absolute bottom-0 left-0 right-0 flex items-end p-6">
|
||||||
<div className="flex items-end gap-4">
|
<div className="flex items-end gap-4">
|
||||||
<img
|
<img
|
||||||
src={getCollectionPosterUrl(collection)}
|
src={getCollectionDisplayPosterUrl(collection)}
|
||||||
alt={collection.name}
|
alt={collection.name}
|
||||||
className="h-32 w-auto rounded-lg shadow-lg sm:h-40"
|
className="h-32 w-auto rounded-lg shadow-lg sm:h-40"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user