From a3e1e82475bc83df26f8a94f91cd8018e2aea2c5 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 20 Jul 2025 15:35:11 +0300 Subject: [PATCH] Fix incorrect placement for in-progress SE/DE bracket --- app/features/tournament/core/Standings.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/features/tournament/core/Standings.ts b/app/features/tournament/core/Standings.ts index a255af285..c95e14501 100644 --- a/app/features/tournament/core/Standings.ts +++ b/app/features/tournament/core/Standings.ts @@ -114,7 +114,7 @@ export function tournamentStandings(tournament: Tournament): Standing[] { const standings = standingsToMergeable({ alreadyIncludedTeamIds, standings: bracket.standings, - teamsAboveCount: alreadyIncludedTeamIds.size, + teamsAboveFromAnotherBracketsCount: alreadyIncludedTeamIds.size, }); result.push(...standings); @@ -134,11 +134,11 @@ function standingsToMergeable< >({ alreadyIncludedTeamIds, standings, - teamsAboveCount, + teamsAboveFromAnotherBracketsCount, }: { alreadyIncludedTeamIds: Set; standings: T[]; - teamsAboveCount: number; + teamsAboveFromAnotherBracketsCount: number; }) { const result: T[] = []; @@ -146,17 +146,24 @@ function standingsToMergeable< (standing) => !alreadyIncludedTeamIds.has(standing.team.id), ); - let placement = teamsAboveCount + 1; + // e.g. if standings start at 3rd place, this must mean there is 2 teams left to finish _this_ bracket + const unfinishedTeamsCount = (standings.at(0)?.placement ?? 1) - 1; + + let placement = 1; for (const [i, standing] of filtered.entries()) { const placementChanged = i !== 0 && standing.placement !== filtered[i - 1].placement; if (placementChanged) { - placement = teamsAboveCount + i + 1; + placement = i + 1; } - result.push({ ...standing, placement }); + result.push({ + ...standing, + placement: + placement + teamsAboveFromAnotherBracketsCount + unfinishedTeamsCount, + }); } return result;