Skip to content

Commit 75ec8a1

Browse files
committed
Refactor LeaderboardExportButton to accept dynamic type and update filename logic
1 parent 4aed281 commit 75ec8a1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/pages/leaderboard/subcomponents/ContestLeaderboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const ContestLeaderboard: React.FC<Props> = ({ type, contestID }) => {
153153
<LeaderboardDropdown contests={contestDetails} />
154154

155155
{/* Export Button */}
156-
<LeaderboardExportButton type="contest" contest={contestName} data={rankedLeaderboard}/>
156+
<LeaderboardExportButton type={type} contest={contestName} data={rankedLeaderboard}/>
157157
</div>
158158

159159
{/* Leaderboard Table (Top 3) */}

src/pages/leaderboard/subcomponents/LeaderboardExportButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { ContestLeaderboardRow, LeaderboardRow } from 'src/features/leaderboard/
77
import { Role } from '../../../commons/application/ApplicationTypes';
88

99
type Props =
10-
| { type: "contest"; contest: string | undefined; data: ContestLeaderboardRow[] }
11-
| { type: "overall"; contest: string | undefined; data: LeaderboardRow[] };
10+
| { type: string; contest: string | undefined; data: ContestLeaderboardRow[] }
11+
| { type: string; contest: string | undefined; data: LeaderboardRow[] };
1212

1313
const LeaderboardExportButton: React.FC<Props> = ({ type, contest, data }) => {
1414
const role = useTypedSelector(store => store.session.role);
@@ -28,7 +28,7 @@ const LeaderboardExportButton: React.FC<Props> = ({ type, contest, data }) => {
2828
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
2929
const link = document.createElement('a');
3030
link.href = URL.createObjectURL(blob);
31-
link.download = type === "overall" ? 'Overall Leaderboard.csv' : `${contest} Leaderboard.csv`; // Filename for download
31+
link.download = type === "overall" ? 'Overall Leaderboard.csv' : type === "popularvote" ? `${contest} Popular Vote Leaderboard.csv` : `${contest} Score Leaderboard.csv`; // Filename for download
3232
link.click();
3333
};
3434

0 commit comments

Comments
 (0)