import { useEffect } from "react"; import { MetaFunction } from "@remix-run/node"; import { Link, useNavigate } from "@remix-run/react"; import { safeGoBack } from "~/utils/helpers"; import { useCollectionsInfiniteQuery } from "~/requestHandler/use-collection-hooks"; import { Skeleton } from "~/components/ui/skeleton"; import { Package, RefreshCw, ArrowRight, ShoppingBag, Calendar, } from "lucide-react"; export default function Collections() { const navigate = useNavigate(); const { data, fetchNextPage, hasNextPage, isFetchingNextPage, status, refetch, } = useCollectionsInfiniteQuery({ pageSize: 20, }); // Flatten all collections from all pages const allCollections = data?.pages.flatMap((page) => page.results) || []; // Format date helper const formatDate = (dateString?: string) => { if (!dateString) return ""; const date = new Date(dateString); return new Intl.DateTimeFormat("fa-IR", { year: "numeric", month: "long", day: "numeric", }).format(date); }; // Loading skeleton const CollectionSkeleton = () => (
{Array.from({ length: 6 }).map((_, index) => (
))}
); // Empty state const EmptyState = () => (

کالکشنی یافت نشد

در حال حاضر کالکشنی موجود نیست.

); // Error state const ErrorState = () => (

خطا در بارگذاری کالکشن‌ها

متاسفانه در بارگذاری کالکشن‌ها مشکلی پیش آمد.

); // Handle scroll for infinite loading useEffect(() => { const handleScroll = () => { if ( window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 500 && hasNextPage && !isFetchingNextPage ) { fetchNextPage(); } }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, [hasNextPage, isFetchingNextPage, fetchNextPage]); const handleBack = () => { safeGoBack(navigate); }; return (
{/* Header - مطابق با ProfilePagesHeader */}

کالکشن‌ها

{/* Content */}
{status === "pending" ? ( ) : status === "error" ? ( ) : allCollections.length === 0 ? ( ) : ( <>
{allCollections.map((collection) => (
{/* Collection Image - بزرگ */}
{collection.coverImageUrl ? ( {collection.title ) : (
)} {/* Product Count Badge */} {collection.productCount !== undefined && (
{collection.productCount} محصول
)}
{/* Collection Info */}

{collection.title || "بدون عنوان"}

{collection.description && (

{collection.description}

)} {/* Bottom Info Row */}
{/* Created Date */} {collection.createdAt && (
{formatDate(collection.createdAt)}
)}
))}
{/* Loading More Indicator */} {isFetchingNextPage && (
)} )}
); } export const meta: MetaFunction = () => { const title = "کالکشن‌های ویترون | مجموعه محصولات منتخب"; const description = "مشاهده مجموعه‌های منتخب از بهترین محصولات ویترون. کالکشن‌های منحصر به فرد و با کیفیت."; const imageUrl = "https://vitrownstatics.s3.ir-thr-at1.arvanstorage.ir/SVG-06.svg?versionId="; return [ { title }, { name: "description", content: description }, { name: "keywords", content: "کالکشن، مجموعه محصولات، محصولات منتخب، ویترون، خرید آنلاین", }, { name: "robots", content: "index, follow" }, // Open Graph { property: "og:type", content: "website" }, { property: "og:title", content: title }, { property: "og:description", content: description }, { property: "og:image", content: imageUrl }, { property: "og:site_name", content: "ویترون" }, { property: "og:locale", content: "fa_IR" }, // Twitter Card { name: "twitter:card", content: "summary_large_image" }, { name: "twitter:title", content: title }, { name: "twitter:description", content: description }, { name: "twitter:image", content: imageUrl }, ]; };