feat: add double elimination match mode

This commit is contained in:
dahyeon committed 2026-06-26 05:00:08 -07:00
1 parent b9aaf55193
commit e12f182e7f
19 files changed
+3415 -58

No files matched your search

+872 -5
View File
@@ -1,9 +1,19 @@
import { useEffect, useState } from "react";
import { useEffect, useState, type CSSProperties } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, ChevronRight, Search, X } from "lucide-react";
import {
AlertTriangle,
ArrowLeftRight,
ChevronRight,
Search,
Shuffle,
X,
} from "lucide-react";
import { Link, useLocation, useNavigate, useParams } from "react-router";
import {
useAuction,
useApplyDoubleEliminationWalkover,
useCancelDoubleEliminationRiotResult,
useCancelDoubleEliminationWalkover,
useCollectTournamentResultByRiotMatch,
useCollectTournamentResultByWindow,
useCommunityUserSearch,
@@ -12,6 +22,8 @@ import {
useMe,
usePollTournamentResult,
useReplaceTournamentCode,
useReshuffleDoubleEliminationSeeds,
useSwapDoubleEliminationSeeds,
useTournamentCodeStats,
useUserHistoryProfile,
} from "../api/hooks";
@@ -36,6 +48,7 @@ import type {
AuctionTopTierThreshold,
ApiCommunityUserSearchCandidate,
ApiCommunityUserSearchRiotAccount,
ApiDoubleEliminationBracketMatch,
ApiMatch,
ApiMatchParticipant,
ApiPositionPreference,
@@ -1520,7 +1533,10 @@ function TournamentCodeList({
function renderSlot(slot: TournamentCodeSlotView) {
const shouldShowTeamLabel =
gameMode === "round-robin" || slot.teamAIndex > 1 || slot.teamBIndex > 2;
gameMode === "round-robin" ||
gameMode === "double-elimination" ||
(slot.teamAIndex ?? 0) > 1 ||
(slot.teamBIndex ?? 0) > 2;
return (
<div
@@ -1533,8 +1549,9 @@ function TournamentCodeList({
</span>
{shouldShowTeamLabel && (
<span className="min-w-0 truncate text-xs text-base-content/30">
{teamIndexLabel(slot.teamAIndex)} vs{" "}
{teamIndexLabel(slot.teamBIndex)}
{slot.bracketMatchId ? `${slot.bracketMatchId} · ` : ""}
{slot.teamAIndex ? teamIndexLabel(slot.teamAIndex) : "미정"} vs{" "}
{slot.teamBIndex ? teamIndexLabel(slot.teamBIndex) : "미정"}
</span>
)}
</div>
@@ -2249,6 +2266,768 @@ function MatchGameListSection({ match }: { match: MatchDetailView }) {
);
}
const DOUBLE_ELIMINATION_MATCH_CARD_WIDTH = 208;
const DOUBLE_ELIMINATION_MATCH_CARD_HEIGHT = 112;
const DOUBLE_ELIMINATION_TEAM_A_CENTER_Y = 52;
const DOUBLE_ELIMINATION_TEAM_B_CENTER_Y = 80;
const DOUBLE_ELIMINATION_MATCH_CENTER_Y = 66;
type DoubleEliminationSeriesResult = NonNullable<
NonNullable<ApiMatch["result"]>["seriesResults"]
>[number];
type DoubleEliminationBracketNodeLayout = {
bracketMatchId: string;
x: number;
y: number;
};
type DoubleEliminationRoundLabelLayout = {
label: string;
x: number;
y: number;
};
type DoubleEliminationBracketLayout = {
width: number;
height: number;
nodes: DoubleEliminationBracketNodeLayout[];
labels: DoubleEliminationRoundLabelLayout[];
};
type DoubleEliminationConnectorTone = "winner" | "loser" | "reset";
type DoubleEliminationConnector = {
fromBracketMatchId: string;
toBracketMatchId: string;
toPosition: "A" | "B";
tone: DoubleEliminationConnectorTone;
};
const DOUBLE_ELIMINATION_BRACKET_SIDE_LABEL: Record<
ApiDoubleEliminationBracketMatch["bracketSide"],
string
> = {
winner: "승자조",
loser: "패자조",
"grand-final": "그랜드 파이널",
"reset-final": "리셋 파이널",
};
function buildDoubleEliminationBracketLayout(
teamCount: 4 | 8,
hasResetFinal: boolean,
): DoubleEliminationBracketLayout {
if (teamCount === 4) {
const nodes: DoubleEliminationBracketNodeLayout[] = [
{ bracketMatchId: "WB_R1_M1", x: 0, y: 92 },
{ bracketMatchId: "WB_R1_M2", x: 0, y: 252 },
{ bracketMatchId: "WB_FINAL", x: 260, y: 172 },
{ bracketMatchId: "LB_R1_M1", x: 260, y: 430 },
{ bracketMatchId: "LB_FINAL", x: 520, y: 430 },
{ bracketMatchId: "GF", x: 780, y: 172 },
...(hasResetFinal
? [{ bracketMatchId: "GF_RESET", x: 1040, y: 172 }]
: []),
];
return {
width:
(hasResetFinal ? 1040 : 780) +
DOUBLE_ELIMINATION_MATCH_CARD_WIDTH +
28,
height: 578,
nodes,
labels: [
{ label: "승자조 1라운드", x: 0, y: 44 },
{ label: "승자조 결승", x: 260, y: 44 },
{ label: "패자조 1라운드", x: 260, y: 382 },
{ label: "패자조 결승", x: 520, y: 382 },
{ label: "그랜드 파이널", x: 780, y: 44 },
...(hasResetFinal
? [{ label: "리셋 파이널", x: 1040, y: 44 }]
: []),
],
};
}
const nodes: DoubleEliminationBracketNodeLayout[] = [
{ bracketMatchId: "WB_R1_M1", x: 0, y: 58 },
{ bracketMatchId: "WB_R1_M2", x: 0, y: 162 },
{ bracketMatchId: "WB_R1_M3", x: 0, y: 266 },
{ bracketMatchId: "WB_R1_M4", x: 0, y: 370 },
{ bracketMatchId: "WB_R2_M1", x: 235, y: 110 },
{ bracketMatchId: "WB_R2_M2", x: 235, y: 318 },
{ bracketMatchId: "WB_FINAL", x: 705, y: 214 },
{ bracketMatchId: "LB_R1_M1", x: 235, y: 550 },
{ bracketMatchId: "LB_R1_M2", x: 235, y: 654 },
{ bracketMatchId: "LB_R2_M1", x: 470, y: 550 },
{ bracketMatchId: "LB_R2_M2", x: 470, y: 654 },
{ bracketMatchId: "LB_R3_M1", x: 705, y: 602 },
{ bracketMatchId: "LB_FINAL", x: 940, y: 602 },
{ bracketMatchId: "GF", x: 1175, y: 214 },
...(hasResetFinal
? [{ bracketMatchId: "GF_RESET", x: 1410, y: 214 }]
: []),
];
return {
width:
(hasResetFinal ? 1410 : 1175) +
DOUBLE_ELIMINATION_MATCH_CARD_WIDTH +
28,
height: 790,
nodes,
labels: [
{ label: "승자조 1라운드", x: 0, y: 20 },
{ label: "승자조 2라운드", x: 235, y: 20 },
{ label: "승자조 결승", x: 705, y: 20 },
{ label: "그랜드 파이널", x: 1175, y: 20 },
...(hasResetFinal
? [{ label: "리셋 파이널", x: 1410, y: 20 }]
: []),
{ label: "패자조 1라운드", x: 235, y: 512 },
{ label: "패자조 2라운드", x: 470, y: 512 },
{ label: "패자조 3라운드", x: 705, y: 512 },
{ label: "패자조 결승", x: 940, y: 512 },
],
};
}
function buildDoubleEliminationConnectors(
bracketMatches: ApiDoubleEliminationBracketMatch[],
): DoubleEliminationConnector[] {
const connectors = bracketMatches.flatMap((bracketMatch) => {
const next: DoubleEliminationConnector[] = [];
if (bracketMatch.winnerAdvancesTo) {
next.push({
fromBracketMatchId: bracketMatch.bracketMatchId,
toBracketMatchId: bracketMatch.winnerAdvancesTo.bracketMatchId,
toPosition: bracketMatch.winnerAdvancesTo.position,
tone: "winner",
});
}
if (bracketMatch.loserAdvancesTo) {
next.push({
fromBracketMatchId: bracketMatch.bracketMatchId,
toBracketMatchId: bracketMatch.loserAdvancesTo.bracketMatchId,
toPosition: bracketMatch.loserAdvancesTo.position,
tone: "loser",
});
}
return next;
});
if (
bracketMatches.some(
(bracketMatch) => bracketMatch.bracketMatchId === "GF_RESET",
)
) {
connectors.push(
{
fromBracketMatchId: "GF",
toBracketMatchId: "GF_RESET",
toPosition: "A",
tone: "reset",
},
{
fromBracketMatchId: "GF",
toBracketMatchId: "GF_RESET",
toPosition: "B",
tone: "reset",
},
);
}
return connectors;
}
function formatDoubleEliminationMatchState(
state: ApiDoubleEliminationBracketMatch["state"],
) {
if (state === "ready") return "진행 가능";
if (state === "completed") return "완료";
return "대기";
}
function formatDoubleEliminationCodeState(state?: string) {
if (!state) return null;
const labels: Record<string, string> = {
reserved: "코드 발급",
used: "코드 사용",
released: "코드 해제",
expired: "코드 만료",
voided: "코드 폐기",
};
return labels[state] ?? state;
}
function formatDoubleEliminationCompletionType(
completedBy?: ApiDoubleEliminationBracketMatch["completedBy"],
) {
if (completedBy === "walkover") return "부전승";
if (completedBy === "riot-result") return "결과 반영";
return null;
}
function DoubleEliminationBracketSection({
match,
canManage,
busy,
onReshuffleSeeds,
onSwapSeeds,
onWalkover,
onCancelWalkover,
onCancelResult,
}: {
match: MatchDetailView;
canManage: boolean;
busy: boolean;
onReshuffleSeeds: () => void;
onSwapSeeds: () => void;
onWalkover: (bracketMatchId: string, winnerTeamIndex: number) => void;
onCancelWalkover: (bracketMatchId: string) => void;
onCancelResult: (bracketMatchId: string) => void;
}) {
const bracket = match.doubleElimination;
if (!bracket) return null;
const hasResetFinal = bracket.bracketMatches.some(
(bracketMatch) => bracketMatch.bracketMatchId === "GF_RESET",
);
const layout = buildDoubleEliminationBracketLayout(
bracket.teamCount,
hasResetFinal,
);
const layoutNodeById = new Map(
layout.nodes.map((node) => [node.bracketMatchId, node]),
);
const connectors = buildDoubleEliminationConnectors(
bracket.bracketMatches,
).filter(
(connector) =>
layoutNodeById.has(connector.fromBracketMatchId) &&
layoutNodeById.has(connector.toBracketMatchId),
);
const codeByBracketMatchId = new Map(
match.tournamentCodes
.filter((slot) => slot.bracketMatchId)
.map((slot) => [slot.bracketMatchId as string, slot]),
);
const seriesByBracketMatchId = new Map(
(match.result?.seriesResults ?? [])
.filter((series) => series.bracketMatchId)
.map((series) => [series.bracketMatchId as string, series]),
);
const seedNumberByTeamIndex = new Map(
bracket.seeds.map((seed) => [seed.teamIndex, seed.seedNumber]),
);
const canChangeSeeds =
canManage &&
!bracket.bracketMatches.some(
(bracketMatch) => bracketMatch.state === "completed",
);
const placedBracketMatchIds = new Set(
layout.nodes.map((node) => node.bracketMatchId),
);
const unplacedBracketMatches = bracket.bracketMatches.filter(
(bracketMatch) => !placedBracketMatchIds.has(bracketMatch.bracketMatchId),
);
const placementItems = [
{ label: "우승", teamIndex: bracket.placements.firstTeamIndex },
{ label: "준우승", teamIndex: bracket.placements.secondTeamIndex },
{ label: "3위", teamIndex: bracket.placements.thirdTeamIndex },
].filter((item) => item.teamIndex);
return (
<section className="mb-6 border border-base-content/10 bg-base-100">
<div className="flex flex-col gap-3 border-b border-base-content/10 bg-base-200/35 px-4 py-3 lg:flex-row lg:items-center lg:justify-between">
<div className="min-w-0">
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-sm font-black text-base-content">
더블 엘리미네이션
</h2>
<span className="border border-info/20 bg-info/8 px-1.5 py-0.5 text-[11px] font-bold text-info">
{bracket.teamCount}팀
</span>
<span className="border border-base-content/10 px-1.5 py-0.5 text-[11px] font-bold text-base-content/45">
GF 리셋 {bracket.resetFinalEnabled ? "허용" : "미사용"}
</span>
</div>
<div className="mt-2 flex flex-wrap gap-1.5 text-xs text-base-content/40">
{bracket.seeds.map((seed) => (
<span
key={seed.seedNumber}
className="inline-flex max-w-[12rem] items-center gap-1 border border-base-content/10 bg-base-100 px-1.5 py-0.5"
>
<span className="font-mono text-[11px] font-black text-primary">
S{seed.seedNumber}
</span>
<span className="truncate">
{resolveMatchTeamName(match, seed.teamIndex)}
</span>
</span>
))}
{placementItems.map((item) => (
<span
key={item.label}
className="inline-flex max-w-[12rem] items-center gap-1 border border-accent/20 bg-accent/10 px-1.5 py-0.5 text-accent-content"
>
<span className="font-bold">{item.label}</span>
<span className="truncate">
{resolveMatchTeamName(match, item.teamIndex as number)}
</span>
</span>
))}
</div>
</div>
{canManage && (
<div className="flex shrink-0 flex-wrap gap-2">
<button
type="button"
className="inline-flex h-8 items-center gap-1.5 border border-base-content/10 bg-base-100 px-2.5 text-xs font-bold text-base-content/50 hover:border-primary/25 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-40"
disabled={!canChangeSeeds || busy}
onClick={onReshuffleSeeds}
>
<Shuffle className="h-3.5 w-3.5" aria-hidden="true" />
시드 재추첨
</button>
<button
type="button"
className="inline-flex h-8 items-center gap-1.5 border border-base-content/10 bg-base-100 px-2.5 text-xs font-bold text-base-content/50 hover:border-primary/25 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-40"
disabled={!canChangeSeeds || busy}
onClick={onSwapSeeds}
>
<ArrowLeftRight className="h-3.5 w-3.5" aria-hidden="true" />
시드 교체
</button>
</div>
)}
</div>
<div className="border-t border-base-content/8 bg-base-content/[0.015] p-3 sm:p-4">
<div
className="overflow-x-auto border border-base-content/10 bg-base-100"
role="region"
aria-label="더블 엘리미네이션 대진표"
>
<div
className="relative shrink-0"
style={{ width: layout.width, height: layout.height }}
>
<div className="pointer-events-none absolute inset-0 bg-base-200/25" />
{layout.labels.map((label) => (
<div
key={`${label.label}-${label.x}-${label.y}`}
className="absolute z-10"
style={{
left: label.x,
top: label.y,
width: DOUBLE_ELIMINATION_MATCH_CARD_WIDTH,
}}
>
<div className="flex items-center gap-2">
<span className="text-[11px] font-black uppercase tracking-wider text-base-content/40">
{label.label}
</span>
<span className="h-px min-w-8 flex-1 bg-base-content/10" />
</div>
</div>
))}
{connectors.map((connector, index) => (
<DoubleEliminationBracketConnector
key={`${connector.fromBracketMatchId}-${connector.toBracketMatchId}-${connector.toPosition}-${index}`}
connector={connector}
layoutNodeById={layoutNodeById}
/>
))}
{bracket.bracketMatches
.filter((bracketMatch) =>
layoutNodeById.has(bracketMatch.bracketMatchId),
)
.map((bracketMatch) => {
const node = layoutNodeById.get(bracketMatch.bracketMatchId);
if (!node) return null;
return (
<DoubleEliminationBracketCard
key={bracketMatch.bracketMatchId}
match={match}
bracketMatch={bracketMatch}
seedNumberByTeamIndex={seedNumberByTeamIndex}
seriesResult={seriesByBracketMatchId.get(
bracketMatch.bracketMatchId,
)}
codeState={
codeByBracketMatchId.get(bracketMatch.bracketMatchId)
?.state
}
canManage={canManage}
busy={busy}
onWalkover={onWalkover}
onCancelWalkover={onCancelWalkover}
onCancelResult={onCancelResult}
style={{
left: node.x,
top: node.y,
width: DOUBLE_ELIMINATION_MATCH_CARD_WIDTH,
height: DOUBLE_ELIMINATION_MATCH_CARD_HEIGHT,
}}
/>
);
})}
</div>
</div>
{unplacedBracketMatches.length > 0 && (
<div className="mt-3 border border-base-content/10 bg-base-200/45 px-3 py-2 text-xs text-base-content/55">
표시되지 않은 대진:{" "}
{unplacedBracketMatches
.map((bracketMatch) => bracketMatch.bracketMatchId)
.join(", ")}
</div>
)}
</div>
</section>
);
}
function DoubleEliminationBracketConnector({
connector,
layoutNodeById,
}: {
connector: DoubleEliminationConnector;
layoutNodeById: Map<string, DoubleEliminationBracketNodeLayout>;
}) {
const from = layoutNodeById.get(connector.fromBracketMatchId);
const to = layoutNodeById.get(connector.toBracketMatchId);
if (!from || !to) return null;
const startX = from.x + DOUBLE_ELIMINATION_MATCH_CARD_WIDTH;
const startY = from.y + DOUBLE_ELIMINATION_MATCH_CENTER_Y;
const endX = to.x;
const endY =
to.y +
(connector.toPosition === "A"
? DOUBLE_ELIMINATION_TEAM_A_CENTER_Y
: DOUBLE_ELIMINATION_TEAM_B_CENTER_Y);
const horizontalDistance = Math.max(10, endX - startX);
const elbowX = startX + horizontalDistance / 2;
const topY = Math.min(startY, endY);
const connectorClass =
connector.tone === "winner"
? "bg-info/35"
: connector.tone === "loser"
? "bg-primary/25"
: "bg-accent/35";
return (
<div className="pointer-events-none absolute inset-0 z-0">
<div
className={`absolute h-[2px] ${connectorClass}`}
style={{
left: startX,
top: startY,
width: Math.max(0, elbowX - startX),
}}
/>
<div
className={`absolute w-[2px] ${connectorClass}`}
style={{
left: elbowX,
top: topY,
height: Math.max(2, Math.abs(endY - startY)),
}}
/>
<div
className={`absolute h-[2px] ${connectorClass}`}
style={{
left: elbowX,
top: endY,
width: Math.max(0, endX - elbowX),
}}
/>
</div>
);
}
function DoubleEliminationBracketCard({
match,
bracketMatch,
seedNumberByTeamIndex,
seriesResult,
codeState,
canManage,
busy,
onWalkover,
onCancelWalkover,
onCancelResult,
style,
}: {
match: MatchDetailView;
bracketMatch: ApiDoubleEliminationBracketMatch;
seedNumberByTeamIndex: Map<number, number>;
seriesResult?: DoubleEliminationSeriesResult;
codeState?: string;
canManage: boolean;
busy: boolean;
onWalkover: (bracketMatchId: string, winnerTeamIndex: number) => void;
onCancelWalkover: (bracketMatchId: string) => void;
onCancelResult: (bracketMatchId: string) => void;
style: CSSProperties;
}) {
const canApplyWalkover =
canManage &&
bracketMatch.state === "ready" &&
Boolean(bracketMatch.teamAIndex && bracketMatch.teamBIndex);
const codeStateLabel = formatDoubleEliminationCodeState(codeState);
const completionTypeLabel = formatDoubleEliminationCompletionType(
bracketMatch.completedBy,
);
return (
<div
className={`absolute z-20 border bg-base-100 p-1.5 shadow-[0_1px_0_rgba(0,0,0,0.03)] ${
bracketMatch.state === "ready"
? "border-info/25"
: bracketMatch.state === "completed"
? "border-accent/25"
: "border-base-content/10"
}`}
style={style}
>
<div className="flex h-full min-w-0 flex-col gap-1">
<div className="flex min-w-0 items-center justify-between gap-2">
<div className="flex min-w-0 items-center gap-1.5">
<span className="truncate font-mono text-[10px] font-black text-base-content/55">
{bracketMatch.bracketMatchId}
</span>
<span className="shrink-0 text-[10px] font-bold text-base-content/30">
G{bracketMatch.gameNumber}
</span>
</div>
<span
className={`shrink-0 text-[10px] font-black ${
bracketMatch.state === "ready"
? "text-info"
: bracketMatch.state === "completed"
? "text-accent"
: "text-base-content/35"
}`}
>
{formatDoubleEliminationMatchState(bracketMatch.state)}
</span>
</div>
<DoubleEliminationBracketTeamRow
match={match}
teamIndex={bracketMatch.teamAIndex}
seedNumber={
bracketMatch.teamAIndex
? seedNumberByTeamIndex.get(bracketMatch.teamAIndex)
: undefined
}
isWinner={bracketMatch.winnerTeamIndex === bracketMatch.teamAIndex}
isLoser={
bracketMatch.state === "completed" &&
bracketMatch.teamAIndex !== bracketMatch.winnerTeamIndex
}
score={resolveDoubleEliminationTeamScore(
seriesResult,
bracketMatch.teamAIndex,
)}
/>
<DoubleEliminationBracketTeamRow
match={match}
teamIndex={bracketMatch.teamBIndex}
seedNumber={
bracketMatch.teamBIndex
? seedNumberByTeamIndex.get(bracketMatch.teamBIndex)
: undefined
}
isWinner={bracketMatch.winnerTeamIndex === bracketMatch.teamBIndex}
isLoser={
bracketMatch.state === "completed" &&
bracketMatch.teamBIndex !== bracketMatch.winnerTeamIndex
}
score={resolveDoubleEliminationTeamScore(
seriesResult,
bracketMatch.teamBIndex,
)}
/>
<div className="mt-auto flex min-w-0 items-center justify-between gap-1">
<div className="flex min-w-0 items-center gap-1">
<span className="truncate text-[10px] font-bold text-base-content/30">
{DOUBLE_ELIMINATION_BRACKET_SIDE_LABEL[
bracketMatch.bracketSide
] ?? bracketMatch.bracketSide}
</span>
{codeStateLabel && (
<span className="shrink-0 border border-base-content/10 px-1 text-[10px] font-bold text-base-content/45">
{codeStateLabel}
</span>
)}
{completionTypeLabel && (
<span className="shrink-0 border border-accent/25 bg-accent/10 px-1 text-[10px] font-black text-accent">
{completionTypeLabel}
</span>
)}
</div>
{canManage && (
<DoubleEliminationBracketCardActions
bracketMatch={bracketMatch}
canApplyWalkover={canApplyWalkover}
busy={busy}
onWalkover={onWalkover}
onCancelWalkover={onCancelWalkover}
onCancelResult={onCancelResult}
/>
)}
</div>
</div>
</div>
);
}
function resolveDoubleEliminationTeamScore(
seriesResult: DoubleEliminationSeriesResult | undefined,
teamIndex: number | undefined,
) {
if (!seriesResult || !teamIndex) return undefined;
if (teamIndex === seriesResult.teamAIndex) return seriesResult.teamAWins;
if (teamIndex === seriesResult.teamBIndex) return seriesResult.teamBWins;
return undefined;
}
function DoubleEliminationBracketTeamRow({
match,
teamIndex,
seedNumber,
isWinner,
isLoser,
score,
}: {
match: MatchDetailView;
teamIndex?: number;
seedNumber?: number;
isWinner: boolean;
isLoser: boolean;
score?: number;
}) {
const teamName = teamIndex ? resolveMatchTeamName(match, teamIndex) : "미정";
const teamTone = teamIndex ? teamIndexColorClasses(teamIndex) : null;
return (
<div
className={`grid h-7 grid-cols-[2.25rem_minmax(0,1fr)_1.25rem] items-center gap-1 border px-1.5 text-xs ${
isWinner
? "border-primary/30 bg-primary/5 text-base-content"
: isLoser
? "border-base-content/8 bg-base-200/50 text-base-content/35"
: teamIndex
? "border-info/20 bg-info/5 text-base-content/75"
: "border-base-content/8 bg-base-200/40 text-base-content/35"
}`}
>
<span className="flex min-w-0 items-center gap-1">
<span
className={`h-1.5 w-1.5 shrink-0 ${
teamTone?.bar ?? "bg-base-content/20"
}`}
/>
<span className="font-mono text-[10px] font-black text-base-content/45">
{seedNumber ? `S${seedNumber}` : teamIndex ? `T${teamIndex}` : "-"}
</span>
</span>
<span className="min-w-0 truncate font-bold leading-none">
{teamName}
</span>
<span
className={`text-right font-mono text-[11px] font-black ${
isWinner ? "text-primary" : "text-base-content/45"
}`}
>
{score ?? ""}
</span>
</div>
);
}
function DoubleEliminationBracketCardActions({
bracketMatch,
canApplyWalkover,
busy,
onWalkover,
onCancelWalkover,
onCancelResult,
}: {
bracketMatch: ApiDoubleEliminationBracketMatch;
canApplyWalkover: boolean;
busy: boolean;
onWalkover: (bracketMatchId: string, winnerTeamIndex: number) => void;
onCancelWalkover: (bracketMatchId: string) => void;
onCancelResult: (bracketMatchId: string) => void;
}) {
return (
<div className="flex shrink-0 items-center gap-1">
{canApplyWalkover && bracketMatch.teamAIndex && (
<button
type="button"
className="border border-base-content/10 px-1 text-[10px] font-bold text-base-content/45 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-40"
disabled={busy}
onClick={() =>
onWalkover(
bracketMatch.bracketMatchId,
bracketMatch.teamAIndex as number,
)
}
>
A 부전승
</button>
)}
{canApplyWalkover && bracketMatch.teamBIndex && (
<button
type="button"
className="border border-base-content/10 px-1 text-[10px] font-bold text-base-content/45 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-40"
disabled={busy}
onClick={() =>
onWalkover(
bracketMatch.bracketMatchId,
bracketMatch.teamBIndex as number,
)
}
>
B 부전승
</button>
)}
{bracketMatch.completedBy === "walkover" &&
bracketMatch.walkover?.active && (
<button
type="button"
className="border border-amber-400/25 px-1 text-[10px] font-bold text-amber-300 hover:bg-amber-400/10 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-300 disabled:cursor-not-allowed disabled:opacity-40"
disabled={busy}
onClick={() => onCancelWalkover(bracketMatch.bracketMatchId)}
>
취소
</button>
)}
{bracketMatch.completedBy === "riot-result" && (
<button
type="button"
className="border border-red-400/25 px-1 text-[10px] font-bold text-red-300 hover:bg-red-400/10 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-300 disabled:cursor-not-allowed disabled:opacity-40"
disabled={busy}
onClick={() => onCancelResult(bracketMatch.bracketMatchId)}
>
결과 취소
</button>
)}
</div>
);
}
function TeamNameChip({
match,
teamIndex,
@@ -2419,6 +3198,15 @@ export default function MatchDetailPage() {
useCollectTournamentResultByWindow(DEFAULT_COMMUNITY_ID);
const collectResultByRiotMatchMutation =
useCollectTournamentResultByRiotMatch(DEFAULT_COMMUNITY_ID);
const reshuffleSeedsMutation =
useReshuffleDoubleEliminationSeeds(DEFAULT_COMMUNITY_ID);
const swapSeedsMutation = useSwapDoubleEliminationSeeds(DEFAULT_COMMUNITY_ID);
const applyWalkoverMutation =
useApplyDoubleEliminationWalkover(DEFAULT_COMMUNITY_ID);
const cancelWalkoverMutation =
useCancelDoubleEliminationWalkover(DEFAULT_COMMUNITY_ID);
const cancelRiotResultMutation =
useCancelDoubleEliminationRiotResult(DEFAULT_COMMUNITY_ID);
const joinMatchMutation = useMutation({
mutationFn: () =>
@@ -2663,6 +3451,56 @@ export default function MatchDetailPage() {
);
}
function handleReshuffleDoubleEliminationSeeds() {
if (!id) return;
if (!window.confirm("시드를 다시 추첨할까요?")) return;
reshuffleSeedsMutation.mutate(id, { onSuccess: invalidateCurrentMatch });
}
function handleSwapDoubleEliminationSeeds() {
if (!id) return;
const leftSeedNumber = Number(window.prompt("교체할 첫 번째 시드 번호"));
const rightSeedNumber = Number(window.prompt("교체할 두 번째 시드 번호"));
if (!Number.isInteger(leftSeedNumber) || !Number.isInteger(rightSeedNumber)) {
return;
}
swapSeedsMutation.mutate(
{ matchId: id, leftSeedNumber, rightSeedNumber },
{ onSuccess: invalidateCurrentMatch },
);
}
function handleApplyDoubleEliminationWalkover(
bracketMatchId: string,
winnerTeamIndex: number,
) {
if (!id) return;
const reason = window.prompt("부전승 사유") ?? undefined;
applyWalkoverMutation.mutate(
{ matchId: id, bracketMatchId, winnerTeamIndex, reason },
{ onSuccess: invalidateCurrentMatch },
);
}
function handleCancelDoubleEliminationWalkover(bracketMatchId: string) {
if (!id) return;
const reason = window.prompt("부전승 취소 사유") ?? undefined;
cancelWalkoverMutation.mutate(
{ matchId: id, bracketMatchId, reason },
{ onSuccess: invalidateCurrentMatch },
);
}
function handleCancelDoubleEliminationRiotResult(bracketMatchId: string) {
if (!id) return;
if (!window.confirm("이 대진의 수집 결과를 취소할까요?")) return;
const reason = window.prompt("결과 취소 사유") ?? undefined;
cancelRiotResultMutation.mutate(
{ matchId: id, bracketMatchId, reason },
{ onSuccess: invalidateCurrentMatch },
);
}
useEffect(() => {
const participants = buildAuctionParticipantPool(
matchQuery.data?.participants ?? [],
@@ -2802,6 +3640,18 @@ export default function MatchDetailPage() {
hasUniqueCaptainSelections &&
hasValidCaptainInitialPoints &&
hasValidAuctionTimerSettings;
const doubleEliminationActionBusy =
reshuffleSeedsMutation.isPending ||
swapSeedsMutation.isPending ||
applyWalkoverMutation.isPending ||
cancelWalkoverMutation.isPending ||
cancelRiotResultMutation.isPending;
const doubleEliminationActionError =
reshuffleSeedsMutation.error ||
swapSeedsMutation.error ||
applyWalkoverMutation.error ||
cancelWalkoverMutation.error ||
cancelRiotResultMutation.error;
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
@@ -2897,6 +3747,23 @@ export default function MatchDetailPage() {
</div>
)}
{doubleEliminationActionError instanceof Error && (
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
{doubleEliminationActionError.message}
</div>
)}
<DoubleEliminationBracketSection
match={match}
canManage={canManageAuction}
busy={doubleEliminationActionBusy}
onReshuffleSeeds={handleReshuffleDoubleEliminationSeeds}
onSwapSeeds={handleSwapDoubleEliminationSeeds}
onWalkover={handleApplyDoubleEliminationWalkover}
onCancelWalkover={handleCancelDoubleEliminationWalkover}
onCancelResult={handleCancelDoubleEliminationRiotResult}
/>
{match.status === "finished" ? (
<FinishedMatchTabs match={match} />
) : (
+5 -2
View File
@@ -28,6 +28,7 @@ const GAME_MODE_LABEL: Record<MatchGameMode, string> = {
pair: "페어 매치",
bracket: "토너먼트",
"round-robin": "리그전",
"double-elimination": "더블 엘리미네이션",
};
function resultBadgeClass(won: boolean) {
@@ -191,9 +192,11 @@ function UpcomingGameCard({
const opponentIndex =
slot.teamAIndex === parsedTeamIndex ? slot.teamBIndex : slot.teamAIndex;
const ourTeam = teamByIndex.get(parsedTeamIndex);
const opponentTeam = teamByIndex.get(opponentIndex);
const opponentTeam = opponentIndex ? teamByIndex.get(opponentIndex) : undefined;
const ourTeamName = teamIndexLabel(parsedTeamIndex, ourTeam?.name);
const opponentTeamName = teamIndexLabel(opponentIndex, opponentTeam?.name);
const opponentTeamName = opponentIndex
? teamIndexLabel(opponentIndex, opponentTeam?.name)
: "상대 미정";
const ourCaptainName = captainName(ourTeam, participantByUserId);
const opponentCaptainName = captainName(opponentTeam, participantByUserId);
const opponentMembers = opponentTeam?.members ?? [];
+58 -3
View File
@@ -24,6 +24,7 @@ const DEFAULT_FORM: MatchMutationRequest = {
maxParticipants: 10,
gameCount: 3,
gameMode: 'pair',
doubleEliminationResetFinalEnabled: true,
prizes: [],
notices: [],
schedule: [],
@@ -33,6 +34,7 @@ const GAME_MODE_LABEL: Record<MatchGameMode, string> = {
pair: '페어',
bracket: '브래킷',
'round-robin': '라운드 로빈',
'double-elimination': '더블 엘리미네이션',
};
function resolveRoundRobinFullRoundCount(maxParticipants?: number) {
@@ -122,6 +124,8 @@ function makeForm(match?: ApiMatch): MatchMutationRequest & {
gameCount: match.gameCount,
gameMode: match.gameMode ?? 'pair',
roundRobinMaxRounds: match.roundRobinMaxRounds,
doubleEliminationResetFinalEnabled:
match.doubleElimination?.resetFinalEnabled ?? true,
prizes: match.prizes,
notices: match.notices,
schedule: match.schedule,
@@ -188,6 +192,10 @@ export default function MatchAdminPage() {
maxParticipants: Number(form.maxParticipants ?? 10),
gameCount: Number(form.gameCount ?? 3),
gameMode: form.gameMode,
doubleEliminationResetFinalEnabled:
form.gameMode === 'double-elimination'
? Boolean(form.doubleEliminationResetFinalEnabled)
: undefined,
roundRobinMaxRounds:
form.gameMode === 'round-robin'
? normalizeRoundRobinMaxRounds(
@@ -329,7 +337,10 @@ export default function MatchAdminPage() {
}}
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
>
{[10, 20, 30, 40, 50, 60].map((value) => (
{(form.gameMode === 'double-elimination'
? [20, 40]
: [10, 20, 30, 40, 50, 60]
).map((value) => (
<option key={value} value={value}>{value}명</option>
))}
</select>
@@ -339,16 +350,36 @@ export default function MatchAdminPage() {
<input
type="number"
min={1}
value={form.gameCount}
disabled={form.gameMode === 'double-elimination'}
value={form.gameMode === 'double-elimination' ? 1 : form.gameCount}
onChange={(event) => setForm((current) => ({ ...current, gameCount: Number(event.target.value) }))}
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
/>
{form.gameMode === 'double-elimination' && (
<span className="mt-1 block text-xs text-base-content/30">
더블 엘리미네이션은 단판으로 진행됩니다.
</span>
)}
</label>
<label className="text-xs text-base-content/45">
게임 모드
<select
value={form.gameMode}
onChange={(event) => setForm((current) => ({ ...current, gameMode: event.target.value as MatchGameMode }))}
onChange={(event) => {
const gameMode = event.target.value as MatchGameMode;
setForm((current) => ({
...current,
gameMode,
maxParticipants:
gameMode === 'double-elimination' &&
current.maxParticipants !== 20 &&
current.maxParticipants !== 40
? 20
: current.maxParticipants,
gameCount:
gameMode === 'double-elimination' ? 1 : current.gameCount,
}));
}}
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
>
{Object.entries(GAME_MODE_LABEL).map(([value, label]) => (
@@ -385,6 +416,22 @@ export default function MatchAdminPage() {
</span>
</label>
)}
{form.gameMode === 'double-elimination' && (
<label className="flex items-center gap-2 border border-base-content/10 px-3 py-2 text-xs text-base-content/55">
<input
type="checkbox"
checked={Boolean(form.doubleEliminationResetFinalEnabled)}
onChange={(event) =>
setForm((current) => ({
...current,
doubleEliminationResetFinalEnabled:
event.target.checked,
}))
}
/>
그랜드 파이널 리셋 허용
</label>
)}
<label className="text-xs text-base-content/45">
상품 (줄바꿈 구분)
<textarea
@@ -474,6 +521,14 @@ export default function MatchAdminPage() {
최대 {match.roundRobinMaxRounds}R
</span>
)}
{match.gameMode === 'double-elimination' && (
<span className="block text-xs text-base-content/30">
GF 리셋{' '}
{match.doubleElimination?.resetFinalEnabled
? '허용'
: '없음'}
</span>
)}
</td>
<td className="px-3 py-2 text-right">
<div className="inline-flex gap-2">