Skip to content

Commit a2e39ca

Browse files
committed
Add null loading state
1 parent 46ff22e commit a2e39ca

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/shared/components/Tile/Badge.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ const StatsBadge = styled.div`
145145
backdrop-filter: blur(13.3871px);
146146
border-radius: 8px;
147147
148-
font-family: 'IBM Plex Sans';
149-
font-style: normal;
150148
font-weight: 500;
151149
font-size: 16px;
152150
line-height: 24px;
@@ -171,15 +169,23 @@ interface StreamStatsBadgeProps extends Omit<BadgeContainerProps, 'children'> {
171169
}
172170

173171
const StreamStatsBadge = ({ streamIds, ...props }: StreamStatsBadgeProps) => {
174-
const stats = useMultipleStreamStatsQuery(streamIds)
172+
const { data: stats, isLoading, error } = useMultipleStreamStatsQuery(streamIds)
173+
174+
if (error || isLoading) {
175+
return null
176+
}
177+
178+
const messagesPerSecond = stats?.messagesPerSecond
179+
const formattedMsgRate =
180+
typeof messagesPerSecond === 'number' ? messagesPerSecond.toFixed(1) : 'N/A'
175181

176182
return (
177183
<BadgeContainer {...props}>
178184
<StatsBadge>
179185
<span>
180186
{streamIds.length} {streamIds.length === 1 ? 'stream' : 'streams'}
181187
</span>
182-
<span>{stats.data?.messagesPerSecond.toFixed(1) ?? 'N/A'} msg/s</span>
188+
<span>{formattedMsgRate} msg/s</span>
183189
</StatsBadge>
184190
</BadgeContainer>
185191
)

0 commit comments

Comments
 (0)