Skip to content

Commit f940b99

Browse files
fix recommendations page switching logic
1 parent 03fc3e2 commit f940b99

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/components/page-selector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ const PageSelector: React.FC<PageSelectorProps> = ({
4343
window.scrollTo({ top: window.innerWidth > 786 ? 200 : 400, behavior: 'instant' })
4444
}
4545

46-
if (!skipsToFirst && fetchNext && fetchPrevious && !isLoading) {
47-
if (newPage > page) fetchNext()
48-
else fetchPrevious()
46+
if (!skipsToFirst && !isLoading) {
47+
if (newPage > page && fetchNext) fetchNext()
48+
else if (fetchPrevious) fetchPrevious()
4949
}
5050

5151
if (adjustUrl) {

src/components/recommendations.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const Recommendations = ({
3535
const {
3636
isLoading,
3737
fetchNextPage,
38-
fetchPreviousPage,
3938
isFetchingNextPage,
4039
isFetchingPreviousPage,
4140
data: profilesToRecommend,
@@ -72,7 +71,18 @@ const Recommendations = ({
7271
setPage(1)
7372
}, [userAddress, selectedList, limit])
7473

75-
const hasNextPage = displayedProfiles?.length === limit
74+
const onFetchNextPage = () => {
75+
if (
76+
profilesToRecommend?.pages.length &&
77+
(profilesToRecommend?.pages.length >= 10 || profilesToRecommend?.pages.length - 1 >= page)
78+
)
79+
return
80+
81+
fetchNextPage()
82+
setPage(page + 1)
83+
}
84+
85+
const hasNextPage = useMemo(() => displayedProfiles?.length === limit && page < 10, [displayedProfiles, page])
7686

7787
return (
7888
<div className={cn('bg-neutral shadow-medium flex flex-col gap-2 rounded-sm pt-2 2xl:gap-3', className)}>
@@ -88,8 +98,7 @@ const Recommendations = ({
8898
hasSkipToFirst={false}
8999
adjustUrl={false}
90100
displayPageNumber={false}
91-
fetchNext={fetchNextPage}
92-
fetchPrevious={fetchPreviousPage}
101+
fetchNext={onFetchNextPage}
93102
/>
94103
</Suspense>
95104
)}

0 commit comments

Comments
 (0)