Revalidate match pages on team drop

This commit is contained in:
Kalle
2026-04-11 13:34:16 +03:00
parent fa9ac427bd
commit 3d7ea4447a
3 changed files with 42 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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;
}