Skip to content

Commit

Permalink
fix: going back in browser pagination working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Wolfgram authored and Daniel Wolfgram committed Feb 1, 2024
1 parent 046f402 commit a4180c1
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const INITIAL_LIMIT = 20
const TransactionHistoryTable = () => {
const onError = usePrintErrorMessage()

const [_ = INITIAL_PAGE, setPage] = useQueryParam('page', NumberParam)
const [page = INITIAL_PAGE, setPage] = useQueryParam('page', NumberParam)
const [limit = INITIAL_LIMIT, setLimit] = useQueryParam('limit', NumberParam)
const [pageIndex, setPageIndex] = useState(INITIAL_PAGE_INDEX)
const currentPageIndex = page ? page - 1 : INITIAL_PAGE_INDEX

const {
isPending: accountsIsPending,
Expand All @@ -33,20 +33,16 @@ const TransactionHistoryTable = () => {
error: transactionsError,
data: transactionsData,
} = useFetchAccountTransactions(accountsData?.accounts[0]?.id ?? '', {
page: pageIndex,
page: currentPageIndex,
limit: limit ?? INITIAL_LIMIT,
})

useEffect(() => {
setPage(pageIndex + 1)
}, [pageIndex, setPage])

const handlePaginationChange = useCallback(
({ pageIndex, pageSize }: PaginationConfig) => {
setPageIndex(pageIndex)
setLimit(pageSize)
setPage(pageIndex + 1)
},
[setPageIndex, setLimit],
[setLimit, setPage],
)

const tableData = {
Expand Down Expand Up @@ -77,7 +73,7 @@ const TransactionHistoryTable = () => {
handlePagination={handlePaginationChange}
options={{ sort: true, pagination: true }}
paginationConfig={{
pageIndex,
pageIndex: currentPageIndex,
pageSize: limit ?? INITIAL_LIMIT,
}}
/>
Expand Down

0 comments on commit a4180c1

Please sign in to comment.