@@ -22,6 +22,25 @@ const Leaderboard: React.FC = () => {
2222 id : 'regular' | 'train' | 'turing' | 'hand' | 'brain'
2323 } [ ]
2424 > ( )
25+
26+ const getTimeAgo = ( date : Date ) => {
27+ const now = new Date ( )
28+ const diffInMinutes = Math . floor (
29+ ( now . getTime ( ) - date . getTime ( ) ) / ( 1000 * 60 ) ,
30+ )
31+
32+ if ( diffInMinutes < 1 ) return 'Just now'
33+ if ( diffInMinutes < 60 )
34+ return `${ diffInMinutes } minute${ diffInMinutes > 1 ? 's' : '' } ago`
35+
36+ const diffInHours = Math . floor ( diffInMinutes / 60 )
37+ if ( diffInHours < 24 )
38+ return `${ diffInHours } hour${ diffInHours > 1 ? 's' : '' } ago`
39+
40+ const diffInDays = Math . floor ( diffInHours / 24 )
41+ return `${ diffInDays } day${ diffInDays > 1 ? 's' : '' } ago`
42+ }
43+
2544 const fetchLeaderboard = useCallback ( async ( ) => {
2645 const lb = await getLeaderboard ( )
2746 setLastUpdated ( new Date ( lb . last_updated + 'Z' ) )
@@ -65,31 +84,21 @@ const Leaderboard: React.FC = () => {
6584
6685 return (
6786 < LeaderboardProvider >
68- < div className = "mx-auto flex h-full w-[90%] flex-col items-start justify-center gap-8 py-[2 %]" >
87+ < div className = "mx-auto flex h-full w-[90%] flex-col items-start justify-center gap-4 py-[1 %]" >
6988 < Head >
7089 < title > Leaderboard – Maia Chess</ title >
7190 < meta
7291 name = "description"
7392 content = "Top users across all Maia Chess leaderboards"
7493 />
7594 </ Head >
76- < div className = "flex flex-col" >
77- < h1 className = "text-4xl font-bold" > Rating Leaderboards</ h1 >
78- < p >
79- Last Updated:{ ' ' }
80- { lastUpdated
81- ? lastUpdated . toLocaleString ( undefined , {
82- year : 'numeric' ,
83- month : 'short' ,
84- day : 'numeric' ,
85- hour : '2-digit' ,
86- minute : '2-digit' ,
87- hour12 : true ,
88- } )
89- : '...' }
95+ < div className = "flex w-full flex-row items-end justify-between" >
96+ < h1 className = "text-3xl font-bold" > Rating Leaderboards</ h1 >
97+ < p className = "text-sm text-secondary" >
98+ Last updated: { lastUpdated ? getTimeAgo ( lastUpdated ) : '...' }
9099 </ p >
91100 </ div >
92- < div className = "grid h-full w-full grid-cols-1 justify-start gap-4 md:grid-cols-2 lg:grid-cols-3" >
101+ < div className = "grid h-full w-full grid-cols-1 justify-start gap-3 md:grid-cols-2 lg:grid-cols-3" >
93102 { leaderboard ?. map ( ( column , index ) => (
94103 < LeaderboardColumn key = { index } { ...column } />
95104 ) ) }
0 commit comments