feat(catalog): add progressive product pagination and load more action
Deploy Canina / deploy (push) Successful in 2m8s

This commit is contained in:
devops committed 2026-10-17 10:04:10 +00:00
1 parent d77ddd4bb2
commit 8326e10ce8
1 file changed
+77 -43
+77 -43
View File
@@ -469,6 +469,7 @@ export default function ArchivePage({
const [sortBy, setSortBy] = useState<string>("createdAt");
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc");
const [viewMode, setViewMode] = useState<"list" | "grid">("list");
const [visibleCount, setVisibleCount] = useState<number>(12);
const [isMobileSolutionsOpen, setIsMobileSolutionsOpen] = useState(false);
const [isMobileSymptomsOpen, setIsMobileSymptomsOpen] = useState(false);
@@ -545,6 +546,7 @@ export default function ArchivePage({
setSelectedPet((initialPetType as PetType) || "all");
setActiveSymptoms(initialSymptoms ? initialSymptoms.split(',').filter(Boolean) : []);
}
setVisibleCount(12);
}, [initialCategory, initialSearch, initialPetType, initialSymptoms]);
// Update URL Query Parameters
@@ -584,6 +586,7 @@ export default function ArchivePage({
}
setFilteredProducts(orderProductsByAvailability(result));
setVisibleCount(12);
} catch (error) {
console.error("Failed to fetch products:", error);
toast.error("خطا در دریافت لیست محصولات از سرور. لطفاً صفحه را رفرش کنید.");
@@ -1107,49 +1110,80 @@ export default function ArchivePage({
)
) : filteredProducts.length > 0 ? (
<>
{/* Keep API sort order inside each availability section. */}
{([{
key: "available",
title: "محصولات موجود",
products: filteredProducts.filter(product => !isProductOutOfStock(product)),
}, {
key: "unavailable",
title: "محصولات ناموجود",
products: filteredProducts.filter(product => isProductOutOfStock(product)),
}] as const).map(section => section.products.length > 0 && (
<section key={section.key} data-testid={`products-${section.key}`} className="mb-10 last:mb-0">
<h2 className="mb-5 text-xl font-black text-medical-gray-900">{section.title}</h2>
{/* Mobile List View vs Card View (Desktop is always responsive multi-column grid) */}
<div
key={viewMode}
className={
viewMode === "list"
? "flex flex-col gap-3 lg:grid lg:grid-cols-2 xl:grid-cols-4 lg:gap-6"
: "grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6"
}
>
<AnimatePresence mode="popLayout">
{section.products.map((p: Product) => (
<React.Fragment key={p.id}>
{/* In list mode on mobile, render ArchiveProductListItem; on desktop (lg+), render standard card */}
{viewMode === "list" ? (
<>
<div className="block lg:hidden w-full">
<ArchiveProductListItem product={p} />
</div>
<div className="hidden lg:block h-full">
<ArchiveProductCard product={p} />
</div>
</>
) : (
<ArchiveProductCard product={p} />
)}
</React.Fragment>
))}
</AnimatePresence>
</div>
</section>
))}
{/* Progressive slice of products for optimal DOM density and mobile UX */}
{(() => {
const slicedProducts = filteredProducts.slice(0, visibleCount);
const hasMore = visibleCount < filteredProducts.length;
const sections = [
{
key: "available",
title: "محصولات موجود",
products: slicedProducts.filter(product => !isProductOutOfStock(product)),
},
{
key: "unavailable",
title: "محصولات ناموجود",
products: slicedProducts.filter(product => isProductOutOfStock(product)),
}
] as const;
return (
<>
{sections.map(section => section.products.length > 0 && (
<section key={section.key} data-testid={`products-${section.key}`} className="mb-8 last:mb-0">
<div className="flex items-center justify-between mb-4">
<h2 className="text-xl font-black text-medical-gray-900">{section.title}</h2>
<span className="text-xs font-bold text-medical-gray-400">
{toPersian(section.products.length)} محصول
</span>
</div>
<div
key={viewMode}
className={
viewMode === "list"
? "flex flex-col gap-3 lg:grid lg:grid-cols-2 xl:grid-cols-4 lg:gap-6"
: "grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6"
}
>
<AnimatePresence mode="popLayout">
{section.products.map((p: Product) => (
<React.Fragment key={p.id}>
{viewMode === "list" ? (
<>
<div className="block lg:hidden w-full">
<ArchiveProductListItem product={p} />
</div>
<div className="hidden lg:block h-full">
<ArchiveProductCard product={p} />
</div>
</>
) : (
<ArchiveProductCard product={p} />
)}
</React.Fragment>
))}
</AnimatePresence>
</div>
</section>
))}
{hasMore && (
<div className="mt-8 mb-4 text-center">
<button
type="button"
onClick={() => setVisibleCount(prev => prev + 12)}
className="inline-flex items-center gap-2 px-6 py-3 bg-white border border-medical-gray-200 hover:border-canina-blue text-canina-blue font-black text-xs sm:text-sm rounded-2xl shadow-xs hover:shadow-md active:scale-95 transition-all cursor-pointer font-vazir"
>
<span>مشاهده ۱۲ محصول بیشتر</span>
<span className="text-xs text-medical-gray-400 font-bold">
(نمایش {toPersian(slicedProducts.length)} از {toPersian(filteredProducts.length)})
</span>
</button>
</div>
)}
</>
);
})()}
{/* SEO Category Rich Description Section (Rendered below products to maintain primary UX while boosting category SEO) */}
{selectedCategory !== "all" && (