Skip to content

Commit

Permalink
Handle situation when there are 0 votes
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed May 16, 2024
1 parent dfeffc9 commit 92fa16d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/app/pages/ProposalDetailsPage/ProposalVotesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AppErrors } from '../../../types/errors'
import { ErrorBoundary } from '../../components/ErrorBoundary'
import Box from '@mui/material/Box'
import { NoMatchingDataMaybeClearFilters, TableSearchBar } from '../../components/Search/TableSearchBar'
import { CardEmptyState } from '../../components/CardEmptyState'

type ProposalVotesProps = {
isLoading: boolean
Expand Down Expand Up @@ -84,18 +85,19 @@ export const ProposalVotesView: FC = () => {
const proposalId = parseInt(useParams().proposalId!, 10)

const { clearFilters } = useVoteFiltering(t)
const { results, isLoading, isOnNonexistentPage, hasNoResultsBecauseOfFilters } = useVotes(
network,
proposalId,
t,
)
const { results, isLoading, isOnNonexistentPage, hasNoResultsBecauseOfFilters, hasNoResultsWhatsoever } =
useVotes(network, proposalId, t)

if (isOnNonexistentPage) throw AppErrors.PageDoesNotExist

if (hasNoResultsBecauseOfFilters) {
return <NoMatchingDataMaybeClearFilters clearFilters={clearFilters} />
}

if (hasNoResultsWhatsoever) {
return <CardEmptyState label={t('networkProposal.thereAreNoVotes')} />
}

return (
<ProposalVotes
isLoading={isLoading}
Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/ProposalDetailsPage/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ export const useVotes = (network: Network, proposalId: number, t: TFunction) =>
const isOnFirstPage = results.tablePaginationProps.selectedPage === 1
const hasData = !!results.data?.length
const isOnNonexistentPage = !isLoading && !isOnFirstPage && !hasData
const hasNoResultsBecauseOfFilters = !isLoading && !hasData && isOnFirstPage && hasFilters
const hasNoResultsWhatsoever = !isLoading && !allVotes.total_count
const hasNoResultsBecauseOfFilters =
!isLoading && !hasData && isOnFirstPage && hasFilters && !hasNoResultsWhatsoever

return { results, isLoading, isOnNonexistentPage, hasNoResultsBecauseOfFilters }
return { results, isLoading, isOnNonexistentPage, hasNoResultsBecauseOfFilters, hasNoResultsWhatsoever }
}
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"createTooltip": "Voting created on epoch shown.",
"deposit": "Deposit",
"failedToLoadAllVotes": "Failed to load all the votes, number might be incomplete!",
"thereAreNoVotes": "No votes have been registered.",
"handler": "Title",
"id": "ID",
"listTitle": "Network Change Proposals",
Expand Down

0 comments on commit 92fa16d

Please sign in to comment.