fix(shop): load all filtered products automatically without manual pagination button
- Remove pagination limit cut-off so all matching products are displayed immediately - Remove loadMore button for seamless full catalog browsing
This commit is contained in:
1 parent
22dc217534
commit
ffa6da7978
1 file changed
+4
-41
@@ -284,28 +284,24 @@ export default function ArchivePage({
|
||||
router.push(newUrl, { scroll: false });
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms]);
|
||||
|
||||
const fetchProducts = async (resetPage = true) => {
|
||||
const fetchProducts = async () => {
|
||||
setIsUpdating(true);
|
||||
try {
|
||||
const res = await productService.getProducts({
|
||||
category: selectedCategory,
|
||||
petType: selectedPet,
|
||||
query: searchQuery,
|
||||
// Send the first active symptom to the backend for server-side filtering
|
||||
symptom: activeSymptoms.length === 1 ? activeSymptoms[0] : undefined,
|
||||
page: resetPage ? 1 : page,
|
||||
limit: 20,
|
||||
limit: 999,
|
||||
});
|
||||
|
||||
let result = res.data;
|
||||
// If multiple symptoms selected, filter with OR logic (union of symptoms)
|
||||
// Filter with OR logic (union of symptoms) if symptoms are active
|
||||
if (activeSymptoms.length > 0) {
|
||||
result = result.filter(p => p.symptoms && p.symptoms.some(s => activeSymptoms.includes(s)));
|
||||
}
|
||||
|
||||
setFilteredProducts(result);
|
||||
setMeta(res.meta);
|
||||
if (resetPage) setPage(1);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch products:", error);
|
||||
toast.error("خطا در دریافت لیست محصولات از سرور. لطفاً صفحه را رفرش کنید.");
|
||||
@@ -315,32 +311,9 @@ export default function ArchivePage({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchProducts(true);
|
||||
fetchProducts();
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms]);
|
||||
|
||||
const loadMore = async () => {
|
||||
if (page >= meta.lastPage) return;
|
||||
try {
|
||||
const res = await productService.getProducts({
|
||||
category: selectedCategory,
|
||||
petType: selectedPet,
|
||||
query: searchQuery,
|
||||
symptom: activeSymptoms.length === 1 ? activeSymptoms[0] : undefined,
|
||||
page: page + 1,
|
||||
limit: 20,
|
||||
});
|
||||
let newItems = res.data;
|
||||
if (activeSymptoms.length > 0) {
|
||||
newItems = newItems.filter(p => p.symptoms.some(s => activeSymptoms.includes(s)));
|
||||
}
|
||||
setFilteredProducts(prev => [...prev, ...newItems]);
|
||||
setMeta(res.meta);
|
||||
setPage(prev => prev + 1);
|
||||
} catch (error) {
|
||||
console.error("Failed to load more:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleSymptom = (s: string) => {
|
||||
setActiveSymptoms(prev => prev.includes(s) ? prev.filter(item => item !== s) : [...prev, s]);
|
||||
};
|
||||
@@ -502,16 +475,6 @@ export default function ArchivePage({
|
||||
))}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
{page < meta.lastPage && (
|
||||
<div className="flex justify-center mt-10">
|
||||
<button
|
||||
onClick={loadMore}
|
||||
className="bg-canina-blue text-white px-8 py-3 rounded-xl font-black text-sm hover:scale-105 transition-transform shadow-lg shadow-canina-blue/20"
|
||||
>
|
||||
بارگذاری محصولات بیشتر
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div key="empty" className="bg-white rounded-[3rem] p-20 text-center border-2 border-dashed border-medical-gray-200 flex flex-col items-center">
|
||||
|
||||
Reference in new issue
Block a user