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 ;