Skip to content

Commit 6e13c85

Browse files
committed
fix(leaderboard): Added Todos
1 parent 8a75ae3 commit 6e13c85

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

  • client/src/components/ui/Leaderboard

client/src/components/ui/Leaderboard/List.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
22

3-
const groupNames: String[] = ["Group A", "Group B", "Group C"];
3+
const groupNames: String[] = ["", "Group A", "Group B", "Group C"];
44

55
export default function List({ data = [] }) {
66
// Mock data for development (with four teams per group)
@@ -96,33 +96,36 @@ export default function List({ data = [] }) {
9696
},
9797
];
9898

99+
// TODO: Fetch real data from api/match/group
100+
99101
// Use provided data or fallback to mock data
100102
const rawData = data.length > 0 ? data : mockData;
101103

102-
// Get unique groups for dropdown
103-
const groups = [...new Set(rawData.map((item) => item.group))];
104+
// Get unique groups
105+
const groupIds = [...new Set(rawData.map((item) => item.group))];
104106

105-
function addCalculatedFields(rawData: any) {
107+
function processData(rawData: Array<any>) {
106108
let teamsData: Array<any> = [];
107109

108-
for (let i = 0; i < groups.length; i++) {
109-
// For each group
110+
// For each group
111+
for (let i = 0; i < groupIds.length; i++) {
110112
// Get all the teams in that group
111113
let groupData = rawData.filter((team) => {
112-
return team.group === i;
114+
return team.group === groupIds[i];
113115
});
114116

115117
// Sort them descending by points
116118
groupData.sort((teamA, teamB) => {
117-
console.log(teamA.regular_points, teamB.regular_points);
118119
return teamB.regular_points - teamA.regular_points;
120+
// TODO: Implement sorting by honor points in case of draw, then by time to finish
119121
});
120122

121123
// Add each of those teams into the teamData with calculated fields
122124
for (let j = 0; j < groupData.length; j++) {
123125
let team = groupData[j];
124-
team.group_rank = j + 1;
125-
team.qualified = team.group_rank <= 2;
126+
team.group = groupNames[team.group];
127+
team.group_rank = j + 1; // TODO: Make resistant to ties
128+
team.qualified = team.group_rank <= 2; // TODO: Make resistant to ties
126129
team.mission_time =
127130
"" +
128131
Math.floor(team.total_time_seconds / 60) +
@@ -135,7 +138,10 @@ export default function List({ data = [] }) {
135138
}
136139

137140
// Add calculated fields group_rank and qualified to the data
138-
const teamsData = addCalculatedFields(rawData);
141+
const teamsData = processData(rawData);
142+
143+
// Get unique groups for dropdown
144+
const groups = [...new Set(teamsData.map((item) => item.group))];
139145

140146
// Initialize selectedGroup with the first group instead of "All Groups"
141147
const [selectedGroup, setSelectedGroup] = useState(groups[0] || 1);

0 commit comments

Comments
 (0)