diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 3de55e2..8083fe6 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -5536,37 +5536,12 @@ function inferSwissRounds(sides) { }) } -function TeamTotals({ matches, navigate, highlight, onHover }) { - const teams = useMemo(() => { - const map = {} - for (const match of matches) { - const teamA = displayTeamName(match.team_a_name) - const teamB = displayTeamName(match.team_b_name) - const winner = displayTeamName(match.winner_name) - for (const name of [teamA, teamB]) { - if (!name) continue - if (!map[name]) map[name] = { wins: 0, losses: 0 } - if (winner) { - if (winner === name) map[name].wins++ - else map[name].losses++ - } - } - } - return Object.entries(map) - .map(([name, s]) => ({ name, wins: s.wins, losses: s.losses, total: s.wins + s.losses })) - .sort((a, b) => b.wins - a.wins || a.losses - b.losses || a.name.localeCompare(b.name)) - }, [matches]) - - if (!teams.length) return null - +function TeamTotalsRoundTable({ teams, highlight, onHover, navigate }) { const active = Boolean(highlight) - + if (!teams.length) return null return (
-

- TEAM TOTALS -

-
+

Team

W

L

@@ -5577,7 +5552,7 @@ function TeamTotals({ matches, navigate, highlight, onHover }) { const wr = team.total > 0 ? Math.round(team.wins / team.total * 100) : 0 return (
onHover?.({ [team.name.toLowerCase()]: 'win' })} onMouseLeave={() => onHover?.(null)} @@ -5599,6 +5574,68 @@ function TeamTotals({ matches, navigate, highlight, onHover }) { ) } +function TeamTotals({ sides, navigate, highlight, onHover }) { + const roundTotals = useMemo(() => { + return sides.flatMap((side) => { + const running = {} + return side.columns.map((column) => { + for (const match of column.matches) { + const teamA = displayTeamName(match.team_a_name) + const teamB = displayTeamName(match.team_b_name) + const winner = displayTeamName(match.winner_name) + for (const name of [teamA, teamB]) { + if (!name) continue + if (!running[name]) running[name] = { wins: 0, losses: 0 } + if (winner) { + if (winner === name) running[name].wins++ + else running[name].losses++ + } + } + } + const teams = Object.entries(running) + .map(([name, s]) => ({ name, wins: s.wins, losses: s.losses, total: s.wins + s.losses })) + .sort((a, b) => b.wins - a.wins || a.losses - b.losses || a.name.localeCompare(b.name)) + return { label: column.label, teams } + }) + }) + }, [sides]) + + if (!roundTotals.length) return null + + const active = Boolean(highlight) + + return ( +
+

+ TEAM TOTALS +

+ +
+ {roundTotals.map((round, index) => ( +
+ +
+ +
+
+ ))} +
+
+
+ ) +} + function TournamentDetailPage({ tournamentId, navigate }) { const [state, setState] = useState({ status: 'loading', data: null, error: null }) @@ -5627,8 +5664,8 @@ function TournamentDetailPage({ tournamentId, navigate }) { }, [matches]) const bracketSides = sides.filter((side) => side.kind === 'bracket') const listSides = sides.filter((side) => side.kind === 'list') - const swissMatches = useMemo(() => { - return listSides.filter((s) => s.key === 'swiss').flatMap((s) => s.columns.flatMap((c) => c.matches)) + const swissSides = useMemo(() => { + return listSides.filter((s) => s.key === 'swiss') }, [listSides]) const standings = data?.standings || [] const hasStandings = standings.length > 0 @@ -5688,8 +5725,8 @@ function TournamentDetailPage({ tournamentId, navigate }) { {bracketSides.length ?

Group stage

: null} {hasStandings ? : null} {listSides.length ? : null} - {swissMatches.length ? ( - + {swissSides.length ? ( + ) : null}
) : null}