diff --git a/app/components/tournament/DuringMatchActions.tsx b/app/components/tournament/DuringMatchActions.tsx
index 287f1002a..c08e0e7d2 100644
--- a/app/components/tournament/DuringMatchActions.tsx
+++ b/app/components/tournament/DuringMatchActions.tsx
@@ -43,7 +43,11 @@ export function DuringMatchActions({
});
if (joinedRoom) {
- const currentStage = currentRound.stages.find((m) => m.position === 1);
+ const currentPosition =
+ currentMatch.score?.reduce((acc, cur) => acc + cur, 1) ?? 1;
+ const currentStage = currentRound.stages.find(
+ (m) => m.position === currentPosition
+ );
invariant(currentStage, "currentStage is undefined");
const { stage } = currentStage;
@@ -66,9 +70,7 @@ export function DuringMatchActions({
/>
{modesShortToLong[stage.mode]} on {stage.name}
-
- Stage {currentMatch.score?.reduce((acc, cur) => acc + cur, 1)}
-
+ Stage {currentPosition}
@@ -90,6 +92,7 @@ export function DuringMatchActions({
ownTeam={ownTeam}
opponentTeam={opponentTeam}
matchId={currentMatch.id}
+ position={currentPosition}
/>
diff --git a/app/components/tournament/DuringMatchActionsRosters.tsx b/app/components/tournament/DuringMatchActionsRosters.tsx
index daefaa6e9..9ffafb0cb 100644
--- a/app/components/tournament/DuringMatchActionsRosters.tsx
+++ b/app/components/tournament/DuringMatchActionsRosters.tsx
@@ -11,10 +11,12 @@ export function DuringMatchActionsRosters({
ownTeam,
opponentTeam,
matchId,
+ position,
}: {
ownTeam: Unpacked;
opponentTeam: Unpacked;
matchId: string;
+ position: number;
}) {
const [checkedPlayers, setCheckedPlayers] = React.useState<
[string[], string[]]
@@ -89,6 +91,7 @@ export function DuringMatchActionsRosters({
name="playerIds"
value={JSON.stringify(checkedPlayers.flat())}
/>
+
{
return new Date(new Date(startTime).getTime() - 1000 * 10);
};
diff --git a/app/models/TournamentMatch.ts b/app/models/TournamentMatch.ts
index ce4a9658b..07cf5b60d 100644
--- a/app/models/TournamentMatch.ts
+++ b/app/models/TournamentMatch.ts
@@ -26,13 +26,13 @@ export function findById(id: string) {
}
export function createResult({
- position,
+ roundStageId,
reporterId,
winner,
matchId,
playerIds,
}: {
- position: number;
+ roundStageId: string;
reporterId: string;
winner: TeamOrder;
matchId: string;
@@ -40,7 +40,11 @@ export function createResult({
}) {
return db.tournamentMatchGameResult.create({
data: {
- position,
+ roundStage: {
+ connect: {
+ id: roundStageId,
+ },
+ },
reporterId,
winner,
players: {
diff --git a/app/routes/to/$organization.$tournament/bracket.$id.tsx b/app/routes/to/$organization.$tournament/bracket.$id.tsx
index babe5b6be..3fb9ff7bc 100644
--- a/app/routes/to/$organization.$tournament/bracket.$id.tsx
+++ b/app/routes/to/$organization.$tournament/bracket.$id.tsx
@@ -12,7 +12,8 @@ import type { BracketModified } from "~/services/tournament";
import { useUser } from "~/utils/hooks";
import { BracketActions } from "~/components/tournament/BracketActions";
import { z } from "zod";
-import { parseRequestFormData, requireUser } from "~/utils";
+import { parseRequestFormData, requireUser, safeJSONParse } from "~/utils";
+import { BEST_OF_OPTIONS, TOURNAMENT_TEAM_ROSTER_MIN_SIZE } from "~/constants";
export const links: LinksFunction = () => {
return [{ rel: "stylesheet", href: styles }];
@@ -23,9 +24,16 @@ const bracketActionSchema = z.union([
_action: z.literal("REPORT_SCORE"),
matchId: z.string().uuid(),
winnerTeamId: z.string().uuid(),
+ position: z.preprocess(
+ Number,
+ z
+ .number()
+ .min(1)
+ .max(Math.max(...BEST_OF_OPTIONS))
+ ),
playerIds: z.preprocess(
- (val) => (val ? JSON.parse(val as any) : undefined),
- z.array(z.string().uuid()).length(8)
+ safeJSONParse,
+ z.array(z.string().uuid()).length(TOURNAMENT_TEAM_ROSTER_MIN_SIZE * 2)
),
}),
z.object({
@@ -55,6 +63,7 @@ export const action: ActionFunction = async ({
playerIds: data.playerIds,
userId: user.id,
winnerTeamId: data.winnerTeamId,
+ position: data.position,
});
return { ok: "REPORT_SCORE" };
}
diff --git a/app/routes/to/$organization.$tournament/start.tsx b/app/routes/to/$organization.$tournament/start.tsx
index 1919db342..6029c51d6 100644
--- a/app/routes/to/$organization.$tournament/start.tsx
+++ b/app/routes/to/$organization.$tournament/start.tsx
@@ -16,7 +16,7 @@ import { Alert } from "~/components/Alert";
import { Button } from "~/components/Button";
import { Catcher } from "~/components/Catcher";
import { RefreshIcon } from "~/components/icons/Refresh";
-import { modesShort, modesShortToLong } from "~/constants";
+import { BEST_OF_OPTIONS, modesShort, modesShortToLong } from "~/constants";
import { eliminationBracket } from "~/core/tournament/algorithms";
import {
EliminationBracketSide,
@@ -229,7 +229,7 @@ function RoundsCollection({
{round.name}
- {([3, 5, 7, 9] as const).map((bestOf) => (
+ {BEST_OF_OPTIONS.map((bestOf) => (