Skip to content

Commit

Permalink
Fix process card loading skeletons (#64)
Browse files Browse the repository at this point in the history
* Fix process card loading skeletons

* Implement custom skeletons
  • Loading branch information
selankon authored Jul 19, 2024
1 parent 923153c commit 31ceb0e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/Blocks/BlocksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const PaginatedBlocksList = () => {
const isLoading = isLoadingStats || isLoadingBlocks

if (isLoading) {
return <LoadingCards />
return <LoadingCards noOfLines={2} />
}

if (!blocks || blocks?.length === 0 || isError) {
Expand Down
36 changes: 30 additions & 6 deletions src/components/Layout/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { Card, CardBody, SkeletonText, Spinner, Square, Stack, Text } from '@chakra-ui/react'
import {
Card,
CardBody,
Flex,
SkeletonCircle,
SkeletonText,
SkeletonTextProps,
Spinner,
Square,
Text,
} from '@chakra-ui/react'
import { Trans } from 'react-i18next'

export const Loading = () => (
Expand All @@ -10,14 +20,28 @@ export const Loading = () => (
</Square>
)

export const LoadingCards = ({ length = 4 }: { length?: number }) => (
<Stack>
export const LoadingCards = ({
length = 4,
skeletonCircle,
...rest
}: {
length?: number
skeletonCircle?: boolean
} & SkeletonTextProps) => (
<>
{Array.from({ length }).map((_, i) => (
<Card key={i}>
<Card key={i} direction='row'>
{skeletonCircle && (
<>
<Flex alignItems='center' flexWrap='wrap' pl={4}>
<SkeletonCircle size='12' />
</Flex>
</>
)}
<CardBody>
<SkeletonText noOfLines={3} spacing='3' skeletonHeight='3' />
<SkeletonText noOfLines={3} spacing={3} skeletonHeight={3} py={2} {...rest} />
</CardBody>
</Card>
))}
</Stack>
</>
)
2 changes: 1 addition & 1 deletion src/components/Organizations/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PaginatedOrganizationsList = () => {
const isLoading = isLoadingCount || isLoadingOrgs

if (isLoading || (query && isFetching)) {
return <LoadingCards />
return <LoadingCards skeletonCircle />
}

if (!orgs || orgs?.organizations.length === 0 || isError) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Process/ProcessList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PaginatedProcessList = () => {
const isLoading = isLoadingCount || isLoadingProcesses

if (isLoading || (isFetching && !isEmpty(processFilters))) {
return <LoadingCards />
return <LoadingCards spacing={4} pl={4} skeletonHeight={4} />
}

if (!processes || processes?.elections.length === 0 || isError) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Transactions/TransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const TransactionsList = ({
}) => {
return (
<>
{isLoading && <LoadingCards />}
{isLoading && <LoadingCards spacing={4} />}
{!data || data?.transactions.length === 0 || (isError && <LoadingError error={error} />)}
{data && data.transactions.length > 0 && (
<RoutedPaginationProvider totalPages={totalPages} path={RoutePath.TransactionsList}>
Expand Down

2 comments on commit 31ceb0e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.