@@ -4,7 +4,7 @@ import 'src/styles/Leaderboard.scss';
4
4
5
5
import { ColDef , IDatasource } from 'ag-grid-community' ;
6
6
import { AgGridReact } from 'ag-grid-react' ;
7
- import React , { useEffect , useMemo , useRef } from 'react' ;
7
+ import React , { useEffect , useMemo , useRef , useState } from 'react' ;
8
8
import { useDispatch } from 'react-redux' ;
9
9
import default_avatar from 'src/assets/default-avatar.jpg' ;
10
10
import { useTypedSelector } from 'src/commons/utils/Hooks' ;
@@ -95,7 +95,7 @@ const OverallLeaderboard: React.FC = () => {
95
95
const paginatedLeaderboard : { rows : LeaderboardRow [ ] ; userCount : number } = useTypedSelector ( store => store . leaderboard . paginatedUserXp ) ;
96
96
const pageSize = 25 ;
97
97
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 [ ] > ( [ ] ) ;
99
99
100
100
useEffect ( ( ) => {
101
101
dispatch ( LeaderboardActions . getPaginatedLeaderboardXp ( 1 , pageSize ) )
@@ -123,6 +123,11 @@ const OverallLeaderboard: React.FC = () => {
123
123
paginatedLeaderboard . rows . length > 0
124
124
) {
125
125
const { successCallback } = latestParamsRef . current ;
126
+
127
+ if ( latestParamsRef . current . startRow === 0 ) {
128
+ setTop3Leaderboard ( paginatedLeaderboard . rows . slice ( 0 , 3 ) ) ;
129
+ }
130
+
126
131
successCallback ( paginatedLeaderboard . rows , Math . min ( paginatedLeaderboard . userCount , visibleEntries ) ) ;
127
132
latestParamsRef . current = null ;
128
133
}
@@ -143,13 +148,6 @@ const OverallLeaderboard: React.FC = () => {
143
148
row . avatar = `/assets/Sample_Profile_${ convertToRandomNumber ( row . username ) } .jpg` ;
144
149
} ) ;
145
150
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
-
153
151
return (
154
152
< div className = "leaderboard-container" >
155
153
{ /* Top 3 Ranking */ }
0 commit comments