|
1 | 1 | import { useEffect, useState } from "react"; |
2 | 2 |
|
| 3 | +const groupNames: String[] = ["", "Group A", "Group B", "Group C"]; |
| 4 | + |
3 | 5 | export default function List({ data = [] }) { |
4 | 6 | // Mock data for development (with four teams per group) |
5 | 7 | const mockData = [ |
6 | 8 | // Group A teams |
7 | 9 | { |
8 | | - groupRank: 1, |
9 | | - teamName: "Drone Rangers", |
10 | | - honourPoints: 350, |
11 | | - regularPoints: 420, |
12 | | - missionTime: "01:45:22", |
13 | | - group: "Group A", |
14 | | - qualified: true, |
| 10 | + team_name: "Drone Rangers", |
| 11 | + honor_points: 350, |
| 12 | + regular_points: 420, |
| 13 | + total_time_seconds: 154, |
| 14 | + group: 1, |
15 | 15 | }, |
16 | 16 | { |
17 | | - groupRank: 2, |
18 | | - teamName: "RoboPilots", |
19 | | - honourPoints: 290, |
20 | | - regularPoints: 365, |
21 | | - missionTime: "02:05:33", |
22 | | - group: "Group A", |
23 | | - qualified: true, |
| 17 | + team_name: "RoboPilots", |
| 18 | + honor_points: 290, |
| 19 | + regular_points: 365, |
| 20 | + total_time_seconds: 234, |
| 21 | + group: 1, |
24 | 22 | }, |
25 | 23 | { |
26 | | - groupRank: 3, |
27 | | - teamName: "Airborne Coders", |
28 | | - honourPoints: 210, |
29 | | - regularPoints: 280, |
30 | | - missionTime: "02:15:40", |
31 | | - group: "Group A", |
32 | | - qualified: false, |
| 24 | + team_name: "Airborne Coders", |
| 25 | + honor_points: 210, |
| 26 | + regular_points: 280, |
| 27 | + total_time_seconds: 163, |
| 28 | + group: 1, |
33 | 29 | }, |
34 | 30 | { |
35 | | - groupRank: 4, |
36 | | - teamName: "Flying Algorithms", |
37 | | - honourPoints: 180, |
38 | | - regularPoints: 240, |
39 | | - missionTime: "02:30:15", |
40 | | - group: "Group A", |
41 | | - qualified: false, |
| 31 | + team_name: "Flying Algorithms", |
| 32 | + honor_points: 180, |
| 33 | + regular_points: 240, |
| 34 | + total_time_seconds: 274, |
| 35 | + group: 1, |
42 | 36 | }, |
43 | 37 |
|
44 | 38 | // Group B teams |
45 | 39 | { |
46 | | - groupRank: 1, |
47 | | - teamName: "Sky Navigators", |
48 | | - honourPoints: 320, |
49 | | - regularPoints: 380, |
50 | | - missionTime: "01:52:10", |
51 | | - group: "Group B", |
52 | | - qualified: true, |
| 40 | + team_name: "Sky Navigators", |
| 41 | + honor_points: 320, |
| 42 | + regular_points: 380, |
| 43 | + total_time_seconds: 198, |
| 44 | + group: 2, |
53 | 45 | }, |
54 | 46 | { |
55 | | - groupRank: 2, |
56 | | - teamName: "Circuit Flyers", |
57 | | - honourPoints: 250, |
58 | | - regularPoints: 310, |
59 | | - missionTime: "02:18:20", |
60 | | - group: "Group B", |
61 | | - qualified: true, |
| 47 | + team_name: "Circuit Flyers", |
| 48 | + honor_points: 250, |
| 49 | + regular_points: 310, |
| 50 | + total_time_seconds: 193, |
| 51 | + group: 2, |
62 | 52 | }, |
63 | 53 | { |
64 | | - groupRank: 3, |
65 | | - teamName: "Byte Squadron", |
66 | | - honourPoints: 220, |
67 | | - regularPoints: 290, |
68 | | - missionTime: "02:25:17", |
69 | | - group: "Group B", |
70 | | - qualified: false, |
| 54 | + team_name: "Byte Squadron", |
| 55 | + honor_points: 220, |
| 56 | + regular_points: 290, |
| 57 | + total_time_seconds: 198, |
| 58 | + group: 2, |
71 | 59 | }, |
72 | 60 | { |
73 | | - groupRank: 4, |
74 | | - teamName: "Quantum Wings", |
75 | | - honourPoints: 190, |
76 | | - regularPoints: 250, |
77 | | - missionTime: "02:35:45", |
78 | | - group: "Group B", |
79 | | - qualified: false, |
| 61 | + team_name: "Quantum Wings", |
| 62 | + honor_points: 190, |
| 63 | + regular_points: 250, |
| 64 | + total_time_seconds: 183, |
| 65 | + group: 2, |
80 | 66 | }, |
81 | 67 |
|
82 | 68 | // Group C teams |
83 | 69 | { |
84 | | - groupRank: 1, |
85 | | - teamName: "Aerial Mechanics", |
86 | | - honourPoints: 270, |
87 | | - regularPoints: 340, |
88 | | - missionTime: "02:11:45", |
89 | | - group: "Group C", |
90 | | - qualified: true, |
| 70 | + team_name: "Aerial Mechanics", |
| 71 | + honor_points: 270, |
| 72 | + regular_points: 340, |
| 73 | + total_time_seconds: 348, |
| 74 | + group: 3, |
91 | 75 | }, |
92 | 76 | { |
93 | | - groupRank: 2, |
94 | | - teamName: "PropCoders", |
95 | | - honourPoints: 240, |
96 | | - regularPoints: 300, |
97 | | - missionTime: "02:20:30", |
98 | | - group: "Group C", |
99 | | - qualified: true, |
| 77 | + team_name: "PropCoders", |
| 78 | + honor_points: 240, |
| 79 | + regular_points: 300, |
| 80 | + total_time_seconds: 314, |
| 81 | + group: 3, |
100 | 82 | }, |
101 | 83 | { |
102 | | - groupRank: 3, |
103 | | - teamName: "Binary Flyers", |
104 | | - honourPoints: 200, |
105 | | - regularPoints: 270, |
106 | | - missionTime: "02:28:55", |
107 | | - group: "Group C", |
108 | | - qualified: false, |
| 84 | + team_name: "Binary Flyers", |
| 85 | + honor_points: 200, |
| 86 | + regular_points: 270, |
| 87 | + total_time_seconds: 109, |
| 88 | + group: 3, |
109 | 89 | }, |
110 | 90 | { |
111 | | - groupRank: 4, |
112 | | - teamName: "Aerodynamic Devs", |
113 | | - honourPoints: 170, |
114 | | - regularPoints: 230, |
115 | | - missionTime: "02:38:20", |
116 | | - group: "Group C", |
117 | | - qualified: false, |
| 91 | + team_name: "Aerodynamic Devs", |
| 92 | + honor_points: 170, |
| 93 | + regular_points: 230, |
| 94 | + total_time_seconds: 54, |
| 95 | + group: 3, |
118 | 96 | }, |
119 | 97 | ]; |
120 | 98 |
|
| 99 | + // TODO: Fetch real data from api/match/group |
| 100 | + |
121 | 101 | // Use provided data or fallback to mock data |
122 | | - const teamsData = data.length > 0 ? data : mockData; |
| 102 | + const rawData = data.length > 0 ? data : mockData; |
| 103 | + |
| 104 | + // Get unique groups |
| 105 | + const groupIds = [...new Set(rawData.map((item) => item.group))]; |
| 106 | + |
| 107 | + function processData(rawData: Array<any>) { |
| 108 | + let teamsData: Array<any> = []; |
| 109 | + |
| 110 | + // For each group |
| 111 | + for (let i = 0; i < groupIds.length; i++) { |
| 112 | + // Get all the teams in that group |
| 113 | + let groupData = rawData.filter((team) => { |
| 114 | + return team.group === groupIds[i]; |
| 115 | + }); |
| 116 | + |
| 117 | + // Sort them descending by points |
| 118 | + groupData.sort((teamA, teamB) => { |
| 119 | + return teamB.regular_points - teamA.regular_points; |
| 120 | + // TODO: Implement sorting by honor points in case of draw, then by time to finish |
| 121 | + }); |
| 122 | + |
| 123 | + // Add each of those teams into the teamData with calculated fields |
| 124 | + for (let j = 0; j < groupData.length; j++) { |
| 125 | + let team = groupData[j]; |
| 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 |
| 129 | + team.mission_time = |
| 130 | + "" + |
| 131 | + Math.floor(team.total_time_seconds / 60) + |
| 132 | + ":" + |
| 133 | + (team.total_time_seconds % 60); |
| 134 | + teamsData.push(team); |
| 135 | + } |
| 136 | + } |
| 137 | + return teamsData; |
| 138 | + } |
| 139 | + |
| 140 | + // Add calculated fields group_rank and qualified to the data |
| 141 | + const teamsData = processData(rawData); |
123 | 142 |
|
124 | 143 | // Get unique groups for dropdown |
125 | 144 | const groups = [...new Set(teamsData.map((item) => item.group))]; |
126 | 145 |
|
127 | 146 | // Initialize selectedGroup with the first group instead of "All Groups" |
128 | | - const [selectedGroup, setSelectedGroup] = useState(groups[0] || "Group A"); |
| 147 | + const [selectedGroup, setSelectedGroup] = useState(groups[0] || 1); |
129 | 148 |
|
130 | 149 | // Filter data for the selected group only |
131 | 150 | const displayData = teamsData.filter((item) => item.group === selectedGroup); |
@@ -181,12 +200,12 @@ export default function List({ data = [] }) { |
181 | 200 | }`} |
182 | 201 | > |
183 | 202 | <td className="body-lg px-6 py-4 font-bold italic"> |
184 | | - {row.groupRank} |
| 203 | + {row.group_rank} |
185 | 204 | </td> |
186 | | - <td className="px-6 py-4">{row.teamName}</td> |
187 | | - <td className="px-6 py-4">{row.honourPoints}</td> |
188 | | - <td className="px-6 py-4">{row.regularPoints}</td> |
189 | | - <td className="px-6 py-4">{row.missionTime}</td> |
| 205 | + <td className="px-6 py-4">{row.team_name}</td> |
| 206 | + <td className="px-6 py-4">{row.honor_points}</td> |
| 207 | + <td className="px-6 py-4">{row.regular_points}</td> |
| 208 | + <td className="px-6 py-4">{row.mission_time}</td> |
190 | 209 | <td className="px-6 py-4"> |
191 | 210 | {row.qualified ? ( |
192 | 211 | <span className="font-medium text-green-600"> |
|
0 commit comments