mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-29 22:58:18 -05:00
Fix bracket progression submit crashing when changing bracket format
This commit is contained in:
@@ -569,6 +569,7 @@ export interface TournamentRound {
|
||||
maps: ColumnType<TournamentRoundMaps | null, string | null, string | null>;
|
||||
}
|
||||
|
||||
// when updating this also update `defaultBracketSettings` in tournament-utils.ts
|
||||
export interface TournamentStageSettings {
|
||||
// SE
|
||||
thirdPlaceMatch?: boolean;
|
||||
|
||||
@@ -92,8 +92,6 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
rankedModesShort.find((mode) => mode === data.toToolsMode) ?? null,
|
||||
bracketProgression: data.bracketProgression ?? null,
|
||||
minMembersPerTeam: data.minMembersPerTeam ?? undefined,
|
||||
teamsPerGroup: data.teamsPerGroup ?? undefined,
|
||||
thirdPlaceMatch: data.thirdPlaceMatch ?? undefined,
|
||||
isRanked: data.isRanked ?? undefined,
|
||||
isInvitational: data.isInvitational ?? false,
|
||||
deadlines: data.strictDeadline ? ("STRICT" as const) : ("DEFAULT" as const),
|
||||
@@ -101,8 +99,6 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
enableSubs: data.enableSubs ?? undefined,
|
||||
requireInGameNames: data.requireInGameNames ?? undefined,
|
||||
autonomousSubs: data.autonomousSubs ?? undefined,
|
||||
swissGroupCount: data.swissGroupCount ?? undefined,
|
||||
swissRoundCount: data.swissRoundCount ?? undefined,
|
||||
tournamentToCopyId: data.tournamentToCopyId,
|
||||
regClosesAt: data.regClosesAt
|
||||
? dateToDatabaseTimestamp(
|
||||
@@ -283,35 +279,8 @@ export const newCalendarEventActionSchema = z
|
||||
checkboxValueToBoolean,
|
||||
z.boolean().nullish(),
|
||||
),
|
||||
//
|
||||
// tournament format related fields
|
||||
//
|
||||
bracketProgression: bracketProgressionSchema.nullish(),
|
||||
minMembersPerTeam: z.coerce.number().int().min(1).max(4).nullish(),
|
||||
withUndergroundBracket: z.preprocess(checkboxValueToBoolean, z.boolean()),
|
||||
thirdPlaceMatch: z.preprocess(
|
||||
checkboxValueToBoolean,
|
||||
z.boolean().nullish(),
|
||||
),
|
||||
teamsPerGroup: z.coerce
|
||||
.number()
|
||||
.min(TOURNAMENT.MIN_GROUP_SIZE)
|
||||
.max(TOURNAMENT.MAX_GROUP_SIZE)
|
||||
.nullish(),
|
||||
swissGroupCount: z.coerce.number().int().positive().nullish(),
|
||||
swissRoundCount: z.coerce.number().int().positive().nullish(),
|
||||
followUpBrackets: z.preprocess(
|
||||
safeJSONParse,
|
||||
z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
placements: z.array(z.number()),
|
||||
}),
|
||||
)
|
||||
.min(1)
|
||||
.nullish(),
|
||||
),
|
||||
bracketProgression: bracketProgressionSchema.nullish(),
|
||||
})
|
||||
.refine(
|
||||
async (schema) => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { SendouSwitch } from "~/components/elements/Switch";
|
||||
import { PlusIcon } from "~/components/icons/Plus";
|
||||
import { TOURNAMENT } from "~/features/tournament";
|
||||
import * as Progression from "~/features/tournament-bracket/core/Progression";
|
||||
import { defaultBracketSettings } from "../../tournament/tournament-utils";
|
||||
|
||||
const defaultBracket = (): Progression.InputBracket => ({
|
||||
id: nanoid(),
|
||||
@@ -154,7 +155,15 @@ function TournamentFormatBracketSelector({
|
||||
const isFirstBracket = count === 1;
|
||||
|
||||
const updateBracket = (newProps: Partial<Progression.InputBracket>) => {
|
||||
onChange({ ...bracket, ...newProps });
|
||||
const defaultSettings = newProps.type
|
||||
? defaultBracketSettings(newProps.type)
|
||||
: undefined;
|
||||
|
||||
onChange({
|
||||
...bracket,
|
||||
...newProps,
|
||||
settings: newProps.settings ?? defaultSettings ?? bracket.settings,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -5,6 +5,8 @@ import { rankedModesShort } from "~/modules/in-game-lists/modes";
|
||||
import { weekNumberToDate } from "~/utils/dates";
|
||||
import invariant from "~/utils/invariant";
|
||||
import { tournamentLogoUrl } from "~/utils/urls";
|
||||
import type { Tables, TournamentStageSettings } from "../../db/tables";
|
||||
import { assertUnreachable } from "../../utils/types";
|
||||
import { MapPool } from "../map-list-generator/core/map-pool";
|
||||
import { currentSeason } from "../mmr/season";
|
||||
import { BANNED_MAPS } from "../sendouq-settings/banned-maps";
|
||||
@@ -307,3 +309,32 @@ export function resolveLeagueRoundStartDate(
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
export function defaultBracketSettings(
|
||||
type: Tables["TournamentStage"]["type"],
|
||||
): TournamentStageSettings {
|
||||
switch (type) {
|
||||
case "single_elimination": {
|
||||
return {
|
||||
thirdPlaceMatch: true,
|
||||
};
|
||||
}
|
||||
case "double_elimination": {
|
||||
return {};
|
||||
}
|
||||
case "round_robin": {
|
||||
return {
|
||||
teamsPerGroup: 4,
|
||||
};
|
||||
}
|
||||
case "swiss": {
|
||||
return {
|
||||
roundCount: 5,
|
||||
groupCount: 1,
|
||||
};
|
||||
}
|
||||
default: {
|
||||
assertUnreachable(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user