Skip to content

Commit

Permalink
consolidate showdata refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliiiu committed Jan 14, 2025
1 parent 9514f5e commit 6f7383d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/components/client/StatsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,31 @@ type Stat = {
icon?: (props: IconProps) => JSX.Element
}

const ShowData = ({
value,
prefix,
isFetched,
}: {
interface NumericDisplayProps {
value: number | undefined
prefix?: string
isFetched?: boolean
}) => {
isFailedToFetchData?: boolean
}

const NumericDisplay = ({
value,
prefix,
isFetched,
isFailedToFetchData,
}: NumericDisplayProps) => {
if (isFailedToFetchData) {
return '-'
}

if (value === undefined && !isFetched) {
return (
<Spinner variant="primary" role="status" size="sm">
<span>Loading...</span>
</Spinner>
)
}

return value ? (prefix || '') + Humanize.formatNumber(value) : '-'
}

Expand Down Expand Up @@ -170,15 +179,12 @@ const StatsPage = () => {
fontSize={{ base: 'sm', md: 'md' }}
fontWeight="semibold"
>
{isFailedToFetchData ? (
'-'
) : (
<ShowData
value={item.value || 0}
prefix={valuePrefix}
isFetched={isFetched}
/>
)}
<NumericDisplay
value={item.value || 0}
prefix={valuePrefix}
isFetched={isFetched}
isFailedToFetchData={isFailedToFetchData}
/>
</Text>
</Flex>
)
Expand Down

0 comments on commit 6f7383d

Please sign in to comment.