11import Link from 'next/link'
2- import { useCallback , useContext } from 'react'
32import { motion } from 'framer-motion'
3+ import { useCallback , useContext , useEffect , useState } from 'react'
44
55import {
66 SunIcon ,
@@ -13,7 +13,9 @@ import {
1313 StarIcon ,
1414} from 'src/components/Icons/icons'
1515import { PlayType } from 'src/types'
16+ import { getGlobalStats } from 'src/api'
1617import { AuthContext , ModalContext } from 'src/contexts'
18+ import { AnimatedNumber } from 'src/components/Misc/AnimatedNumber'
1719
1820interface Props {
1921 scrollHandler : ( ) => void
@@ -117,6 +119,11 @@ const FeatureCard: React.FC<FeatureCardProps> = ({
117119}
118120
119121export const HomeHero : React . FC < Props > = ( { scrollHandler } : Props ) => {
122+ const [ globalStats , setGlobalStats ] = useState < {
123+ play_moves_total : number
124+ puzzle_games_total : number
125+ turing_games_total : number
126+ } > ( )
120127 const { setPlaySetupModalProps } = useContext ( ModalContext )
121128 const { user, connectLichess } = useContext ( AuthContext )
122129
@@ -127,8 +134,15 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
127134 [ setPlaySetupModalProps ] ,
128135 )
129136
137+ useEffect ( ( ) => {
138+ ; ( async ( ) => {
139+ const data = await getGlobalStats ( )
140+ setGlobalStats ( data )
141+ } ) ( )
142+ } , [ ] )
143+
130144 return (
131- < div className = "relative flex flex-col items-center justify-center overflow-hidden pb-12 pt-16 md:pb-28 md:pt-36" >
145+ < div className = "relative flex flex-col items-center justify-center gap-14 overflow-hidden pb-12 pt-16 md:pb-16 md:pt-36" >
132146 < div className = "z-10 flex w-full max-w-[1200px] flex-col items-center justify-center gap-10 p-4 text-left md:flex-row md:gap-20" >
133147 < div className = "flex w-full flex-col items-start justify-center gap-6 md:w-[40%] md:gap-8" >
134148 < div className = "flex flex-col gap-3 md:gap-4" >
@@ -189,7 +203,6 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
189203 ) }
190204 </ motion . div >
191205 </ div >
192-
193206 < div className = "grid w-full flex-1 grid-cols-1 gap-4 md:grid-cols-3" >
194207 < FeatureCard
195208 icon = { < RegularPlayIcon /> }
@@ -237,6 +250,34 @@ export const HomeHero: React.FC<Props> = ({ scrollHandler }: Props) => {
237250 />
238251 </ div >
239252 </ div >
253+ < motion . div
254+ className = "flex gap-6"
255+ initial = { { opacity : 0 , y : 10 } }
256+ animate = { { opacity : 1 , y : 0 } }
257+ transition = { { duration : 0.4 , delay : 0.3 } }
258+ >
259+ < p className = "text-base text-primary/80" >
260+ < AnimatedNumber
261+ value = { globalStats ?. play_moves_total || 0 }
262+ className = "font-bold"
263+ /> { ' ' }
264+ moves played
265+ </ p >
266+ < p className = "text-base text-primary/80" >
267+ < AnimatedNumber
268+ value = { globalStats ?. puzzle_games_total || 0 }
269+ className = "font-bold"
270+ /> { ' ' }
271+ puzzle games solved
272+ </ p >
273+ < p className = "text-base text-primary/80" >
274+ < AnimatedNumber
275+ value = { globalStats ?. turing_games_total || 0 }
276+ className = "font-bold"
277+ /> { ' ' }
278+ turing games played
279+ </ p >
280+ </ motion . div >
240281 </ div >
241282 )
242283}
0 commit comments