@@ -4,7 +4,7 @@ import 'src/styles/Leaderboard.scss';
44
55import { ColDef , IDatasource } from 'ag-grid-community' ;
66import { AgGridReact } from 'ag-grid-react' ;
7- import React , { useEffect , useMemo , useRef } from 'react' ;
7+ import React , { useEffect , useMemo , useRef , useState } from 'react' ;
88import { useDispatch } from 'react-redux' ;
99import default_avatar from 'src/assets/default-avatar.jpg' ;
1010import { useTypedSelector } from 'src/commons/utils/Hooks' ;
@@ -95,7 +95,7 @@ const OverallLeaderboard: React.FC = () => {
9595 const paginatedLeaderboard : { rows : LeaderboardRow [ ] ; userCount : number } = useTypedSelector ( store => store . leaderboard . paginatedUserXp ) ;
9696 const pageSize = 25 ;
9797 const visibleEntries = useTypedSelector ( store => store . session . topLeaderboardDisplay ) ?? Number . MAX_SAFE_INTEGER ;
98- // const topX = rankedLeaderboard.slice(0, Number(visibleEntries) );
98+ const [ top3Leaderboard , setTop3Leaderboard ] = useState < LeaderboardRow [ ] > ( [ ] ) ;
9999
100100 useEffect ( ( ) => {
101101 dispatch ( LeaderboardActions . getPaginatedLeaderboardXp ( 1 , pageSize ) )
@@ -123,6 +123,11 @@ const OverallLeaderboard: React.FC = () => {
123123 paginatedLeaderboard . rows . length > 0
124124 ) {
125125 const { successCallback } = latestParamsRef . current ;
126+
127+ if ( latestParamsRef . current . startRow === 0 ) {
128+ setTop3Leaderboard ( paginatedLeaderboard . rows . slice ( 0 , 3 ) ) ;
129+ }
130+
126131 successCallback ( paginatedLeaderboard . rows , Math . min ( paginatedLeaderboard . userCount , visibleEntries ) ) ;
127132 latestParamsRef . current = null ;
128133 }
@@ -143,13 +148,6 @@ const OverallLeaderboard: React.FC = () => {
143148 row . avatar = `/assets/Sample_Profile_${ convertToRandomNumber ( row . username ) } .jpg` ;
144149 } ) ;
145150
146- const top3Leaderboard = useMemo ( ( ) => {
147- if ( paginatedLeaderboard . rows . length > 0 ) {
148- return paginatedLeaderboard . rows . slice ( 0 , 3 ) ; // Get the top 3 users
149- }
150- return [ ] ; // Fallback if no data
151- } , [ paginatedLeaderboard . rows ] ) ;
152-
153151 return (
154152 < div className = "leaderboard-container" >
155153 { /* Top 3 Ranking */ }
0 commit comments