Skip to content

Commit

Permalink
Fix delegators pagination (#12)
Browse files Browse the repository at this point in the history
* remove unnecessary and breaking deps for pagination useEffects
  • Loading branch information
lukachi authored May 17, 2024
1 parent 4c07947 commit 16d9945
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].

## [1.4.6] - 2024-05-17
### Fixed
- `useTablePagination` hook

## [1.4.5] - 2024-05-09
### Fixed
- `ProposalDepositsRow` deposit tx parsing
Expand Down Expand Up @@ -124,7 +128,8 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

- Initiated project

[Unreleased]: https://gitlab.com/rarimo/scan/compare/1.4.5...HEAD
[Unreleased]: https://gitlab.com/rarimo/scan/compare/1.4.6...HEAD
[1.4.6]: https://gitlab.com/rarimo/scan/compare/1.4.5...1.4.6
[1.4.5]: https://gitlab.com/rarimo/scan/compare/1.4.4...1.4.5
[1.4.4]: https://gitlab.com/rarimo/scan/compare/1.4.3...1.4.4
[1.4.3]: https://gitlab.com/rarimo/scan/compare/1.4.2...1.4.3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scan",
"version": "1.4.5",
"version": "1.4.6",
"private": true,
"gitHooks": {
"pre-commit": "yarn lint",
Expand Down
38 changes: 25 additions & 13 deletions src/components/TableWithPagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'
import {
Skeleton,
Stack,
Table,
TableBody,
TableContainer,
Expand Down Expand Up @@ -53,7 +55,29 @@ export default function TableWithPagination({
}) {
const theme = useTheme()

const table = (
if (isLoading) {
return (
<Stack spacing={2}>
{Array.from({ length: limit }).map((_, idx) => {
return <Skeleton key={idx} variant='rectangular' height={TABLE_LIST_HEAD_ROW_HEIGHT} />
})}
</Stack>
)
}

if (!rows?.length || isLoadingError) {
return (
<NoData
isError={isLoadingError}
title={noDataTitle}
subtitle={noDataSubtitle}
errorTitle={errorTitle}
errorSubtitle={errorSubtitle}
/>
)
}

return (
<>
<TableContainer
sx={{
Expand Down Expand Up @@ -127,16 +151,4 @@ export default function TableWithPagination({
/>
</>
)

return !isLoading && (!rows?.length || isLoadingError) ? (
<NoData
isError={isLoadingError}
title={noDataTitle}
subtitle={noDataSubtitle}
errorTitle={errorTitle}
errorSubtitle={errorSubtitle}
/>
) : (
table
)
}
5 changes: 3 additions & 2 deletions src/components/Validator/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ValidatorDelegationsFilters, ValidatorDelegationsFiltersMapStringKey }

export default function Validator({ operator }: { operator: string }) {
const { limit, offset, handleChangePage, handleChangeRowsPerPage, setOffset, setTableKey } =
useTablePagination()
useTablePagination('validator_delegations')

const { filter, handleFilterChange } = useTabsFilter({
queryKey: 'delegation_type',
Expand Down Expand Up @@ -82,7 +82,8 @@ export default function Validator({ operator }: { operator: string }) {

useEffect(() => {
setKey()
}, [filter, setKey, setTableKey])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [filter])

useEffect(() => {
setKey()
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useTablePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export const useTablePagination = <T = unknown>(tableKey?: string) => {

useEffect(() => {
replaceUrl()
}, [limit, offset, order, orderBy, replaceUrl, table])

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [limit, offset, order, orderBy, table])

useEffect(() => {
replaceUrl()
Expand Down

0 comments on commit 16d9945

Please sign in to comment.