Skip to content

Commit

Permalink
Use no total count paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Jun 10, 2024
1 parent 7f939d7 commit 42ea2f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Process/ProcessList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useQueryParams from '~src/router/use-query-params'
import { InputSearch } from '~src/layout/Inputs'
import { IElectionListFilter } from '@vocdoni/sdk'
import { Button, Checkbox, Flex } from '@chakra-ui/react'
import { isEmpty } from '~utils/objects'

type FilterQueryParams = {
[K in keyof Omit<IElectionListFilter, 'organizationId'>]: string
Expand All @@ -22,7 +23,9 @@ export const ProcessSearchBox = () => {

return (
<Flex direction={{ base: 'column', lg: 'row' }} align={'center'} justify={'end'} gap={4}>
<Checkbox onChange={(e) => setQueryParams({ ...queryParams, withResults: e.target.checked ? 'true' : 'false' })}>
<Checkbox
onChange={(e) => setQueryParams({ ...queryParams, withResults: e.target.checked ? 'true' : undefined })}
>
<Trans i18nKey='process.show_with_results'>Show only processes with results</Trans>
</Checkbox>
<Flex justify='flex-end'>
Expand Down Expand Up @@ -83,6 +86,12 @@ export const PaginatedProcessList = () => {
const count = processCount || 0
const { queryParams: processFilters } = useQueryParams<FilterQueryParams>()

// If no filters applied we can calculate the total pages using process total count
let totalPages: number | undefined = undefined
if (isEmpty(processFilters)) {
totalPages = Math.ceil(count / 10)
}

const {
data: processes,
isLoading: isLoadingOrgs,
Expand All @@ -109,7 +118,7 @@ export const PaginatedProcessList = () => {
}

return (
<RoutedPaginationProvider totalPages={Math.ceil(count / 10)} path={processListPath}>
<RoutedPaginationProvider totalPages={totalPages} path={processListPath}>
{processes?.elections.map((election, i) => <ElectionCard key={i} election={election} />)}
<RoutedPagination />
</RoutedPaginationProvider>
Expand Down
3 changes: 3 additions & 0 deletions src/utils/objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isEmpty(obj?: object): boolean {
return !obj || Object.keys(obj).length === 0
}

0 comments on commit 42ea2f5

Please sign in to comment.