Skip to content

Commit 6aa9e14

Browse files
committed
Fix pagination on my polls page
1 parent da851ce commit 6aa9e14

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/pages/me/polls/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const MyPolls: NextPage = () => {
4444
POLLS_PER_PAGE * page,
4545
POLLS_PER_PAGE * page + POLLS_PER_PAGE
4646
);
47-
const canGoNext = page < Math.floor(polls.length / POLLS_PER_PAGE);
47+
const canGoNext = page + 1 < polls.length / POLLS_PER_PAGE;
4848
const canGoBack = page > 0;
4949
const hasPolls = paginatedPolls.length > 0;
5050

@@ -91,6 +91,13 @@ const MyPolls: NextPage = () => {
9191
}
9292
};
9393

94+
useEffect(() => {
95+
const pagesOverflow = page * POLLS_PER_PAGE >= polls.length;
96+
if (pagesOverflow && !isLoading) {
97+
setPage((prev) => prev - 1);
98+
}
99+
}, [polls, page, isLoading]);
100+
94101
useEffect(() => {
95102
if (id) {
96103
loadPolls();

0 commit comments

Comments
 (0)