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 (
);
}
export function CollectionCardSkeleton() {
return ;
}
interface CollectionsGridProps {
collections: Collection[];
isLoading?: boolean;
hasMore?: boolean;
onLoadMore?: () => void;
}
export function CollectionsGrid({
collections,
isLoading,
hasMore,
onLoadMore,
}: CollectionsGridProps) {
const observerRef = useRef(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 (
{Array.from({ length: 12 }).map((_, i) => (
))}
);
}
if (collections.length === 0) {
return (
No collections found.
);
}
return (
{collections.map((collection, index) => (
))}
);
}