From 0380612093d7cd4a4ebeab0062b2c83a0b3f93a5 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 1 Sep 2026 17:11:02 +0300 Subject: [PATCH] Fix team list page showing wrong seed --- .../tournament/loaders/to.$id.teams.server.ts | 46 +++++++++++-- .../tournament/routes/to.$id.teams.tsx | 64 ++++--------------- changelog/2026-09-01-teams-tab-seed-order.md | 5 ++ 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 changelog/2026-09-01-teams-tab-seed-order.md diff --git a/app/features/tournament/loaders/to.$id.teams.server.ts b/app/features/tournament/loaders/to.$id.teams.server.ts index d9a2acc0e..271da1d06 100644 --- a/app/features/tournament/loaders/to.$id.teams.server.ts +++ b/app/features/tournament/loaders/to.$id.teams.server.ts @@ -1,4 +1,5 @@ import type { LoaderFunctionArgs } from "react-router"; +import type { Tournament } from "~/features/tournament-bracket/core/Tournament"; import { tournamentFromParams, tournamentTeamsFullInSeedOrder, @@ -6,6 +7,7 @@ import { import type { SerializeFrom } from "~/utils/remix"; import { paginate } from "~/utils/remix.server"; import { tournamentTeamsSearchParams } from "../tournament-search-params"; +import { getBracketProgressionLabel } from "../tournament-utils"; export type TournamentTeamsLoaderData = SerializeFrom; @@ -19,6 +21,7 @@ export const loader = async ({ request, params, url }: LoaderFunctionArgs) => { const { page } = tournamentTeamsSearchParams.parse(request); const teams = await tournamentTeamsFullInSeedOrder({ tournament, user }); + const seedInfoByTeamId = teamSeedInfo(tournament); const { currentPage, pagesCount } = paginate({ url, @@ -28,11 +31,46 @@ export const loader = async ({ request, params, url }: LoaderFunctionArgs) => { }); return { - teams: teams.slice( - (currentPage - 1) * TEAMS_PAGE_SIZE, - currentPage * TEAMS_PAGE_SIZE, - ), + teams: teams + .slice((currentPage - 1) * TEAMS_PAGE_SIZE, currentPage * TEAMS_PAGE_SIZE) + .map((team) => ({ + ...team, + seedInfo: seedInfoByTeamId.get(team.id), + })), currentPage, pagesCount, }; }; + +function teamSeedInfo(tournament: Tournament) { + const perBracketSeedCounters = new Map(); + + return new Map( + tournament.ctx.teams.map((team, globalIndex) => { + if (!tournament.isMultiStartingBracket) { + return [ + team.id, + { + seed: globalIndex + 1, + bracketLabel: undefined as string | undefined, + }, + ] as const; + } + + const bracketIdx = team.startingBracketIdx ?? 0; + const currentSeed = (perBracketSeedCounters.get(bracketIdx) ?? 0) + 1; + perBracketSeedCounters.set(bracketIdx, currentSeed); + + return [ + team.id, + { + seed: currentSeed, + bracketLabel: getBracketProgressionLabel( + bracketIdx, + tournament.ctx.settings.bracketProgression, + ), + }, + ] as const; + }), + ); +} diff --git a/app/features/tournament/routes/to.$id.teams.tsx b/app/features/tournament/routes/to.$id.teams.tsx index 6c9c95762..6ffc52388 100644 --- a/app/features/tournament/routes/to.$id.teams.tsx +++ b/app/features/tournament/routes/to.$id.teams.tsx @@ -6,7 +6,6 @@ import { tournamentTeamPage } from "~/utils/urls"; import { TeamWithRoster } from "../components/TeamWithRoster"; import type { TournamentTeamsLoaderData } from "../loaders/to.$id.teams.server"; import { tournamentTeamsSearchParams } from "../tournament-search-params"; -import { getBracketProgressionLabel } from "../tournament-utils"; export { loader } from "../loaders/to.$id.teams.server"; @@ -19,60 +18,21 @@ export default function TournamentTeamsPage() { pagesCount: data.pagesCount, }); - const seedInfoByTeamId = teamSeedInfo(tournament); - return (
- {data.teams.map((team) => { - const { seed, bracketLabel } = seedInfoByTeamId.get(team.id) ?? {}; - - return ( - - ); - })} + {data.teams.map((team) => ( + + ))} {data.pagesCount > 1 ? : null}
); } - -function teamSeedInfo(tournament: ReturnType) { - const perBracketSeedCounters = new Map(); - - return new Map( - tournament.ctx.teams.map((team, globalIndex) => { - if (!tournament.isMultiStartingBracket) { - return [ - team.id, - { - seed: globalIndex + 1, - bracketLabel: undefined as string | undefined, - }, - ] as const; - } - - const bracketIdx = team.startingBracketIdx ?? 0; - const currentSeed = (perBracketSeedCounters.get(bracketIdx) ?? 0) + 1; - perBracketSeedCounters.set(bracketIdx, currentSeed); - - return [ - team.id, - { - seed: currentSeed, - bracketLabel: getBracketProgressionLabel( - bracketIdx, - tournament.ctx.settings.bracketProgression, - ), - }, - ] as const; - }), - ); -} diff --git a/changelog/2026-09-01-teams-tab-seed-order.md b/changelog/2026-09-01-teams-tab-seed-order.md new file mode 100644 index 000000000..c148670f2 --- /dev/null +++ b/changelog/2026-09-01-teams-tab-seed-order.md @@ -0,0 +1,5 @@ +--- +navItem: calendar +type: bug +--- +Fixed the tournament teams tab sometimes showing seed numbers out of order