@@ -15,7 +15,7 @@ import {
1515 BotOrNotIcon ,
1616} from 'src/components/Common/Icons'
1717import { PlayType } from 'src/types'
18- import { getGlobalStats } from 'src/api'
18+ import { getGlobalStats , getActiveUserCount } from 'src/api'
1919import { AuthContext , ModalContext } from 'src/contexts'
2020import { AnimatedNumber } from 'src/components/Common/AnimatedNumber'
2121
@@ -120,6 +120,7 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
120120 puzzle_games_total : number
121121 turing_games_total : number
122122 } > ( )
123+ const [ activeUsers , setActiveUsers ] = useState < number > ( 0 )
123124 const { setPlaySetupModalProps } = useContext ( ModalContext )
124125 const { user, connectLichess } = useContext ( AuthContext )
125126
@@ -130,11 +131,36 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
130131 [ setPlaySetupModalProps ] ,
131132 )
132133
134+ // Fetch global stats and set up periodic updates
133135 useEffect ( ( ) => {
134- ; ( async ( ) => {
136+ const fetchGlobalStats = async ( ) => {
135137 const data = await getGlobalStats ( )
136138 setGlobalStats ( data )
137- } ) ( )
139+ }
140+
141+ // Fetch immediately
142+ fetchGlobalStats ( )
143+
144+ // Update every 20 seconds
145+ const interval = setInterval ( fetchGlobalStats , 20000 )
146+
147+ return ( ) => clearInterval ( interval )
148+ } , [ ] )
149+
150+ // Fetch active users count and set up periodic updates
151+ useEffect ( ( ) => {
152+ const fetchActiveUsers = async ( ) => {
153+ const count = await getActiveUserCount ( )
154+ setActiveUsers ( count )
155+ }
156+
157+ // Fetch immediately
158+ fetchActiveUsers ( )
159+
160+ // Update every 20 seconds
161+ const interval = setInterval ( fetchActiveUsers , 20000 )
162+
163+ return ( ) => clearInterval ( interval )
138164 } , [ ] )
139165
140166 return (
@@ -227,28 +253,43 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
227253 />
228254 </ div >
229255 </ div >
230- < motion . div className = "grid grid-cols-3 gap-6 px-2 md:flex" >
256+ < motion . div className = "grid grid-cols-2 gap-6 px-2 md:flex md:gap-6" >
257+ { activeUsers > 0 ? (
258+ < p className = "text-center text-base text-primary/80" >
259+ < AnimatedNumber
260+ value = { activeUsers }
261+ className = "font-bold text-human-2"
262+ /> { ' ' }
263+ users online
264+ </ p >
265+ ) : (
266+ < > </ >
267+ ) }
231268 < p className = "text-center text-base text-primary/80" >
232269 < AnimatedNumber
233270 value = { globalStats ?. play_moves_total || 0 }
234- className = "font-bold"
271+ className = "font-bold text-human-2 "
235272 /> { ' ' }
236273 moves played
237274 </ p >
238275 < p className = "text-center text-base text-primary/80" >
239276 < AnimatedNumber
240277 value = { globalStats ?. puzzle_games_total || 0 }
241- className = "font-bold"
278+ className = "font-bold text-human-2 "
242279 /> { ' ' }
243280 puzzle games solved
244281 </ p >
245- < p className = "text-center text-base text-primary/80" >
246- < AnimatedNumber
247- value = { globalStats ?. turing_games_total || 0 }
248- className = "font-bold"
249- /> { ' ' }
250- turing games played
251- </ p >
282+ { activeUsers <= 0 ? (
283+ < p className = "text-center text-base text-primary/80" >
284+ < AnimatedNumber
285+ value = { globalStats ?. turing_games_total || 0 }
286+ className = "font-bold"
287+ /> { ' ' }
288+ turing games played
289+ </ p >
290+ ) : (
291+ < > </ >
292+ ) }
252293 </ motion . div >
253294 </ div >
254295 </ Fragment >
0 commit comments