From 3d7ea4447a87e5f2e4753537f1a071f5a1a2c0c7 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 11 Apr 2026 13:34:16 +0300 Subject: [PATCH] Revalidate match pages on team drop --- .../actions/to.$id.matches.$mid.server.ts | 16 +++++++++++++- .../tournament/actions/to.$id.admin.server.ts | 22 ++++++++++++++++++- .../tournament/tournament-utils.server.ts | 6 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts b/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts index ec8a02ad9..7f666ae2a 100644 --- a/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-bracket/actions/to.$id.matches.$mid.server.ts @@ -113,6 +113,7 @@ export const action: ActionFunction = async ({ params, request }) => { let emitMatchUpdate = false; let emitTournamentUpdate = false; + let endedDroppedMatchIds: number[] = []; switch (data._action) { case "REPORT_SCORE": { @@ -225,7 +226,10 @@ export const action: ActionFunction = async ({ params, request }) => { } if (setOver) { - endDroppedTeamMatches({ tournament, manager }); + endedDroppedMatchIds = endDroppedTeamMatches({ + tournament, + manager, + }); } })(); @@ -710,6 +714,11 @@ export const action: ActionFunction = async ({ params, request }) => { result: winnerTeamId === match.opponentTwo!.id ? "win" : "loss", }, }); + + endedDroppedMatchIds = endDroppedTeamMatches({ + tournament, + manager, + }); })(); emitMatchUpdate = true; @@ -732,6 +741,11 @@ export const action: ActionFunction = async ({ params, request }) => { type: "TOURNAMENT_MATCH_UPDATED", revalidateOnly: true, }, + ...endedDroppedMatchIds.map((id) => ({ + room: tournamentMatchWebsocketRoom(id), + type: "TOURNAMENT_MATCH_UPDATED" as const, + revalidateOnly: true as const, + })), ]); } if (emitTournamentUpdate) { diff --git a/app/features/tournament/actions/to.$id.admin.server.ts b/app/features/tournament/actions/to.$id.admin.server.ts index 4b26a9d90..942d56502 100644 --- a/app/features/tournament/actions/to.$id.admin.server.ts +++ b/app/features/tournament/actions/to.$id.admin.server.ts @@ -3,6 +3,7 @@ import * as R from "remeda"; import { DANGEROUS_CAN_ACCESS_DEV_CONTROLS } from "~/features/admin/core/dev-controls"; import { requireUser } from "~/features/auth/core/user.server"; import { userIsBanned } from "~/features/ban/core/banned.server"; +import * as ChatSystemMessage from "~/features/chat/ChatSystemMessage.server"; import * as ShowcaseTournaments from "~/features/front-page/core/ShowcaseTournaments.server"; import { notify } from "~/features/notifications/core/notify.server"; import * as TournamentTeamRepository from "~/features/tournament/TournamentTeamRepository.server"; @@ -12,6 +13,10 @@ import { clearTournamentDataCache, tournamentFromDB, } from "~/features/tournament-bracket/core/Tournament.server"; +import { + tournamentMatchWebsocketRoom, + tournamentWebsocketRoom, +} from "~/features/tournament-bracket/tournament-bracket-utils"; import * as TournamentLFGRepository from "~/features/tournament-lfg/TournamentLFGRepository.server"; import * as UserRepository from "~/features/user-page/UserRepository.server"; import invariant from "~/utils/invariant"; @@ -396,7 +401,7 @@ export const action: ActionFunction = async ({ request, params }) => { }); } - endDroppedTeamMatches({ + const endedMatchIds = endDroppedTeamMatches({ tournament, manager: getServerTournamentManager(), droppedTeamId: data.teamId, @@ -409,6 +414,21 @@ export const action: ActionFunction = async ({ request, params }) => { ), }); + if (endedMatchIds.length > 0) { + ChatSystemMessage.send([ + ...endedMatchIds.map((matchId) => ({ + room: tournamentMatchWebsocketRoom(matchId), + type: "TOURNAMENT_MATCH_UPDATED" as const, + revalidateOnly: true as const, + })), + { + room: tournamentWebsocketRoom(tournament.ctx.id), + type: "TOURNAMENT_UPDATED" as const, + revalidateOnly: true as const, + }, + ]); + } + message = "Team dropped out"; break; } diff --git a/app/features/tournament/tournament-utils.server.ts b/app/features/tournament/tournament-utils.server.ts index 5ee29b5f8..d156ee650 100644 --- a/app/features/tournament/tournament-utils.server.ts +++ b/app/features/tournament/tournament-utils.server.ts @@ -63,6 +63,8 @@ export function endDroppedTeamMatches({ }) { const stageData = manager.get.tournamentData(tournament.ctx.id); + const endedMatchIds: number[] = []; + for (const match of stageData.match) { if (!match.opponent1?.id || !match.opponent2?.id) continue; if (match.opponent1.result === "win" || match.opponent2.result === "win") @@ -100,5 +102,9 @@ export function endDroppedTeamMatches({ }, true, ); + + endedMatchIds.push(match.id); } + + return endedMatchIds; }