"use client"; import { useLocale, useTranslations } from "next-intl"; import { useEffect, useState } from "react"; import InfiniteScroll from "react-infinite-scroll-component"; import HeroCarousel from "./Carousel"; import CategoryGrid from "./CategoryGrid"; import CollectionSection from "./ProductGrid"; import { useCategories, useCarousels, useCollections } from "@/lib/hooks"; export default function HomePage() { const locale = useLocale(); const t = useTranslations("common"); const [mounted, setMounted] = useState(false); const [visibleCount, setVisibleCount] = useState(10); const { data: categories, isLoading: categoriesLoading, isError: categoriesError, } = useCategories(); const { data: carousels, isLoading: carouselsLoading } = useCarousels(); const { data: collections, isLoading: collectionsLoading, isError: collectionsError, } = useCollections(); useEffect(() => setMounted(true), []); const loadMore = () => { if (collections && visibleCount < collections.length) { setVisibleCount((prev) => Math.min(prev + 10, collections.length)); } }; if (!mounted) return
Loading...
; const carouselItems = carousels?.map((carousel) => ({ title: carousel.title || "", image: carousel.image || carousel.thumbnail, url: carousel.link || null, })) || []; const visibleCollections = collections?.slice(0, visibleCount) || []; const hasMore = collections ? visibleCount < collections.length : false; return (
{!carouselsLoading && carouselItems.length > 0 && ( )} {collectionsError ? (

Failed to load collections. Please try again.

) : collectionsLoading ? (
{Array.from({ length: 3 }).map((_, i) => (
{Array.from({ length: 4 }).map((_, j) => (
))}
))}
) : (

Loading more collections...

} endMessage={

✓ All collections loaded

} scrollThreshold={0.8} >
{visibleCollections.map((collection) => ( ))}
)}
); }