From 8326e10ce801a23453302b58c2ae115a61d83f4e Mon Sep 17 00:00:00 2001 From: devops Date: Sat, 17 Oct 2026 10:04:10 +0000 Subject: [PATCH] feat(catalog): add progressive product pagination and load more action --- .../application/components/ArchivePage.tsx | 120 +++++++++++------- 1 file changed, 77 insertions(+), 43 deletions(-) diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx index 919e6c9d..577cde51 100644 --- a/frontend/application/components/ArchivePage.tsx +++ b/frontend/application/components/ArchivePage.tsx @@ -469,6 +469,7 @@ export default function ArchivePage({ const [sortBy, setSortBy] = useState("createdAt"); const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc"); const [viewMode, setViewMode] = useState<"list" | "grid">("list"); + const [visibleCount, setVisibleCount] = useState(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.title}

- {/* Mobile List View vs Card View (Desktop is always responsive multi-column grid) */} -
- - {section.products.map((p: Product) => ( - - {/* In list mode on mobile, render ArchiveProductListItem; on desktop (lg+), render standard card */} - {viewMode === "list" ? ( - <> -
- -
-
- -
- - ) : ( - - )} -
- ))} -
-
-
- ))} + {/* 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.title}

+ + {toPersian(section.products.length)} محصول + +
+
+ + {section.products.map((p: Product) => ( + + {viewMode === "list" ? ( + <> +
+ +
+
+ +
+ + ) : ( + + )} +
+ ))} +
+
+
+ ))} + + {hasMore && ( +
+ +
+ )} + + ); + })()} {/* SEO Category Rich Description Section (Rendered below products to maintain primary UX while boosting category SEO) */} {selectedCategory !== "all" && (