From 0ba2b4c789ff394ce37e03884a196897ed7355de Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:36:57 +0200 Subject: [PATCH] Dynamic max roster size --- .../routes/to.$id.brackets.tsx | 8 +++++--- app/features/tournament/routes/to.$id.join.tsx | 9 ++++++++- .../tournament/routes/to.$id.register.tsx | 8 +++++--- app/features/tournament/tournament-constants.ts | 2 +- app/features/tournament/tournament-utils.ts | 16 ++++++++++++++-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/features/tournament-bracket/routes/to.$id.brackets.tsx b/app/features/tournament-bracket/routes/to.$id.brackets.tsx index 37bb8d45a..605d301cb 100644 --- a/app/features/tournament-bracket/routes/to.$id.brackets.tsx +++ b/app/features/tournament-bracket/routes/to.$id.brackets.tsx @@ -81,6 +81,7 @@ import { } from "~/features/mmr"; import { queryTeamPlayerRatingAverage } from "~/features/mmr/mmr-utils.server"; import * as TournamentRepository from "~/features/tournament/TournamentRepository.server"; +import { HACKY_maxRosterSizeBeforeStart } from "~/features/tournament/tournament-utils"; export const links: LinksFunction = () => { return [ @@ -122,8 +123,7 @@ export const action: ActionFunction = async ({ params, request }) => { } else { // in the normal check in process this is handled teams = teams.filter( - (team) => - team.members.length > TOURNAMENT.TEAM_MAX_MEMBERS_BEFORE_START, + (team) => team.members.length >= TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL, ); } @@ -623,7 +623,9 @@ function AddSubsPopOver({ const [, copyToClipboard] = useCopyToClipboard(); const subsAvailableToAdd = - TOURNAMENT.TEAM_MAX_MEMBERS_BEFORE_START + 1 - members.length; + HACKY_maxRosterSizeBeforeStart(parentRouteData.tournament) + + 1 - + members.length; const inviteLink = `${SENDOU_INK_BASE_URL}${tournamentJoinPage({ eventId: parentRouteData.tournament.id, diff --git a/app/features/tournament/routes/to.$id.join.tsx b/app/features/tournament/routes/to.$id.join.tsx index d29cbfbd7..d55a99c83 100644 --- a/app/features/tournament/routes/to.$id.join.tsx +++ b/app/features/tournament/routes/to.$id.join.tsx @@ -24,6 +24,7 @@ import { tournamentTeamMaxSize, } from "../tournament-utils"; import { useTranslation } from "~/hooks/useTranslation"; +import { findByIdentifier } from "../queries/findByIdentifier.server"; export const action: ActionFunction = async ({ request, params }) => { const tournamentId = tournamentIdFromParams(params); @@ -41,6 +42,7 @@ export const action: ActionFunction = async ({ request, params }) => { team.members.some((member) => member.userId === user.id), ); + const tournament = notFoundIfFalsy(findByIdentifier(tournamentId)); const tournamentHasStarted = hasTournamentStarted(tournamentId); if (tournamentHasStarted) { @@ -56,6 +58,7 @@ export const action: ActionFunction = async ({ request, params }) => { teamToJoin, userId: user.id, tournamentHasStarted, + tournament, }) === "VALID", "Cannot join this team or invite code is invalid", ); @@ -118,6 +121,7 @@ export default function JoinTeamPage() { ); const captain = teamToJoin?.members.find((member) => member.isOwner); const validationStatus = validateCanJoin({ + tournament: parentRouteData.tournament, inviteCode: data.inviteCode, teamToJoin, userId: user?.id, @@ -174,11 +178,13 @@ function validateCanJoin({ teamToJoin, userId, tournamentHasStarted, + tournament, }: { inviteCode?: string | null; teamToJoin?: TournamentLoaderTeam; userId?: number; tournamentHasStarted: boolean; + tournament: { name: string }; }) { if (typeof inviteCode !== "string") { return "MISSING_CODE"; @@ -193,7 +199,8 @@ function validateCanJoin({ return "NO_TEAM_MATCHING_CODE"; } if ( - teamToJoin.members.length >= tournamentTeamMaxSize(tournamentHasStarted) + teamToJoin.members.length >= + tournamentTeamMaxSize({ tournament, tournamentHasStarted }) ) { return "TEAM_FULL"; } diff --git a/app/features/tournament/routes/to.$id.register.tsx b/app/features/tournament/routes/to.$id.register.tsx index 21bfc1bc7..5dadbd31e 100644 --- a/app/features/tournament/routes/to.$id.register.tsx +++ b/app/features/tournament/routes/to.$id.register.tsx @@ -75,6 +75,7 @@ import { useSelectCounterpickMapPoolState } from "../tournament-hooks"; import { registerSchema } from "../tournament-schemas.server"; import { HACKY_isInviteOnlyEvent, + HACKY_maxRosterSizeBeforeStart, HACKY_resolveCheckInTime, HACKY_resolvePicture, HACKY_subsFeatureEnabled, @@ -677,7 +678,7 @@ function FillRoster({ ); const optionalMembers = Math.max( - TOURNAMENT.TEAM_MAX_MEMBERS_BEFORE_START - + HACKY_maxRosterSizeBeforeStart(parentRouteData.tournament) - ownTeamMembers.length - missingMembers, 0, @@ -697,7 +698,8 @@ function FillRoster({ })(); const teamIsFull = - ownTeamMembers.length >= TOURNAMENT.TEAM_MAX_MEMBERS_BEFORE_START; + ownTeamMembers.length >= + HACKY_maxRosterSizeBeforeStart(parentRouteData.tournament); return (