From d3f4d2cb96b47b4e54159ce77f61fe9b5420456e Mon Sep 17 00:00:00 2001 From: Giovanni Martire Date: Sun, 14 Jan 2024 10:31:31 +0100 Subject: [PATCH] Fix pagination crash when filters were applied --- app/actions.ts | 8 +------- components/Pagination/Pagination.tsx | 6 +++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/actions.ts b/app/actions.ts index fcfe69e..f9772fb 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -414,8 +414,6 @@ export async function fetchDashboard() { export async function paginationParamsToURL(params: {}) { let url = ''; - console.log(params); - if (Object.keys(params).length > 0) { Object.keys(params).forEach((key, index) => { if (key === 'page') return; @@ -424,20 +422,16 @@ export async function paginationParamsToURL(params: {}) { let string = `${index !== 0 ? '&' : ''}${key}=`; params[key].forEach((value, index) => { - console.log(value); string += `${value}${index === 0 ? `&${key}=` : ''}`; }); - return (url += `${string}${ - index === Object.keys(params).length - 1 ? '&' : '' - }`); + return (url += `${string}`); } return (url += `${index !== 0 ? '&' : ''}${key}=${params[key]}${ index === Object.keys(params).length - 1 ? '&' : '' }`); }); - console.log(url); } return url; diff --git a/components/Pagination/Pagination.tsx b/components/Pagination/Pagination.tsx index 150231e..6f2ddce 100644 --- a/components/Pagination/Pagination.tsx +++ b/components/Pagination/Pagination.tsx @@ -37,7 +37,7 @@ export default function Pagination({ const onPageChange = async (number: number) => { let url = await paginationParamsToURL(params); - router.push(`/leaderboards?${url}page=${number}#leaderboard`, { + router.push(`/leaderboards?${url}&page=${number}#leaderboard`, { scroll: true, }); @@ -53,7 +53,7 @@ export default function Pagination({ const onNext = async () => { if (currentPage < parseInt(lastPage)) { let url = await paginationParamsToURL(params); - router.push(`/leaderboards?${url}page=${currentPage + 1}#leaderboard`, { + router.push(`/leaderboards?${url}&page=${currentPage + 1}#leaderboard`, { scroll: true, }); } @@ -62,7 +62,7 @@ export default function Pagination({ const onPrevious = async () => { if (currentPage > 1) { let url = await paginationParamsToURL(params); - router.push(`/leaderboards?${url}page=${currentPage - 1}#leaderboard`, { + router.push(`/leaderboards?${url}&page=${currentPage - 1}#leaderboard`, { scroll: true, }); }