feat: auto provision tournament codes

This commit is contained in:
dahyeon committed 2026-06-20 02:29:30 -07:00
1 parent 65bc214fb2
commit bac29ac933
13 files changed
+1164 -117

No files matched your search

+28 -14
View File
@@ -36,6 +36,9 @@ export interface TeamParticipantView extends ParticipantView {
export interface TeamView {
teamIndex: number;
name: string;
captainUserId?: string;
captainName?: string;
captainTag?: string;
participants: TeamParticipantView[];
}
@@ -413,21 +416,32 @@ export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
participants.map((participant) => [participant.userId, participant]),
);
const teams = match.teams.map((team) => ({
teamIndex: team.teamIndex,
name: teamIndexLabel(team.teamIndex, team.name),
participants: team.members.map((member) => {
const participant =
participantLookup.get(member.userId) ??
createFallbackParticipant(member.userId);
const teams = match.teams.map((team) => {
const captain = team.captainUserId
? participantLookup.get(team.captainUserId)
: undefined;
return {
...participant,
assignedPosition: member.assignedPosition,
cost: member.cost,
};
}),
}));
return {
teamIndex: team.teamIndex,
name: teamIndexLabel(team.teamIndex, team.name),
captainUserId: team.captainUserId,
captainName:
captain?.summonerName ??
(team.captainUserId ? `User ${team.captainUserId.slice(-4)}` : undefined),
captainTag: captain?.tag,
participants: team.members.map((member) => {
const participant =
participantLookup.get(member.userId) ??
createFallbackParticipant(member.userId);
return {
...participant,
assignedPosition: member.assignedPosition,
cost: member.cost,
};
}),
};
});
const winnerTeam = match.result?.winnerTeamIndex
? teams.find((team) => team.teamIndex === match.result?.winnerTeamIndex)
+331 -96
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, Search, X } from "lucide-react";
import { AlertTriangle, ChevronRight, Search, X } from "lucide-react";
import { Link, useLocation, useNavigate, useParams } from "react-router";
import {
useAuction,
@@ -29,7 +29,6 @@ import { profileIconUrl } from "../lib/ddragon";
import {
POSITION_ORDER,
positionLabel,
sideShortLabel,
teamIndexColorClasses,
teamIndexLabel,
} from "../lib/league";
@@ -44,7 +43,6 @@ import type {
ManualTournamentResultCollectResponse,
MatchGameMode,
Position,
TeamSide,
TournamentCodeSlotView,
} from "../api/types";
@@ -1311,21 +1309,33 @@ function TeamCard({
<div
className={`${tone.bg} px-4 py-2 flex items-center justify-between border-b ${tone.border}`}
>
<div className="flex items-center gap-2">
<span
className={`text-xs font-bold uppercase tracking-wide ${tone.text}`}
>
{team.name}
</span>
{isWinner && (
<span className="inline-flex items-center text-xs font-bold px-1.5 py-0.5 bg-accent/15 text-amber-400 border border-accent/20">
WIN
<div className="min-w-0">
<div className="flex items-center gap-2">
<span
className={`text-xs font-bold uppercase tracking-wide ${tone.text}`}
>
{team.name}
</span>
{isWinner && (
<span className="inline-flex items-center text-xs font-bold px-1.5 py-0.5 bg-accent/15 text-amber-400 border border-accent/20">
WIN
</span>
)}
</div>
{team.captainName && (
<div className="mt-0.5 truncate text-xs text-base-content/35">
팀장 {team.captainName}
{team.captainTag ? (
<span className="ml-1 text-base-content/20">
#{team.captainTag}
</span>
) : null}
</div>
)}
</div>
<Link
to={`/match/${matchId}/team/${team.teamIndex}`}
className="text-xs font-bold text-base-content/35 hover:text-primary"
className="shrink-0 text-xs font-bold text-base-content/35 hover:text-primary"
>
진행 페이지
</Link>
@@ -1621,28 +1631,64 @@ function PoolStatsHint({ enabled }: { enabled: boolean }) {
);
}
function formatGameDuration(seconds: number) {
const minutes = Math.floor(seconds / 60);
const rest = seconds % 60;
return `${minutes}:${String(rest).padStart(2, "0")}`;
const KST_GAME_START_FORMATTER = new Intl.DateTimeFormat("ko-KR", {
timeZone: "Asia/Seoul",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "2-digit",
hour12: true,
});
function formatGameStartKst(timestamp: number) {
const date = new Date(timestamp);
if (Number.isNaN(date.getTime())) return "-";
const parts = KST_GAME_START_FORMATTER.formatToParts(date);
const value = (type: Intl.DateTimeFormatPartTypes) =>
parts.find((part) => part.type === type)?.value ?? "";
const month = value("month");
const day = value("day");
const dayPeriod = value("dayPeriod");
const hour = value("hour");
const minute = value("minute");
return `${month}/${day} ${dayPeriod} ${hour}:${minute}`.trim();
}
function resultSideClass(side: "blue" | "red") {
return side === "blue" ? "text-blue-400" : "text-red-400";
}
function resultSideLabel(side: TeamSide) {
return sideShortLabel(side);
function resolveMatchTeam(match: MatchDetailView, teamIndex: number) {
return match.teams.find((item) => item.teamIndex === teamIndex);
}
function resolveMatchTeamName(match: MatchDetailView, teamIndex: number) {
const team = match.teams.find((item) => item.teamIndex === teamIndex);
const team = resolveMatchTeam(match, teamIndex);
return teamIndexLabel(teamIndex, team?.name);
}
function resolveMatchCaptainName(match: MatchDetailView, teamIndex: number) {
return resolveMatchTeam(match, teamIndex)?.captainName ?? "팀장 미지정";
}
function getMatchResultGameCapacity(match: MatchDetailView) {
return Math.max(
match.gameCount,
match.tournamentCodes.length,
...(match.result?.games.map((game) => game.gameNumber) ?? []),
);
}
type RoundRobinStandingResult = {
gameNumber: number;
opponentTeamIndex: number;
opponentName: string;
won: boolean;
};
type RoundRobinStanding = {
teamIndex: number;
name: string;
captainName?: string;
captainTag?: string;
seriesWins: number;
seriesLosses: number;
gameWins: number;
@@ -1653,6 +1699,7 @@ type RoundRobinStanding = {
assists: number;
kdaScore: number;
winRate: number;
matchResults: RoundRobinStandingResult[];
};
function formatRecordRate(value: number) {
@@ -1661,7 +1708,12 @@ function formatRecordRate(value: number) {
}
function formatSignedNumber(value: number) {
return String(value);
return value > 0 ? `+${value}` : String(value);
}
function formatWinRate(value: number) {
if (!Number.isFinite(value)) return "-";
return `${Math.round(value * 100)}%`;
}
function formatKda(standing: RoundRobinStanding) {
@@ -1679,10 +1731,13 @@ function buildRoundRobinStandings(
const getStanding = (teamIndex: number) => {
const existing = standings.get(teamIndex);
if (existing) return existing;
const team = resolveMatchTeam(match, teamIndex);
const standing: RoundRobinStanding = {
teamIndex,
name: resolveMatchTeamName(match, teamIndex),
captainName: team?.captainName,
captainTag: team?.captainTag,
seriesWins: 0,
seriesLosses: 0,
gameWins: 0,
@@ -1693,6 +1748,7 @@ function buildRoundRobinStandings(
assists: 0,
kdaScore: 0,
winRate: 0,
matchResults: [],
};
standings.set(teamIndex, standing);
return standing;
@@ -1730,6 +1786,21 @@ function buildRoundRobinStandings(
});
match.result?.games.forEach((game) => {
const blueTeam = getStanding(game.blueTeamIndex);
const redTeam = getStanding(game.redTeamIndex);
blueTeam.matchResults.push({
gameNumber: game.gameNumber,
opponentTeamIndex: game.redTeamIndex,
opponentName: redTeam.name,
won: game.winnerTeamIndex === game.blueTeamIndex,
});
redTeam.matchResults.push({
gameNumber: game.gameNumber,
opponentTeamIndex: game.blueTeamIndex,
opponentName: blueTeam.name,
won: game.winnerTeamIndex === game.redTeamIndex,
});
game.participants.forEach((participant) => {
const standing = getStanding(participant.teamIndex);
standing.kills += participant.kills;
@@ -1746,6 +1817,9 @@ function buildRoundRobinStandings(
standing.deaths > 0
? (standing.kills + standing.assists) / standing.deaths
: standing.kills + standing.assists;
standing.matchResults.sort(
(left, right) => left.gameNumber - right.gameNumber,
);
});
return [...standings.values()].sort((left, right) => {
@@ -1771,6 +1845,45 @@ function buildRoundRobinStandings(
});
}
function StandingResultChips({
results,
limit = 4,
}: {
results: RoundRobinStandingResult[];
limit?: number;
}) {
if (results.length === 0) {
return <span className="text-xs text-base-content/25">경기 없음</span>;
}
const visibleResults = results.slice(0, limit);
const hiddenCount = Math.max(0, results.length - visibleResults.length);
return (
<div className="flex min-w-0 flex-wrap gap-1.5">
{visibleResults.map((result) => (
<span
key={`${result.gameNumber}-${result.opponentTeamIndex}`}
className={`inline-flex items-center gap-1 border px-1.5 py-0.5 text-[11px] font-semibold ${
result.won
? "border-primary/20 bg-primary/5 text-primary"
: "border-base-content/10 bg-base-200/35 text-base-content/45"
}`}
>
<span className="font-black">{result.won ? "W" : "L"}</span>
<span className="text-base-content/35">vs</span>
<span className="max-w-16 truncate">{result.opponentName}</span>
</span>
))}
{hiddenCount > 0 && (
<span className="inline-flex items-center border border-base-content/8 px-1.5 py-0.5 text-[11px] font-semibold text-base-content/35">
+{hiddenCount}
</span>
)}
</div>
);
}
function RoundRobinStandingsTable({ match }: { match: MatchDetailView }) {
const standings = buildRoundRobinStandings(match);
@@ -1796,21 +1909,108 @@ function RoundRobinStandingsTable({ match }: { match: MatchDetailView }) {
</div>
)}
</div>
<div className="mt-4 overflow-x-auto border border-base-content/8">
<table className="min-w-[760px] w-full text-xs">
<div className="mt-4 space-y-3 md:hidden">
{standings.map((standing, index) => {
const tone = teamIndexColorClasses(standing.teamIndex);
const isWinner = match.result?.winnerTeamIndex === standing.teamIndex;
return (
<div
key={standing.teamIndex}
className={`relative border bg-base-100 p-3 ${
isWinner ? "border-primary/25" : "border-base-content/8"
}`}
>
<span
className={`absolute left-0 top-0 h-full w-0.5 ${tone.bar}`}
aria-hidden="true"
/>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<div className="flex items-center gap-2">
<span className="inline-flex h-7 w-7 items-center justify-center bg-base-200 text-sm font-black text-base-content">
{index + 1}
</span>
<div className="min-w-0">
<div className="truncate text-sm font-black text-base-content">
{standing.name}
</div>
<div className="truncate text-xs text-base-content/35">
팀장 {standing.captainName ?? "미지정"}
{standing.captainTag ? (
<span className="ml-1 text-base-content/20">
#{standing.captainTag}
</span>
) : null}
</div>
</div>
</div>
</div>
{isWinner && (
<span className="shrink-0 border border-primary/20 bg-primary/5 px-1.5 py-0.5 text-[11px] font-bold text-primary">
1위
</span>
)}
</div>
<div className="mt-3 grid grid-cols-4 gap-2 text-center text-xs">
<div className="bg-base-200/35 px-2 py-2">
<div className="text-base-content/30">전적</div>
<div className="mt-0.5 font-black text-base-content">
{standing.seriesWins}승 {standing.seriesLosses}패
</div>
</div>
<div className="bg-base-200/35 px-2 py-2">
<div className="text-base-content/30">세트</div>
<div className="mt-0.5 font-bold tabular-nums text-base-content/75">
{standing.gameWins}-{standing.gameLosses}
</div>
</div>
<div className="bg-base-200/35 px-2 py-2">
<div className="text-base-content/30">득실</div>
<div className="mt-0.5 font-bold tabular-nums text-base-content/75">
{formatSignedNumber(standing.gameDiff)}
</div>
</div>
<div className="bg-base-200/35 px-2 py-2">
<div className="text-base-content/30">승률</div>
<div className="mt-0.5 font-bold tabular-nums text-base-content/75">
{formatWinRate(standing.winRate)}
</div>
</div>
</div>
<div className="mt-3">
<div className="mb-1 text-xs font-bold text-base-content/35">
경기 흐름
</div>
<StandingResultChips results={standing.matchResults} limit={5} />
</div>
<div className="mt-3 flex items-center justify-between border-t border-base-content/8 pt-2 text-xs">
<span className="text-base-content/35">K/D/A</span>
<span className="font-mono text-base-content/70">
{standing.kills} / {standing.deaths} / {standing.assists}
</span>
<span className="font-mono font-bold text-base-content/70">
KDA {formatKda(standing)}
</span>
</div>
</div>
);
})}
</div>
<div className="mt-4 hidden overflow-x-auto border border-base-content/8 md:block">
<table className="min-w-[920px] w-full text-xs">
<thead className="bg-base-100 text-xs text-base-content/45">
<tr className="border-b border-base-content/8">
<th className="h-9 px-3 text-left font-semibold">팀 순위</th>
<th className="h-9 px-3 text-left font-semibold">팀 / 팀장</th>
<th className="h-9 px-3 text-center font-semibold bg-primary/5 text-primary">
승
전적
</th>
<th className="h-9 px-3 text-center font-semibold">패</th>
<th className="h-9 px-3 text-center font-semibold">득실차</th>
<th className="h-9 px-3 text-center font-semibold">세트</th>
<th className="h-9 px-3 text-center font-semibold">득실</th>
<th className="h-9 px-3 text-center font-semibold">승률</th>
<th className="h-9 px-3 text-left font-semibold">경기 흐름</th>
<th className="h-9 px-3 text-center font-semibold">K/D/A</th>
<th className="h-9 px-3 text-center font-semibold">KDA</th>
<th className="h-9 px-3 text-center font-semibold">킬</th>
<th className="h-9 px-3 text-center font-semibold">데스</th>
<th className="h-9 px-3 text-center font-semibold">어시스트</th>
</tr>
</thead>
<tbody className="divide-y divide-base-content/8 bg-base-100/60">
@@ -1833,35 +2033,49 @@ function RoundRobinStandingsTable({ match }: { match: MatchDetailView }) {
className={`h-6 w-1 shrink-0 ${tone.bar}`}
aria-hidden="true"
/>
<span className="min-w-0 truncate font-semibold text-base-content/85">
{standing.name}
</span>
<div className="min-w-0">
<div className="flex min-w-0 items-center gap-2">
<span className="min-w-0 truncate font-semibold text-base-content/85">
{standing.name}
</span>
{isWinner && (
<span className="shrink-0 border border-primary/20 bg-primary/5 px-1 py-0.5 text-[10px] font-bold text-primary">
1위
</span>
)}
</div>
<div className="mt-0.5 truncate text-xs text-base-content/35">
팀장 {standing.captainName ?? "미지정"}
{standing.captainTag ? (
<span className="ml-1 text-base-content/20">
#{standing.captainTag}
</span>
) : null}
</div>
</div>
</div>
</td>
<td className="h-14 px-3 text-center font-black tabular-nums bg-primary/5 text-primary">
{standing.seriesWins}
{standing.seriesWins}승 {standing.seriesLosses}패
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{standing.seriesLosses}
{standing.gameWins}-{standing.gameLosses}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{formatSignedNumber(standing.gameDiff)}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{formatRecordRate(standing.winRate)}
{formatWinRate(standing.winRate)}
</td>
<td className="h-14 px-3 text-left">
<StandingResultChips results={standing.matchResults} />
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{standing.kills} / {standing.deaths} / {standing.assists}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{formatKda(standing)}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{standing.kills}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{standing.deaths}
</td>
<td className="h-14 px-3 text-center tabular-nums text-base-content/70">
{standing.assists}
</td>
</tr>
);
})}
@@ -1875,11 +2089,7 @@ function RoundRobinStandingsTable({ match }: { match: MatchDetailView }) {
function MatchStandingsSection({ match }: { match: MatchDetailView }) {
if (!match.result) return null;
const maxGameNumber = Math.max(
match.gameCount,
match.tournamentCodes.length,
...match.result.games.map((game) => game.gameNumber),
);
const maxGameNumber = getMatchResultGameCapacity(match);
const seriesResults = match.result.seriesResults ?? [];
const primarySeries = seriesResults[0];
const showRoundRobinStandings =
@@ -1957,56 +2167,62 @@ function MatchGameListSection({ match }: { match: MatchDetailView }) {
const gamesByNumber = new Map(
match.result.games.map((game) => [game.gameNumber, game]),
);
const maxGameNumber = Math.max(
match.gameCount,
match.tournamentCodes.length,
...match.result.games.map((game) => game.gameNumber),
);
const maxGameNumber = getMatchResultGameCapacity(match);
const gameNumbers = Array.from(
{ length: maxGameNumber },
(_, index) => index + 1,
);
return (
<div className="border border-base-content/8 divide-y divide-base-content/8">
<div className="border border-base-content/8 divide-y divide-base-content/8 bg-base-100">
{gameNumbers.map((gameNumber) => {
const game = gamesByNumber.get(gameNumber);
const rowClass =
"grid grid-cols-[56px_1fr_auto] gap-3 items-center px-3 py-2.5 text-xs";
"grid grid-cols-[52px_minmax(0,1fr)_auto] gap-3 px-3 py-3 text-sm";
const content = (
<>
<span className="text-base-content/35 font-bold">
<span className="pt-0.5 text-xs font-bold text-base-content/35">
{gameNumber}경기
</span>
{game ? (
<div className="min-w-0">
<span
className={`font-black ${resultSideClass(game.winnerSide)}`}
>
{resolveMatchTeamName(match, game.winnerTeamIndex)} 승
</span>
<span className="ml-1 text-base-content/35">
({resultSideLabel(game.winnerSide)} 진영)
</span>
<span className="ml-2 text-base-content/35 font-mono">
{game.riotMatchId}
</span>
<div className="min-w-0 space-y-1">
<div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
<TeamNameChip match={match} teamIndex={game.blueTeamIndex} />
<span className="text-[10px] font-black text-base-content/25">
VS
</span>
<TeamNameChip match={match} teamIndex={game.redTeamIndex} />
<span className="inline-flex items-center border border-amber-500/20 bg-amber-500/8 px-1.5 py-0.5 text-[11px] font-bold text-amber-500">
{resolveMatchTeamName(match, game.winnerTeamIndex)} 승
</span>
</div>
<div className="flex min-w-0 flex-wrap gap-x-3 gap-y-1 text-xs text-base-content/35">
<span className="min-w-0 truncate">
팀장 {resolveMatchCaptainName(match, game.blueTeamIndex)} vs{" "}
{resolveMatchCaptainName(match, game.redTeamIndex)}
</span>
<span className="font-mono text-[11px] text-base-content/25">
{game.riotMatchId}
</span>
</div>
</div>
) : (
<span className="text-base-content/25">대기 중</span>
<div className="min-w-0 text-base-content/30">대기 중</div>
)}
{game ? (
<span className="flex shrink-0 items-center justify-end gap-3 pt-0.5">
<span className="whitespace-nowrap text-right text-xs font-medium text-base-content/45">
{formatGameStartKst(game.gameCreation)}
</span>
<span className="inline-flex h-7 w-7 items-center justify-center text-primary/70 transition-colors group-hover:text-primary">
<ChevronRight className="h-4 w-4 transition-transform group-hover:translate-x-0.5" />
</span>
</span>
) : (
<span className="shrink-0 pt-0.5 text-right text-xs text-base-content/25">
-
</span>
)}
<span className="text-right text-base-content/35 font-mono">
{game ? (
<>
{formatGameDuration(game.gameDuration)}
<span className="ml-2 font-sans font-bold text-primary opacity-0 transition-opacity group-hover:opacity-100">
상세
</span>
</>
) : (
"-"
)}
</span>
</>
);
@@ -2015,8 +2231,8 @@ function MatchGameListSection({ match }: { match: MatchDetailView }) {
<Link
key={gameNumber}
to={`/match/${match.id}/game/${gameNumber}`}
className={`${rowClass} group transition-colors hover:bg-primary/5`}
aria-label={`${gameNumber}경기 상세 보기`}
className={`${rowClass} group transition-colors hover:bg-primary/5 focus-visible:bg-primary/8 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`}
aria-label={`${gameNumber}경기 ${resolveMatchTeamName(match, game.blueTeamIndex)} 대 ${resolveMatchTeamName(match, game.redTeamIndex)} 상세 보기`}
>
{content}
</Link>
@@ -2033,14 +2249,33 @@ function MatchGameListSection({ match }: { match: MatchDetailView }) {
);
}
function TeamNameChip({
match,
teamIndex,
}: {
match: MatchDetailView;
teamIndex: number;
}) {
const tone = teamIndexColorClasses(teamIndex);
return (
<span className="inline-flex min-w-0 items-center gap-1.5 font-semibold text-base-content/75">
<span className={`h-1.5 w-1.5 shrink-0 rounded-full ${tone.bar}`} />
<span className="truncate">{resolveMatchTeamName(match, teamIndex)}</span>
</span>
);
}
function MatchResultPanel({ match }: { match: MatchDetailView }) {
if (!match.result) return null;
return (
<div className="mb-6 border border-base-content/10 bg-base-content/[0.02] p-5">
<MatchStandingsSection match={match} />
<div className="mt-5">
<MatchGameListSection match={match} />
<div className="mb-6 space-y-4">
<div className="border border-base-content/10 bg-base-content/[0.02] p-5">
<MatchStandingsSection match={match} />
<div className="mt-5">
<MatchGameListSection match={match} />
</div>
</div>
</div>
);
@@ -2070,10 +2305,10 @@ function FinishedMatchTabs({ match }: { match: MatchDetailView }) {
key={item.id}
type="button"
onClick={() => setResultTab(item.id)}
className={`min-w-[7.5rem] border-r border-base-content/8 px-4 py-3 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
className={`min-w-[7.5rem] border-r border-b-2 border-base-content/8 px-4 py-3 text-xs font-bold transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
activeTab === item.id
? "bg-primary text-primary-content"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
? "border-b-primary bg-base-200/50 text-base-content"
: "border-b-transparent text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{item.label}