Skip to content

Commit

Permalink
Add null loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
tumppi committed Dec 17, 2024
1 parent 46ff22e commit a2e39ca
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/shared/components/Tile/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ const StatsBadge = styled.div`
backdrop-filter: blur(13.3871px);
border-radius: 8px;
font-family: 'IBM Plex Sans';
font-style: normal;
font-weight: 500;
font-size: 16px;
line-height: 24px;
Expand All @@ -171,15 +169,23 @@ interface StreamStatsBadgeProps extends Omit<BadgeContainerProps, 'children'> {
}

const StreamStatsBadge = ({ streamIds, ...props }: StreamStatsBadgeProps) => {
const stats = useMultipleStreamStatsQuery(streamIds)
const { data: stats, isLoading, error } = useMultipleStreamStatsQuery(streamIds)

if (error || isLoading) {
return null
}

const messagesPerSecond = stats?.messagesPerSecond
const formattedMsgRate =
typeof messagesPerSecond === 'number' ? messagesPerSecond.toFixed(1) : 'N/A'

return (
<BadgeContainer {...props}>
<StatsBadge>
<span>
{streamIds.length} {streamIds.length === 1 ? 'stream' : 'streams'}
</span>
<span>{stats.data?.messagesPerSecond.toFixed(1) ?? 'N/A'} msg/s</span>
<span>{formattedMsgRate} msg/s</span>
</StatsBadge>
</BadgeContainer>
)
Expand Down

0 comments on commit a2e39ca

Please sign in to comment.