@@ -16,7 +16,7 @@ import { backendAPI, loadGameState } from "@utils";
1616
1717function Leaderboard ( ) {
1818 const dispatch = useContext ( GlobalDispatchContext ) ;
19- const { leaderboard, highscore , isAdmin } = useContext ( GlobalStateContext ) ;
19+ const { leaderboard, highScore , isAdmin } = useContext ( GlobalStateContext ) ;
2020 const [ loading , setLoading ] = useState ( true ) ;
2121 const [ showSettings , setShowSettings ] = useState ( false ) ;
2222 const location = useLocation ( ) ;
@@ -36,23 +36,6 @@ function Leaderboard() {
3636 fetchGameState ( ) ;
3737 } , [ dispatch , backendAPI ] ) ;
3838
39- const sortedLeaderboard = leaderboard
40- ? Object . entries ( leaderboard )
41- . filter ( ( [ , playerData ] ) => playerData && playerData . highscore )
42- . sort ( ( [ , a ] , [ , b ] ) => {
43- const aScore = a . highscore . split ( ":" ) . map ( Number ) ;
44- const bScore = b . highscore . split ( ":" ) . map ( Number ) ;
45-
46- for ( let i = 0 ; i < 3 ; i ++ ) {
47- if ( aScore [ i ] !== bScore [ i ] ) {
48- return aScore [ i ] - bScore [ i ] ;
49- }
50- }
51- return 0 ;
52- } )
53- . slice ( 0 , 20 )
54- : [ ] ;
55-
5639 if ( loading ) return < Loading /> ;
5740
5841 if ( showSettings ) return < AdminView setShowSettings = { setShowSettings } /> ;
@@ -63,10 +46,10 @@ function Leaderboard() {
6346 < >
6447 { isAdmin && < AdminGear setShowSettings = { setShowSettings } /> }
6548 < div className = "px-4 my-6" >
66- < div className = "highscore -container" >
49+ < div className = "highScore -container" >
6750 < div className = "icon" > 🏅</ div >
6851 < h3 > Personal Best</ h3 >
69- < p > { highscore || "No highscore available" } </ p >
52+ < p > { highScore || "No highScore available" } </ p >
7053 </ div >
7154 < div className = "icon pt-4" > 🏆</ div >
7255 < div className = "pb-4" >
@@ -81,18 +64,20 @@ function Leaderboard() {
8164 </ tr >
8265 </ thead >
8366 < tbody >
84- { sortedLeaderboard ?. length === 0 ? (
67+ { leaderboard ?. length === 0 ? (
8568 < tr >
8669 < td colSpan = "3" > There are no race finishes yet.</ td >
8770 </ tr >
8871 ) : (
89- sortedLeaderboard ?. map ( ( [ userId , entry ] , index ) => (
90- < tr key = { userId } >
91- < td > { index + 1 } </ td >
92- < td > { entry . username } </ td >
93- < td > { entry . highscore } </ td >
94- </ tr >
95- ) )
72+ leaderboard ?. map ( ( item , index ) => {
73+ return (
74+ < tr key = { index } >
75+ < td > { index + 1 } </ td >
76+ < td > { item . displayName } </ td >
77+ < td > { item . highScore } </ td >
78+ </ tr >
79+ ) ;
80+ } )
9681 ) }
9782 </ tbody >
9883 </ table >
0 commit comments