Skip to content

Commit

Permalink
fix: visit page 1 when page size is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Jan 26, 2024
1 parent d3e8502 commit 500453d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pages/Transaction/TransactionComp/TransactionComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ export const TransactionComp = ({
const handlePageChange = (type: 'inputs' | 'outputs') => (page: number, size?: number) => {
const pageField = `page_of_${type}`
const searchParams = new URLSearchParams(search)
searchParams.set(pageField, `${page}`)
if (size) {
searchParams.set('page_size', `${size}`)
const total = (type === 'inputs' ? displayInputs.meta?.total : displayOutputs.meta?.total) ?? 0
const maxPage = Math.ceil(total / size)
if (page > maxPage) {
searchParams.set(pageField, `${maxPage}`)
}
searchParams.delete('page_of_inputs')
searchParams.delete('page_of_outputs')
} else {
searchParams.set(pageField, `${page}`)
}
const url = `${pathname}?${searchParams.toString()}`
history.push(url)
Expand Down

0 comments on commit 500453d

Please sign in to comment.