From d3ef8421305a823cfcbf3a444242f525acb4760d Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Mon, 3 Nov 2025 15:50:24 +0100 Subject: [PATCH] feat(annunci): Implement page reset logic in AnnunciList based on data availability --- apps/infoalloggi/src/pages/annunci.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/infoalloggi/src/pages/annunci.tsx b/apps/infoalloggi/src/pages/annunci.tsx index 3fd349b..4321fd3 100644 --- a/apps/infoalloggi/src/pages/annunci.tsx +++ b/apps/infoalloggi/src/pages/annunci.tsx @@ -311,6 +311,23 @@ const AnnunciList = () => { }); }, [data, isPlaceholderData, page]); + useEffect(() => { + // Reset to page 0 if current page has no data or less than page size + const checkPage = async () => { + if (data) { + if (data.annunci.length === 0 && page !== 0) { + await setPage(0); + } + if (data.annunci.length < 6 || !data.hasMore) { + await setPage(0); + } + } + }; + checkPage().catch((err) => { + console.error("Error checking data for page reset:", err); + }); + }, [data, tipo, comune, consegna, sort, setPage]); + if (ricercaLoading) return ; if (status === "error") return ;