1- import { FC } from 'react' ;
1+ import { FC , useMemo } from 'react' ;
22
33import { usePartyProgress } from '@/api/progress' ;
44
55export const PartyStats : FC < { party_id : string } > = ( { party_id } ) => {
6- const { percentages, triedCodes } = usePartyProgress ( party_id ) ;
6+ const { percentages, triedCodes, triedCodesByUserId } = usePartyProgress ( party_id ) ;
7+
8+ const userTopCodes = useMemo ( ( ) => {
9+ const userTopCodes : [ string , number ] [ ] = [ ] ;
10+
11+ for ( const [ userId , codes ] of triedCodesByUserId . entries ( ) ) {
12+ userTopCodes . push ( [ userId , codes . length ] ) ;
13+ }
14+
15+ userTopCodes . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ;
16+
17+ return userTopCodes ;
18+ } , [ triedCodesByUserId ] ) ;
719
820 return (
921 < div className = "card w-full flex flex-col gap-2 !pb-2" style = { { gridColumnEnd : '-2' } } >
@@ -23,6 +35,19 @@ export const PartyStats: FC<{ party_id: string }> = ({ party_id }) => {
2335 </ span >
2436 < span > { triedCodes . size } </ span >
2537 </ div >
38+ < div >
39+ < span >
40+ Leaderboard
41+ </ span >
42+ < ul className = "border" >
43+ { userTopCodes . map ( ( [ userId , codes ] ) => (
44+ < li key = { userId } className = "flex items-center justify-between" >
45+ < span > { userId } </ span >
46+ < span > { codes } </ span >
47+ </ li >
48+ ) ) }
49+ </ ul >
50+ </ div >
2651 </ div >
2752 < div className = "w-full h-4 bg-primary rounded-md border border-secondary overflow-hidden mb-2" >
2853 < div className = "h-full bg-accent" style = { { width : `${ percentages } %` } } >
0 commit comments