Skip to content

Commit 70628fb

Browse files
committed
feat: add loading and error states to stats component
1 parent f02d718 commit 70628fb

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

web/src/hooks/useCoinPrice.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ export type Prices = {
1313
export const useCoinPrice = (coinIds: string[]) => {
1414
const isEnabled = coinIds !== undefined;
1515

16-
const { data: prices, isError } = useQuery<Prices>({
16+
const {
17+
data: prices,
18+
isError,
19+
isLoading,
20+
error,
21+
} = useQuery<Prices>({
1722
queryKey: [`coinPrice${coinIds}`],
1823
enabled: isEnabled,
1924
queryFn: async () => fetchCoinPrices(coinIds),
2025
});
2126
return {
2227
prices,
2328
isError,
29+
isLoading,
30+
error,
2431
};
25-
};
32+
};

web/src/pages/Courts/CourtDetails/Stats/index.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useCourtDetails } from "queries/useCourtDetails";
1414
import { landscapeStyle } from "styles/landscapeStyle";
1515

1616
import StatsContent from "./StatsContent";
17+
import Spinner from "components/Spinner";
1718

1819
const Container = styled.div`
1920
padding: 0 24px 12px 24px;
@@ -50,13 +51,31 @@ const StyledAccordion = styled(Accordion)`
5051
)}
5152
`;
5253

54+
const ErrorMessage = styled.div`
55+
display: flex;
56+
align-items: center;
57+
justify-content: center;
58+
padding: 24px;
59+
color: ${({ theme }) => theme.error};
60+
font-size: 16px;
61+
font-weight: 500;
62+
`;
63+
5364
const Stats = () => {
5465
const { id } = useParams();
55-
const { data } = useCourtDetails(id);
66+
const { data, isLoading: isLoadingCourt, error: courtError } = useCourtDetails(id);
5667
const coinIds = [CoinIds.PNK, CoinIds.ETH];
57-
const { prices: pricesData } = useCoinPrice(coinIds);
68+
const { prices: pricesData, isLoading: isLoadingPrices, error: pricesError } = useCoinPrice(coinIds);
5869
const isDesktop = useIsDesktop();
5970

71+
if (isLoadingCourt || isLoadingPrices) {
72+
return <Spinner />;
73+
}
74+
75+
if (courtError || pricesError) {
76+
return <ErrorMessage>Failed to load statistics</ErrorMessage>;
77+
}
78+
6079
return isDesktop ? (
6180
<Container>
6281
<Header>Statistics</Header>
@@ -75,4 +94,4 @@ const Stats = () => {
7594
);
7695
};
7796

78-
export default Stats;
97+
export default Stats;

0 commit comments

Comments
 (0)