feat: add limited round-robin scheduling

This commit is contained in:
dahyeon committed 2026-06-19 01:13:50 -07:00
1 parent 24983aeb09
commit 658592973e
15 files changed
+403 -63

No files matched your search

+4
View File
@@ -142,6 +142,7 @@ export type TournamentCodeSlotState = TournamentCodeState | 'pending';
export interface TournamentCodeSlotView {
gameNumber: number;
roundNumber?: number;
teamAIndex: number;
teamBIndex: number;
code: string | null;
@@ -219,6 +220,7 @@ export interface ApiMatchScheduleItem {
export interface ApiMatchGameAssignment {
gameNumber: number;
roundNumber?: number;
teamAIndex: number;
teamBIndex: number;
}
@@ -243,6 +245,7 @@ export interface ApiMatch {
maxParticipants: number;
gameCount: number;
gameMode: MatchGameMode;
roundRobinMaxRounds?: number;
gameSchedule?: ApiMatchGameAssignment[];
tournamentCodes?: TournamentCodeSlotView[];
hostUserId?: string;
@@ -371,6 +374,7 @@ export interface MatchMutationRequest {
maxParticipants?: number;
gameCount?: number;
gameMode?: MatchGameMode;
roundRobinMaxRounds?: number;
prizes?: string[];
notices?: string[];
schedule?: ApiMatchScheduleItem[];
+55 -20
View File
@@ -1467,28 +1467,63 @@ function TournamentCodeList({ slots }: { slots: TournamentCodeSlotView[] }) {
);
}
return (
<div className="space-y-2">
{slots.map((slot) => (
<div key={slot.gameNumber} className="flex items-start gap-2">
<span className="text-xs font-bold text-base-content/40 w-20 shrink-0 pt-1.5">
{slot.gameNumber}경기
{(slot.teamAIndex > 1 || slot.teamBIndex > 2) && (
<span className="block text-xs font-normal text-base-content/25">
{teamIndexLabel(slot.teamAIndex)} vs{" "}
{teamIndexLabel(slot.teamBIndex)}
</span>
)}
</span>
{slot.code ? (
<TournamentCodeDisplay slot={slot} />
) : (
<span className="text-xs text-base-content/30 border border-dashed border-base-content/10 px-2 py-2 flex-1">
발급 대기 중... 운영자가 코드를 채우면 자동으로 붙습니다.
function renderSlot(slot: TournamentCodeSlotView) {
return (
<div key={slot.gameNumber} className="flex items-start gap-2">
<span className="text-xs font-bold text-base-content/40 w-20 shrink-0 pt-1.5">
{slot.gameNumber}경기
{(slot.teamAIndex > 1 || slot.teamBIndex > 2) && (
<span className="block text-xs font-normal text-base-content/25">
{teamIndexLabel(slot.teamAIndex)} vs{" "}
{teamIndexLabel(slot.teamBIndex)}
</span>
)}
</div>
))}
</span>
{slot.code ? (
<TournamentCodeDisplay slot={slot} />
) : (
<span className="text-xs text-base-content/30 border border-dashed border-base-content/10 px-2 py-2 flex-1">
발급 대기 중... 운영자가 코드를 채우면 자동으로 붙습니다.
</span>
)}
</div>
);
}
if (slots.some((slot) => slot.roundNumber)) {
const slotsByRound = slots.reduce<
Map<number, TournamentCodeSlotView[]>
>((map, slot) => {
const roundNumber = slot.roundNumber ?? 0;
const roundSlots = map.get(roundNumber) ?? [];
roundSlots.push(slot);
map.set(roundNumber, roundSlots);
return map;
}, new Map());
return (
<div className="space-y-3">
{[...slotsByRound.entries()]
.sort(([left], [right]) => left - right)
.map(([roundNumber, roundSlots]) => (
<div key={roundNumber}>
<div className="mb-1 text-xs font-bold text-base-content/45">
{roundNumber}라운드
</div>
<div className="space-y-2">
{roundSlots
.sort((left, right) => left.gameNumber - right.gameNumber)
.map(renderSlot)}
</div>
</div>
))}
</div>
);
}
return (
<div className="space-y-2">
{slots.map(renderSlot)}
</div>
);
}
+69 -1
View File
@@ -35,6 +35,21 @@ const GAME_MODE_LABEL: Record<MatchGameMode, string> = {
'round-robin': '라운드 로빈',
};
function resolveRoundRobinFullRoundCount(maxParticipants?: number) {
const teamCount = Math.floor(Number(maxParticipants ?? 10) / 5);
if (teamCount < 2) return 0;
return teamCount % 2 === 0 ? teamCount - 1 : teamCount;
}
function normalizeRoundRobinMaxRounds(
value: number | undefined,
maxParticipants?: number,
) {
if (!value || !Number.isFinite(value)) return undefined;
const fullRoundCount = resolveRoundRobinFullRoundCount(maxParticipants);
return Math.max(1, Math.min(fullRoundCount, Math.floor(value)));
}
function RequiredBadge() {
return (
<span className="ml-1 inline-flex items-center border border-primary/20 bg-primary/5 px-1.5 py-0.5 text-xs font-bold text-primary">
@@ -106,6 +121,7 @@ function makeForm(match?: ApiMatch): MatchMutationRequest & {
maxParticipants: match.maxParticipants,
gameCount: match.gameCount,
gameMode: match.gameMode ?? 'pair',
roundRobinMaxRounds: match.roundRobinMaxRounds,
prizes: match.prizes,
notices: match.notices,
schedule: match.schedule,
@@ -138,6 +154,9 @@ export default function MatchAdminPage() {
() => [...(matchesQuery.data ?? [])].sort((a, b) => new Date(b.scheduledAt).getTime() - new Date(a.scheduledAt).getTime()),
[matchesQuery.data],
);
const roundRobinFullRoundCount = resolveRoundRobinFullRoundCount(
form.maxParticipants,
);
async function invalidate() {
await Promise.all([
@@ -169,6 +188,13 @@ export default function MatchAdminPage() {
maxParticipants: Number(form.maxParticipants ?? 10),
gameCount: Number(form.gameCount ?? 3),
gameMode: form.gameMode,
roundRobinMaxRounds:
form.gameMode === 'round-robin'
? normalizeRoundRobinMaxRounds(
form.roundRobinMaxRounds,
form.maxParticipants,
)
: undefined,
prizes: parseLines(form.prizesText),
notices: parseLines(form.noticesText),
schedule: parseSchedule(form.scheduleText),
@@ -290,7 +316,17 @@ export default function MatchAdminPage() {
정원
<select
value={form.maxParticipants}
onChange={(event) => setForm((current) => ({ ...current, maxParticipants: Number(event.target.value) }))}
onChange={(event) => {
const maxParticipants = Number(event.target.value);
setForm((current) => ({
...current,
maxParticipants,
roundRobinMaxRounds: normalizeRoundRobinMaxRounds(
current.roundRobinMaxRounds,
maxParticipants,
),
}));
}}
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) => (
@@ -323,6 +359,32 @@ export default function MatchAdminPage() {
현재 경매/코드 연결은 페어 방식 기준으로 동작합니다.
</span>
</label>
{form.gameMode === 'round-robin' && (
<label className="text-xs text-base-content/45">
최대 라운드 수
<span className="ml-1 text-xs text-base-content/25">선택</span>
<input
type="number"
min={1}
max={roundRobinFullRoundCount || undefined}
placeholder="예: 3"
value={form.roundRobinMaxRounds ?? ''}
onChange={(event) =>
setForm((current) => ({
...current,
roundRobinMaxRounds:
event.target.value === ''
? undefined
: Number(event.target.value),
}))
}
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
/>
<span className="mt-1 block text-xs text-base-content/30">
비워두면 전체 {roundRobinFullRoundCount}라운드로 생성됩니다.
</span>
</label>
)}
<label className="text-xs text-base-content/45">
상품 (줄바꿈 구분)
<textarea
@@ -406,6 +468,12 @@ export default function MatchAdminPage() {
</td>
<td className="px-3 py-2 text-xs">
{GAME_MODE_LABEL[match.gameMode ?? 'pair']}
{match.gameMode === 'round-robin' &&
match.roundRobinMaxRounds && (
<span className="block text-xs text-base-content/30">
최대 {match.roundRobinMaxRounds}R
</span>
)}
</td>
<td className="px-3 py-2 text-right">
<div className="inline-flex gap-2">