feat(annunci): Implement page reset logic in AnnunciList based on data availability
This commit is contained in:
parent
16bb7094dc
commit
d3ef842130
1 changed files with 17 additions and 0 deletions
|
|
@ -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 />;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue