- 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
103 lines
3.0 KiB
TypeScript
103 lines
3.0 KiB
TypeScript
import { useCallback, useRef, useEffect } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { getCollectionDisplayPosterUrl } from "@/lib/collection-media";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import type { Collection } from "@/types";
|
|
|
|
interface CollectionCardProps {
|
|
collection: Collection;
|
|
}
|
|
|
|
export function CollectionCard({ collection }: CollectionCardProps) {
|
|
return (
|
|
<Link
|
|
to={`/collections/${collection.id}`}
|
|
className="group overflow-hidden rounded-lg transition-all hover:scale-[1.02] hover:shadow-lg"
|
|
>
|
|
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
|
<img
|
|
src={getCollectionDisplayPosterUrl(collection)}
|
|
alt={collection.name}
|
|
className="h-full w-full object-cover transition-transform group-hover:scale-105"
|
|
loading="lazy"
|
|
/>
|
|
<div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-3">
|
|
<p className="text-sm font-medium text-white line-clamp-2">
|
|
{collection.name}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
export function CollectionCardSkeleton() {
|
|
return <Skeleton className="aspect-[2/3] w-full rounded-lg" />;
|
|
}
|
|
|
|
interface CollectionsGridProps {
|
|
collections: Collection[];
|
|
isLoading?: boolean;
|
|
hasMore?: boolean;
|
|
onLoadMore?: () => void;
|
|
}
|
|
|
|
export function CollectionsGrid({
|
|
collections,
|
|
isLoading,
|
|
hasMore,
|
|
onLoadMore,
|
|
}: CollectionsGridProps) {
|
|
const observerRef = useRef<IntersectionObserver | null>(null);
|
|
|
|
const lastItemRef = useCallback(
|
|
(node: HTMLDivElement | null) => {
|
|
if (isLoading) return;
|
|
if (observerRef.current) observerRef.current.disconnect();
|
|
observerRef.current = new IntersectionObserver((entries) => {
|
|
if (entries[0].isIntersecting && hasMore && onLoadMore) {
|
|
onLoadMore();
|
|
}
|
|
});
|
|
if (node) observerRef.current.observe(node);
|
|
},
|
|
[isLoading, hasMore, onLoadMore],
|
|
);
|
|
|
|
useEffect(() => {
|
|
return () => observerRef.current?.disconnect();
|
|
}, []);
|
|
if (isLoading) {
|
|
return (
|
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
|
{Array.from({ length: 12 }).map((_, i) => (
|
|
<CollectionCardSkeleton key={i} />
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (collections.length === 0) {
|
|
return (
|
|
<div className="flex h-40 items-center justify-center text-muted-foreground">
|
|
No collections found.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
|
{collections.map((collection, index) => (
|
|
<div
|
|
key={collection.id}
|
|
ref={index === collections.length - 1 ? lastItemRef : undefined}
|
|
className="animate-card-enter"
|
|
style={{ animationDelay: `${Math.min(index * 30, 300)}ms` }}
|
|
>
|
|
<CollectionCard collection={collection} />
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|