1+ import { QueryClientProvider , useQuery } from '@tanstack/react-query' ;
2+ import { API_URL } from '@/lib/constants' ;
3+ import { queryClient } from '@/store' ;
4+
5+ interface Streamer {
6+ id : string ;
7+ name : string ;
8+ isLive : boolean ;
9+ livePlatform : string | null ;
10+ }
11+
12+ interface StreamerData {
13+ streamers : Streamer [ ] ;
14+ }
15+
16+ async function fetchStreamers ( ) : Promise < StreamerData > {
17+ const response = await fetch ( `${ API_URL } /api/streamers` ) ;
18+ if ( ! response . ok ) {
19+ throw new Error ( 'Failed to fetch streamers' ) ;
20+ }
21+ return response . json ( ) ;
22+ }
23+
24+ function StreamerStatsClient ( ) {
25+ const { data, isLoading, error } = useQuery ( {
26+ queryKey : [ 'streamers' ] ,
27+ queryFn : fetchStreamers ,
28+ } ) ;
29+
30+ const totalStreamers = data ?. streamers . length || 0 ;
31+ const liveStreamers = data ?. streamers . filter ( ( s ) => s . isLive ) . length || 0 ;
32+ const supportedPlatforms = 2 ; // Twitch and Kick
33+
34+ if ( error ) {
35+ // Fallback to static numbers if API fails
36+ return (
37+ < div className = "grid grid-cols-1 md:grid-cols-3 gap-8 text-center" >
38+ < div className = "space-y-2" >
39+ < div className = "text-4xl font-bold text-accent" > 50+</ div >
40+ < div className = "text-muted-foreground" > Streamers Supported</ div >
41+ </ div >
42+ < div className = "space-y-2" >
43+ < div className = "text-4xl font-bold text-accent" > 2</ div >
44+ < div className = "text-muted-foreground" > Platforms Supported</ div >
45+ </ div >
46+ < div className = "space-y-2" >
47+ < div className = "text-4xl font-bold text-accent" > ∞</ div >
48+ < div className = "text-muted-foreground" > Potential to Unlock</ div >
49+ </ div >
50+ </ div >
51+ ) ;
52+ }
53+
54+ return (
55+ < div className = "grid grid-cols-1 md:grid-cols-3 gap-8 text-center" >
56+ < div className = "space-y-2" >
57+ < div className = "text-4xl font-bold text-accent" >
58+ { isLoading ? "..." : totalStreamers }
59+ </ div >
60+ < div className = "text-muted-foreground" > Streamers Supported</ div >
61+ </ div >
62+ < div className = "space-y-2" >
63+ < div className = "text-4xl font-bold text-accent" >
64+ { isLoading ? "..." : liveStreamers }
65+ </ div >
66+ < div className = "text-muted-foreground" > Currently Live</ div >
67+ </ div >
68+ < div className = "space-y-2" >
69+ < div className = "text-4xl font-bold text-accent" > { supportedPlatforms } </ div >
70+ < div className = "text-muted-foreground" > Platforms Supported</ div >
71+ </ div >
72+ </ div >
73+ ) ;
74+ }
75+ export function StreamerStats ( ) {
76+ return (
77+ < QueryClientProvider client = { queryClient } >
78+ < StreamerStatsClient />
79+ </ QueryClientProvider >
80+ ) ;
81+ }
0 commit comments