feat(annunci): Implement page reset logic in AnnunciList based on data availability

This commit is contained in:
Marco Pedone 2025-11-03 15:50:24 +01:00
parent 16bb7094dc
commit d3ef842130

View file

@ -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 <LoadingPage />;
if (status === "error") return <Status500 />;