Skip to content

Commit

Permalink
Fix pagination crash when filters were applied
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinariHex committed Jan 14, 2024
1 parent 4bd89f1 commit d3f4d2c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
8 changes: 1 addition & 7 deletions app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});
}
Expand All @@ -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,
});
}
Expand Down

0 comments on commit d3f4d2c

Please sign in to comment.