@@ -7,19 +7,19 @@ import { ContestLeaderboardRow, LeaderboardRow } from 'src/features/leaderboard/
7
7
import { Role } from '../../../commons/application/ApplicationTypes' ;
8
8
9
9
type Props =
10
- | { type : "contest" ; data : ContestLeaderboardRow [ ] }
11
- | { type : "overall" ; data : LeaderboardRow [ ] } ;
10
+ | { type : "contest" ; contest : string | undefined ; data : ContestLeaderboardRow [ ] }
11
+ | { type : "overall" ; contest : string | undefined ; data : LeaderboardRow [ ] } ;
12
12
13
- const LeaderboardExportButton : React . FC < Props > = ( { type, data } ) => {
13
+ const LeaderboardExportButton : React . FC < Props > = ( { type, contest , data } ) => {
14
14
const role = useTypedSelector ( store => store . session . role ) ;
15
15
const exportCSV = ( ) => {
16
- const headers = [ 'Rank' , 'Name' , 'Username' , ( type == "overall" ? 'XP' : 'Score' ) , ( type == "overall" ? 'Achievements' : 'Submission Id' ) ] ;
16
+ const headers = [ 'Rank' , 'Name' , 'Username' , ( type === "overall" ? 'XP' : 'Score' ) , ( type = == "overall" ? 'Achievements' : 'Submission Id' ) ] ;
17
17
const rows = data ?. map ( player => [
18
18
player . rank ,
19
19
player . name ,
20
20
player . username ,
21
- type == "overall" ? ( player as LeaderboardRow ) . xp : ( player as ContestLeaderboardRow ) . score ,
22
- type == "overall" ? ( player as LeaderboardRow ) . achievements : ( player as ContestLeaderboardRow ) . submissionId
21
+ type === "overall" ? ( player as LeaderboardRow ) . xp : ( player as ContestLeaderboardRow ) . score ,
22
+ type === "overall" ? ( player as LeaderboardRow ) . achievements : ( player as ContestLeaderboardRow ) . submissionId
23
23
] ) ;
24
24
25
25
// Combine headers and rows
@@ -28,7 +28,7 @@ const LeaderboardExportButton: React.FC<Props> = ({ type, data }) => {
28
28
const blob = new Blob ( [ csvContent ] , { type : 'text/csv;charset=utf-8;' } ) ;
29
29
const link = document . createElement ( 'a' ) ;
30
30
link . href = URL . createObjectURL ( blob ) ;
31
- link . download = 'leaderboard .csv'; // Filename for download
31
+ link . download = type === "overall" ? 'Overall Leaderboard .csv' : ` ${ contest } Leaderboard.csv` ; // Filename for download
32
32
link . click ( ) ;
33
33
} ;
34
34
0 commit comments