mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-08 12:16:12 -05:00
Fix team list page showing wrong seed
This commit is contained in:
@@ -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<typeof loader>;
|
||||
|
||||
@@ -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<number, number>();
|
||||
|
||||
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;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<div className="stack lg">
|
||||
{data.teams.map((team) => {
|
||||
const { seed, bracketLabel } = seedInfoByTeamId.get(team.id) ?? {};
|
||||
|
||||
return (
|
||||
<TeamWithRoster
|
||||
key={team.id}
|
||||
team={team}
|
||||
seed={seed}
|
||||
bracketLabel={bracketLabel}
|
||||
teamPageUrl={tournamentTeamPage({
|
||||
tournamentId: tournament.ctx.id,
|
||||
tournamentTeamId: team.id,
|
||||
})}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{data.teams.map((team) => (
|
||||
<TeamWithRoster
|
||||
key={team.id}
|
||||
team={team}
|
||||
seed={team.seedInfo?.seed}
|
||||
bracketLabel={team.seedInfo?.bracketLabel}
|
||||
teamPageUrl={tournamentTeamPage({
|
||||
tournamentId: tournament.ctx.id,
|
||||
tournamentTeamId: team.id,
|
||||
})}
|
||||
/>
|
||||
))}
|
||||
{data.pagesCount > 1 ? <Pagination {...pagination} /> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function teamSeedInfo(tournament: ReturnType<typeof useTournament>) {
|
||||
const perBracketSeedCounters = new Map<number, number>();
|
||||
|
||||
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;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
5
changelog/2026-09-01-teams-tab-seed-order.md
Normal file
5
changelog/2026-09-01-teams-tab-seed-order.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
navItem: calendar
|
||||
type: bug
|
||||
---
|
||||
Fixed the tournament teams tab sometimes showing seed numbers out of order
|
||||
Reference in New Issue
Block a user