refactor: cut web results over to competition projections
This commit is contained in:
1 parent
7db97c540b
commit
6bddb666fc
13 files changed
+2153
-3885
No files matched your search
@@ -0,0 +1,763 @@
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import type {
|
||||
CompetitionCommandResponse,
|
||||
CompetitionDetailResponse,
|
||||
SeriesAdjudicationDecision,
|
||||
SeriesProjection,
|
||||
SeriesReversalMode,
|
||||
SeriesReversalPreviewResponse,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import {
|
||||
useAdjudicateCompetitionSeries,
|
||||
usePreviewCompetitionSeriesReversal,
|
||||
useReverseCompetitionSeries,
|
||||
} from "../../api/hooks";
|
||||
import { ApiError } from "../../lib/api";
|
||||
|
||||
type AdjudicationType = SeriesAdjudicationDecision["type"];
|
||||
|
||||
const ADJUDICATION_LABELS: Record<AdjudicationType, string> = {
|
||||
walkover: "부전승",
|
||||
forfeit: "몰수패",
|
||||
administrative: "운영자 판정",
|
||||
"administrative-draw": "운영자 무승부",
|
||||
};
|
||||
|
||||
export function CompetitionAdminControls({
|
||||
competition,
|
||||
communityId,
|
||||
canManage,
|
||||
}: {
|
||||
competition: CompetitionDetailResponse;
|
||||
communityId: string;
|
||||
canManage: boolean;
|
||||
}) {
|
||||
const queryClient = useQueryClient();
|
||||
const series = competition.projection.series;
|
||||
const defaultSeries =
|
||||
series.find(
|
||||
(item) => item.status === "ready" || item.status === "in-progress",
|
||||
) ??
|
||||
series.find((item) => item.status === "completed") ??
|
||||
series[0];
|
||||
const [selectedSeriesId, setSelectedSeriesId] = useState<string>(
|
||||
defaultSeries?.seriesId ?? "",
|
||||
);
|
||||
const [adjudicationType, setAdjudicationType] =
|
||||
useState<AdjudicationType>("walkover");
|
||||
const [winnerTeamId, setWinnerTeamId] = useState<string>("");
|
||||
const [adjudicationReason, setAdjudicationReason] = useState("");
|
||||
const [reversalMode, setReversalMode] =
|
||||
useState<SeriesReversalMode>("strict");
|
||||
const [reversalReason, setReversalReason] = useState("");
|
||||
const [reversalPreview, setReversalPreview] =
|
||||
useState<SeriesReversalPreviewResponse | null>(null);
|
||||
const [impactConfirmed, setImpactConfirmed] = useState(false);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const adjudicationIdempotencyKeyRef = useRef<string | null>(null);
|
||||
const reversalIdempotencyKeyRef = useRef<string | null>(null);
|
||||
const adjudicationMutation = useAdjudicateCompetitionSeries(communityId);
|
||||
const previewMutation = usePreviewCompetitionSeriesReversal(communityId);
|
||||
const reversalMutation = useReverseCompetitionSeries(communityId);
|
||||
|
||||
const selectedSeries =
|
||||
series.find((item) => item.seriesId === selectedSeriesId) ?? defaultSeries;
|
||||
const teamById = useMemo(
|
||||
() => new Map(competition.teams.map((team) => [team.teamId, team])),
|
||||
[competition.teams],
|
||||
);
|
||||
const eligibleTeams = selectedSeries
|
||||
? selectedSeries.entries.flatMap((entry) =>
|
||||
entry.teamId ? [teamById.get(entry.teamId)] : [],
|
||||
)
|
||||
: [];
|
||||
const selectedSeriesGames = selectedSeries
|
||||
? competition.projection.games.filter(
|
||||
(game) => game.seriesId === selectedSeries.seriesId,
|
||||
)
|
||||
: [];
|
||||
const drawAllowed = Boolean(
|
||||
selectedSeries?.rule.type === "fixed-games" &&
|
||||
selectedSeries.rule.drawPolicy === "allow",
|
||||
);
|
||||
const canAdjudicate = Boolean(
|
||||
selectedSeries &&
|
||||
(selectedSeries.status === "ready" ||
|
||||
selectedSeries.status === "in-progress"),
|
||||
);
|
||||
const canReverse = selectedSeries?.status === "completed";
|
||||
const previewIsCurrent = Boolean(
|
||||
reversalPreview && reversalPreview.sourceRevision === competition.revision,
|
||||
);
|
||||
const effectiveSelectedSeriesId = selectedSeries?.seriesId ?? "";
|
||||
const effectiveWinnerTeamId = eligibleTeams.some(
|
||||
(team) => team?.teamId === winnerTeamId,
|
||||
)
|
||||
? winnerTeamId
|
||||
: (eligibleTeams.find(Boolean)?.teamId ?? "");
|
||||
const effectiveAdjudicationType =
|
||||
adjudicationType === "administrative-draw" && !drawAllowed
|
||||
? "administrative"
|
||||
: adjudicationType === "walkover" && selectedSeriesGames.length > 0
|
||||
? "forfeit"
|
||||
: adjudicationType;
|
||||
|
||||
if (!canManage || series.length === 0) return null;
|
||||
|
||||
async function invalidateCompetitionCaches(
|
||||
response?: CompetitionCommandResponse,
|
||||
) {
|
||||
const matchId = String(competition.matchId);
|
||||
if (response) {
|
||||
queryClient.setQueryData(
|
||||
["competition", communityId, matchId],
|
||||
response.competition,
|
||||
);
|
||||
}
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["competition", communityId, matchId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["competition-team", communityId, matchId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["match", communityId, matchId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["matches", communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["matches-page", communityId],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
function resetCommandFeedback() {
|
||||
setNotice(null);
|
||||
adjudicationMutation.reset();
|
||||
previewMutation.reset();
|
||||
reversalMutation.reset();
|
||||
}
|
||||
|
||||
function handleSelectedSeriesChange(nextSeriesId: string) {
|
||||
const nextSeries = series.find((item) => item.seriesId === nextSeriesId);
|
||||
const nextHasGames = competition.projection.games.some(
|
||||
(game) => game.seriesId === nextSeries?.seriesId,
|
||||
);
|
||||
setSelectedSeriesId(nextSeriesId);
|
||||
setWinnerTeamId("");
|
||||
setAdjudicationType(nextHasGames ? "forfeit" : "walkover");
|
||||
setAdjudicationReason("");
|
||||
setReversalMode("strict");
|
||||
setReversalReason("");
|
||||
setReversalPreview(null);
|
||||
setImpactConfirmed(false);
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
resetCommandFeedback();
|
||||
}
|
||||
|
||||
function handleAdjudicationSubmit(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
if (!selectedSeries || !canAdjudicate || !adjudicationReason.trim()) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
effectiveAdjudicationType !== "administrative-draw" &&
|
||||
!effectiveWinnerTeamId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const decision: SeriesAdjudicationDecision =
|
||||
effectiveAdjudicationType === "administrative-draw"
|
||||
? { type: "administrative-draw" }
|
||||
: {
|
||||
type: effectiveAdjudicationType,
|
||||
winnerTeamId: effectiveWinnerTeamId as TeamId,
|
||||
};
|
||||
const idempotencyKey =
|
||||
adjudicationIdempotencyKeyRef.current ??
|
||||
`adjudicate:${selectedSeries.seriesId}:${crypto.randomUUID()}`;
|
||||
adjudicationIdempotencyKeyRef.current = idempotencyKey;
|
||||
resetCommandFeedback();
|
||||
adjudicationMutation.mutate(
|
||||
{
|
||||
matchId: String(competition.matchId),
|
||||
seriesId: selectedSeries.seriesId,
|
||||
revision: competition.revision,
|
||||
idempotencyKey,
|
||||
request: {
|
||||
decision,
|
||||
reason: adjudicationReason.trim(),
|
||||
},
|
||||
},
|
||||
{
|
||||
onSuccess: async (response) => {
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
setNotice("Series 판정을 기록했습니다.");
|
||||
setAdjudicationReason("");
|
||||
await invalidateCompetitionCaches(response);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handlePreviewSubmit(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
if (!selectedSeries || !canReverse || !reversalReason.trim()) return;
|
||||
|
||||
resetCommandFeedback();
|
||||
setReversalPreview(null);
|
||||
setImpactConfirmed(false);
|
||||
previewMutation.mutate(
|
||||
{
|
||||
matchId: String(competition.matchId),
|
||||
seriesId: selectedSeries.seriesId,
|
||||
revision: competition.revision,
|
||||
request: {
|
||||
mode: reversalMode,
|
||||
reason: reversalReason.trim(),
|
||||
},
|
||||
},
|
||||
{
|
||||
onSuccess: (preview) => {
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
setReversalPreview(preview);
|
||||
setImpactConfirmed(false);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function handleReverse() {
|
||||
if (
|
||||
!selectedSeries ||
|
||||
!reversalPreview ||
|
||||
!previewIsCurrent ||
|
||||
!impactConfirmed ||
|
||||
!reversalReason.trim()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const idempotencyKey =
|
||||
reversalIdempotencyKeyRef.current ??
|
||||
`reverse:${selectedSeries.seriesId}:${crypto.randomUUID()}`;
|
||||
reversalIdempotencyKeyRef.current = idempotencyKey;
|
||||
resetCommandFeedback();
|
||||
reversalMutation.mutate(
|
||||
{
|
||||
matchId: String(competition.matchId),
|
||||
seriesId: selectedSeries.seriesId,
|
||||
revision: reversalPreview.sourceRevision,
|
||||
idempotencyKey,
|
||||
request: {
|
||||
mode: reversalMode,
|
||||
reason: reversalReason.trim(),
|
||||
impactHash: reversalPreview.impactHash,
|
||||
},
|
||||
},
|
||||
{
|
||||
onSuccess: async (response) => {
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
setNotice("Series 결과를 되돌렸습니다.");
|
||||
setReversalPreview(null);
|
||||
setImpactConfirmed(false);
|
||||
setReversalReason("");
|
||||
await invalidateCompetitionCaches(response);
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const commandError =
|
||||
adjudicationMutation.error ??
|
||||
previewMutation.error ??
|
||||
reversalMutation.error;
|
||||
const commandErrorCode = competitionCommandErrorCode(commandError);
|
||||
const staleCommand =
|
||||
(commandError instanceof ApiError && commandError.status === 412) ||
|
||||
commandErrorCode === "REVERSAL_PREVIEW_STALE";
|
||||
const commandPending =
|
||||
adjudicationMutation.isPending ||
|
||||
previewMutation.isPending ||
|
||||
reversalMutation.isPending;
|
||||
|
||||
return (
|
||||
<section
|
||||
className="mb-6 border border-warning/25 bg-warning/[0.04] p-4"
|
||||
aria-labelledby="competition-admin-heading"
|
||||
>
|
||||
<div className="flex flex-wrap items-start justify-between gap-3 border-b border-warning/20 pb-3">
|
||||
<div>
|
||||
<p className="text-[11px] font-bold uppercase tracking-wider text-warning">
|
||||
Owner / Admin
|
||||
</p>
|
||||
<h2
|
||||
id="competition-admin-heading"
|
||||
className="mt-1 text-base font-bold"
|
||||
>
|
||||
공식 결과 관리
|
||||
</h2>
|
||||
</div>
|
||||
<span className="border border-base-content/10 px-2 py-1 font-mono text-xs text-base-content/45">
|
||||
revision {competition.revision}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<label className="mt-4 block text-xs font-bold text-base-content/55">
|
||||
Series
|
||||
<select
|
||||
className="mt-1.5 h-10 w-full border border-base-content/15 bg-base-100 px-3 text-sm focus:border-warning/50 focus:outline-none"
|
||||
value={effectiveSelectedSeriesId}
|
||||
disabled={commandPending}
|
||||
onChange={(event) => handleSelectedSeriesChange(event.target.value)}
|
||||
>
|
||||
{series.map((item) => (
|
||||
<option key={item.seriesId} value={item.seriesId}>
|
||||
{seriesLabel(item)} · {seriesStatusLabel(item.status)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{notice && (
|
||||
<p
|
||||
className="mt-3 border border-success/20 bg-success/10 px-3 py-2 text-sm text-success"
|
||||
role="status"
|
||||
>
|
||||
{notice}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{commandError && (
|
||||
<div
|
||||
className="mt-3 border border-error/20 bg-error/10 px-3 py-2 text-sm text-error"
|
||||
role="alert"
|
||||
>
|
||||
<p>{competitionCommandErrorMessage(commandError)}</p>
|
||||
{staleCommand && (
|
||||
<button
|
||||
type="button"
|
||||
className="mt-2 border border-error/25 px-2 py-1 text-xs font-bold hover:bg-error/10"
|
||||
onClick={() => {
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
resetCommandFeedback();
|
||||
void invalidateCompetitionCaches();
|
||||
}}
|
||||
>
|
||||
최신 revision 불러오기
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{canAdjudicate ? (
|
||||
<form className="mt-4 space-y-3" onSubmit={handleAdjudicationSubmit}>
|
||||
<h3 className="text-sm font-bold">Series 판정</h3>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<label className="text-xs font-bold text-base-content/50">
|
||||
판정 유형
|
||||
<select
|
||||
className="mt-1.5 h-10 w-full border border-base-content/15 bg-base-100 px-3 text-sm focus:border-warning/50 focus:outline-none"
|
||||
value={effectiveAdjudicationType}
|
||||
disabled={adjudicationMutation.isPending}
|
||||
onChange={(event) => {
|
||||
resetCommandFeedback();
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
setAdjudicationType(event.target.value as AdjudicationType);
|
||||
}}
|
||||
>
|
||||
<option
|
||||
value="walkover"
|
||||
disabled={selectedSeriesGames.length > 0}
|
||||
>
|
||||
{ADJUDICATION_LABELS.walkover}
|
||||
</option>
|
||||
<option value="forfeit">{ADJUDICATION_LABELS.forfeit}</option>
|
||||
<option value="administrative">
|
||||
{ADJUDICATION_LABELS.administrative}
|
||||
</option>
|
||||
{drawAllowed && (
|
||||
<option value="administrative-draw">
|
||||
{ADJUDICATION_LABELS["administrative-draw"]}
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{effectiveAdjudicationType !== "administrative-draw" && (
|
||||
<label className="text-xs font-bold text-base-content/50">
|
||||
승리 팀
|
||||
<select
|
||||
className="mt-1.5 h-10 w-full border border-base-content/15 bg-base-100 px-3 text-sm focus:border-warning/50 focus:outline-none"
|
||||
value={effectiveWinnerTeamId}
|
||||
disabled={adjudicationMutation.isPending}
|
||||
onChange={(event) => {
|
||||
resetCommandFeedback();
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
setWinnerTeamId(event.target.value);
|
||||
}}
|
||||
>
|
||||
{eligibleTeams.map((team) =>
|
||||
team ? (
|
||||
<option key={team.teamId} value={team.teamId}>
|
||||
{team.name}
|
||||
</option>
|
||||
) : null,
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<label className="block text-xs font-bold text-base-content/50">
|
||||
판정 사유
|
||||
<textarea
|
||||
className="mt-1.5 min-h-24 w-full resize-y border border-base-content/15 bg-base-100 px-3 py-2 text-sm focus:border-warning/50 focus:outline-none"
|
||||
maxLength={2000}
|
||||
value={adjudicationReason}
|
||||
disabled={adjudicationMutation.isPending}
|
||||
onChange={(event) => {
|
||||
resetCommandFeedback();
|
||||
adjudicationIdempotencyKeyRef.current = null;
|
||||
setAdjudicationReason(event.target.value);
|
||||
}}
|
||||
placeholder="감사 로그에 남을 구체적인 사유를 입력하세요."
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-warning btn-sm px-4 text-xs"
|
||||
disabled={
|
||||
adjudicationMutation.isPending ||
|
||||
!adjudicationReason.trim() ||
|
||||
(effectiveAdjudicationType !== "administrative-draw" &&
|
||||
!effectiveWinnerTeamId)
|
||||
}
|
||||
>
|
||||
{adjudicationMutation.isPending ? "기록 중..." : "판정 기록"}
|
||||
</button>
|
||||
</form>
|
||||
) : canReverse && selectedSeries ? (
|
||||
<form className="mt-4 space-y-3" onSubmit={handlePreviewSubmit}>
|
||||
<h3 className="text-sm font-bold">결과 되돌리기</h3>
|
||||
<p className="text-xs leading-5 text-base-content/50">
|
||||
먼저 현재 revision에서 영향을 계산합니다. 실행 시 동일 revision과
|
||||
impact hash가 검증됩니다.
|
||||
</p>
|
||||
<fieldset className="grid gap-2 sm:grid-cols-2">
|
||||
<legend className="mb-1 text-xs font-bold text-base-content/50">
|
||||
되돌리기 범위
|
||||
</legend>
|
||||
{(["strict", "cascade"] as const).map((mode) => (
|
||||
<label
|
||||
key={mode}
|
||||
className="flex cursor-pointer items-start gap-2 border border-base-content/10 bg-base-100 px-3 py-2 text-xs"
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="reversal-mode"
|
||||
className="radio radio-warning radio-xs mt-0.5"
|
||||
value={mode}
|
||||
checked={reversalMode === mode}
|
||||
disabled={
|
||||
previewMutation.isPending || reversalMutation.isPending
|
||||
}
|
||||
onChange={() => {
|
||||
resetCommandFeedback();
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
setReversalMode(mode);
|
||||
setReversalPreview(null);
|
||||
setImpactConfirmed(false);
|
||||
}}
|
||||
/>
|
||||
<span>
|
||||
<strong className="block text-base-content/70">
|
||||
{mode === "strict" ? "Strict" : "Cascade"}
|
||||
</strong>
|
||||
<span className="mt-0.5 block text-base-content/40">
|
||||
{mode === "strict"
|
||||
? "후속 결과가 없을 때 선택 Series만 되돌립니다."
|
||||
: "영향받은 후속 Series 결과도 함께 되돌립니다."}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
|
||||
<label className="block text-xs font-bold text-base-content/50">
|
||||
되돌리기 사유
|
||||
<textarea
|
||||
className="mt-1.5 min-h-24 w-full resize-y border border-base-content/15 bg-base-100 px-3 py-2 text-sm focus:border-warning/50 focus:outline-none"
|
||||
maxLength={2000}
|
||||
value={reversalReason}
|
||||
disabled={previewMutation.isPending || reversalMutation.isPending}
|
||||
onChange={(event) => {
|
||||
resetCommandFeedback();
|
||||
reversalIdempotencyKeyRef.current = null;
|
||||
setReversalReason(event.target.value);
|
||||
setReversalPreview(null);
|
||||
setImpactConfirmed(false);
|
||||
}}
|
||||
placeholder="감사 로그에 남을 구체적인 사유를 입력하세요."
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-outline btn-sm px-4 text-xs"
|
||||
disabled={
|
||||
previewMutation.isPending ||
|
||||
reversalMutation.isPending ||
|
||||
!reversalReason.trim()
|
||||
}
|
||||
>
|
||||
{previewMutation.isPending ? "계산 중..." : "영향 미리보기"}
|
||||
</button>
|
||||
|
||||
{reversalPreview && (
|
||||
<ReversalImpactPanel
|
||||
preview={reversalPreview}
|
||||
competition={competition}
|
||||
confirmed={impactConfirmed}
|
||||
onConfirmedChange={setImpactConfirmed}
|
||||
previewIsCurrent={previewIsCurrent}
|
||||
executing={reversalMutation.isPending}
|
||||
onExecute={handleReverse}
|
||||
/>
|
||||
)}
|
||||
</form>
|
||||
) : (
|
||||
<p className="mt-4 border border-dashed border-base-content/15 px-3 py-4 text-sm text-base-content/45">
|
||||
이 Series는 현재 판정하거나 되돌릴 수 있는 상태가 아닙니다.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function ReversalImpactPanel({
|
||||
preview,
|
||||
competition,
|
||||
confirmed,
|
||||
onConfirmedChange,
|
||||
previewIsCurrent,
|
||||
executing,
|
||||
onExecute,
|
||||
}: {
|
||||
preview: SeriesReversalPreviewResponse;
|
||||
competition: CompetitionDetailResponse;
|
||||
confirmed: boolean;
|
||||
onConfirmedChange: (confirmed: boolean) => void;
|
||||
previewIsCurrent: boolean;
|
||||
executing: boolean;
|
||||
onExecute: () => void;
|
||||
}) {
|
||||
const seriesById = new Map(
|
||||
competition.projection.series.map((series) => [series.seriesId, series]),
|
||||
);
|
||||
const teamById = new Map(
|
||||
competition.teams.map((team) => [team.teamId, team]),
|
||||
);
|
||||
const { impact } = preview;
|
||||
|
||||
return (
|
||||
<div className="border border-error/25 bg-error/[0.04] p-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h4 className="text-sm font-bold text-error">영향 범위</h4>
|
||||
<span className="font-mono text-xs text-base-content/45">
|
||||
source revision {preview.sourceRevision}
|
||||
</span>
|
||||
</div>
|
||||
<dl className="mt-3 grid grid-cols-2 gap-2 text-xs sm:grid-cols-4">
|
||||
<ImpactCount label="Series" value={impact.seriesIds.length} />
|
||||
<ImpactCount label="Facts" value={impact.factIds.length} />
|
||||
<ImpactCount label="Game slots" value={impact.gameSlotIds.length} />
|
||||
<ImpactCount label="Teams" value={impact.teamIds.length} />
|
||||
<ImpactCount label="코드 반환" value={impact.releasesReservedCodes} />
|
||||
<ImpactCount label="사용 코드 무효화" value={impact.voidsUsedCodes} />
|
||||
<ImpactCount
|
||||
label="통계 재생성"
|
||||
value={impact.requiresStatsRebuild ? "필요" : "불필요"}
|
||||
/>
|
||||
</dl>
|
||||
|
||||
<div className="mt-3 grid gap-2 sm:grid-cols-2">
|
||||
<ImpactList
|
||||
title="영향받는 Series"
|
||||
items={impact.seriesIds.map((seriesId) => {
|
||||
const series = seriesById.get(seriesId);
|
||||
return series ? seriesLabel(series) : String(seriesId);
|
||||
})}
|
||||
/>
|
||||
<ImpactList
|
||||
title="영향받는 팀"
|
||||
items={impact.teamIds.map(
|
||||
(teamId) => teamById.get(teamId)?.name ?? String(teamId),
|
||||
)}
|
||||
/>
|
||||
<ImpactList title="되돌릴 사실 ID" items={impact.factIds.map(String)} />
|
||||
<ImpactList
|
||||
title="영향받는 Game slot ID"
|
||||
items={impact.gameSlotIds.map(String)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-3">
|
||||
<span className="text-xs font-bold text-base-content/45">
|
||||
Impact hash
|
||||
</span>
|
||||
<code className="mt-1 block break-all border border-base-content/10 bg-base-100 px-2 py-1.5 font-mono text-[11px] text-base-content/55">
|
||||
{preview.impactHash}
|
||||
</code>
|
||||
</div>
|
||||
|
||||
{!previewIsCurrent && (
|
||||
<p
|
||||
className="mt-3 border border-error/20 bg-error/10 px-2 py-2 text-xs text-error"
|
||||
role="alert"
|
||||
>
|
||||
Competition revision이 변경되었습니다. 새 미리보기가 필요합니다.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<label className="mt-3 flex items-start gap-2 text-xs text-base-content/60">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="checkbox checkbox-error checkbox-xs mt-0.5"
|
||||
checked={confirmed}
|
||||
disabled={!previewIsCurrent || executing}
|
||||
onChange={(event) => onConfirmedChange(event.target.checked)}
|
||||
/>
|
||||
표시된 Series, 사실, 코드 및 통계 영향을 확인했습니다.
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-error btn-sm mt-3 px-4 text-xs"
|
||||
disabled={!confirmed || !previewIsCurrent || executing}
|
||||
onClick={onExecute}
|
||||
>
|
||||
{executing ? "되돌리는 중..." : "Hash 확인 후 되돌리기"}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ImpactCount({
|
||||
label,
|
||||
value,
|
||||
}: {
|
||||
label: string;
|
||||
value: number | string;
|
||||
}) {
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 px-2 py-2">
|
||||
<dt className="text-base-content/40">{label}</dt>
|
||||
<dd className="mt-0.5 font-mono font-bold text-base-content/70">
|
||||
{value}
|
||||
</dd>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ImpactList({ title, items }: { title: string; items: string[] }) {
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 px-2 py-2 text-xs">
|
||||
<h5 className="font-bold text-base-content/45">{title}</h5>
|
||||
{items.length > 0 ? (
|
||||
<ul className="mt-1 space-y-0.5 text-base-content/60">
|
||||
{items.map((item, index) => (
|
||||
<li key={`${item}:${index}`} className="break-all">
|
||||
{item}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="mt-1 text-base-content/35">없음</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function seriesLabel(series: SeriesProjection) {
|
||||
return series.code ?? `${stageLabel(series)} Series`;
|
||||
}
|
||||
|
||||
function stageLabel(series: SeriesProjection) {
|
||||
switch (series.stage.type) {
|
||||
case "pair":
|
||||
return "대진";
|
||||
case "round-robin":
|
||||
return `${series.stage.roundNumber ?? 1}라운드`;
|
||||
case "upper":
|
||||
return `승자조 ${series.stage.roundNumber ?? 1}라운드`;
|
||||
case "lower":
|
||||
return `패자조 ${series.stage.roundNumber ?? 1}라운드`;
|
||||
case "grand-final":
|
||||
return "그랜드 파이널";
|
||||
case "reset-final":
|
||||
return "리셋 파이널";
|
||||
}
|
||||
}
|
||||
|
||||
function seriesStatusLabel(status: SeriesProjection["status"]) {
|
||||
switch (status) {
|
||||
case "inactive":
|
||||
return "비활성";
|
||||
case "waiting":
|
||||
return "대기";
|
||||
case "ready":
|
||||
return "경기 가능";
|
||||
case "in-progress":
|
||||
return "진행 중";
|
||||
case "completed":
|
||||
return "종료";
|
||||
}
|
||||
}
|
||||
|
||||
function competitionCommandErrorMessage(error: unknown) {
|
||||
const code = competitionCommandErrorCode(error);
|
||||
if (code === "REVERSAL_PREVIEW_STALE") {
|
||||
return "미리보기 이후 Competition이 변경되었습니다. 최신 revision에서 영향을 다시 계산하세요.";
|
||||
}
|
||||
if (code === "REVERSAL_DESCENDANT_ACTIVITY") {
|
||||
return "후속 Series에 결과 또는 코드 사용 이력이 있습니다. Cascade 모드로 영향을 다시 계산하세요.";
|
||||
}
|
||||
if (code === "WALKOVER_HAS_ACTIVE_GAMES") {
|
||||
return "이미 반영된 게임이 있어 부전승 처리할 수 없습니다. 몰수패 또는 운영자 판정을 사용하세요.";
|
||||
}
|
||||
if (code === "ADJUDICATION_DRAW_NOT_ALLOWED") {
|
||||
return "이 Series 규칙은 운영자 무승부를 허용하지 않습니다.";
|
||||
}
|
||||
if (error instanceof ApiError) {
|
||||
if (error.status === 412) {
|
||||
return "Competition revision이 변경되었습니다. 최신 revision을 불러온 뒤 다시 시도하세요.";
|
||||
}
|
||||
if (error.status === 409) {
|
||||
return `현재 결과 상태와 충돌했습니다. ${error.message}`;
|
||||
}
|
||||
if (error.status === 422) {
|
||||
return `요청을 적용할 수 없습니다. ${error.message}`;
|
||||
}
|
||||
if (error.status === 403) {
|
||||
return "이 Competition 결과를 관리할 권한이 없습니다.";
|
||||
}
|
||||
}
|
||||
return error instanceof Error
|
||||
? error.message
|
||||
: "Competition 명령을 처리하지 못했습니다.";
|
||||
}
|
||||
|
||||
function competitionCommandErrorCode(error: unknown) {
|
||||
if (!(error instanceof ApiError)) return null;
|
||||
const envelope = error.data as { error?: { code?: unknown } } | null;
|
||||
return typeof envelope?.error?.code === "string" ? envelope.error.code : null;
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
import type {
|
||||
BracketRoundView,
|
||||
CompetitionDetailResponse,
|
||||
CompetitionOutcome,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import { Link } from "react-router";
|
||||
import { RoundRobinTable } from "./RoundRobinTable";
|
||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||
|
||||
export function CompetitionResults({
|
||||
competition,
|
||||
}: {
|
||||
competition: CompetitionDetailResponse;
|
||||
}) {
|
||||
const { projection } = competition;
|
||||
const teamById = new Map(
|
||||
competition.teams.map((team) => [team.teamId, team]),
|
||||
);
|
||||
const seriesById = new Map(
|
||||
projection.series.map((series) => [series.seriesId, series]),
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="mb-6 space-y-4" aria-labelledby="competition-heading">
|
||||
<header className="flex flex-wrap items-end justify-between gap-3 border-b border-base-content/10 pb-3">
|
||||
<div>
|
||||
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
Competition
|
||||
</p>
|
||||
<h2 id="competition-heading" className="mt-1 text-lg font-bold">
|
||||
공식 경기 결과
|
||||
</h2>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs text-base-content/40">
|
||||
revision {competition.revision}
|
||||
</span>
|
||||
<Link
|
||||
to={`/match/${competition.matchId}/team`}
|
||||
className="border border-base-content/10 px-2.5 py-1.5 text-xs font-bold text-base-content/55 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
내 팀 진행
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{projection.outcome && (
|
||||
<OutcomeSummary outcome={projection.outcome} teamById={teamById} />
|
||||
)}
|
||||
|
||||
{projection.formatType === "round-robin" && (
|
||||
<RoundRobinTable standings={projection.standings} teamById={teamById} />
|
||||
)}
|
||||
|
||||
{projection.rounds.length > 0 ? (
|
||||
<div className="overflow-x-auto pb-2">
|
||||
<div className="grid min-w-max auto-cols-[17rem] grid-flow-col gap-4">
|
||||
{projection.rounds.map((round) => (
|
||||
<RoundColumn
|
||||
key={`${round.stage}:${round.roundNumber ?? 0}`}
|
||||
round={round}
|
||||
seriesById={seriesById}
|
||||
teamById={teamById}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p
|
||||
className="border border-dashed border-base-content/15 px-4 py-5 text-sm text-base-content/45"
|
||||
role="status"
|
||||
>
|
||||
편성된 공식 대진이 없습니다.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{projection.games.length > 0 && (
|
||||
<div className="border border-base-content/10 bg-base-content/[0.02] p-4">
|
||||
<h3 className="text-xs font-bold uppercase tracking-wider text-base-content/40">
|
||||
완료된 게임
|
||||
</h3>
|
||||
<ul className="mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{projection.games.map((game) => (
|
||||
<li
|
||||
key={game.id}
|
||||
className="flex items-center justify-between gap-3 border border-base-content/8 bg-base-100 px-3 py-2 text-xs"
|
||||
>
|
||||
<span className="text-base-content/45">
|
||||
Game {game.displayNumber}
|
||||
</span>
|
||||
<span className="truncate font-semibold">
|
||||
{teamById.get(game.winnerTeamId)?.name ?? "알 수 없는 팀"} 승
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function RoundColumn({
|
||||
round,
|
||||
seriesById,
|
||||
teamById,
|
||||
}: {
|
||||
round: BracketRoundView;
|
||||
seriesById: Map<
|
||||
string,
|
||||
CompetitionDetailResponse["projection"]["series"][number]
|
||||
>;
|
||||
teamById: Map<TeamId, CompetitionDetailResponse["teams"][number]>;
|
||||
}) {
|
||||
return (
|
||||
<section aria-label={round.label} className="space-y-2">
|
||||
<h3 className="px-1 text-xs font-bold text-base-content/45">
|
||||
{stageLabel(round.stage, round.roundNumber)}
|
||||
</h3>
|
||||
<div className="space-y-3">
|
||||
{round.seriesIds.map((seriesId) => {
|
||||
const series = seriesById.get(seriesId);
|
||||
return series ? (
|
||||
<SeriesScoreCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
teamById={teamById}
|
||||
/>
|
||||
) : null;
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function OutcomeSummary({
|
||||
outcome,
|
||||
teamById,
|
||||
}: {
|
||||
outcome: CompetitionOutcome;
|
||||
teamById: Map<TeamId, CompetitionDetailResponse["teams"][number]>;
|
||||
}) {
|
||||
if (outcome.type === "paired-series") {
|
||||
return (
|
||||
<p className="border-l-2 border-success bg-success/5 px-3 py-2 text-sm text-base-content/65">
|
||||
{outcome.completedSeriesIds.length + outcome.drawnSeriesIds.length}개
|
||||
Series가 모두 종료되었습니다.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
const leaders =
|
||||
outcome.type === "round-robin"
|
||||
? outcome.leaderTeamIds
|
||||
: [outcome.championTeamId];
|
||||
return (
|
||||
<p className="border-l-2 border-success bg-success/5 px-3 py-2 text-sm">
|
||||
<span className="mr-2 text-xs font-bold text-success">
|
||||
{outcome.type === "round-robin" ? "1위" : "우승"}
|
||||
</span>
|
||||
<span className="font-bold">
|
||||
{leaders
|
||||
.map((teamId) => teamById.get(teamId)?.name ?? "알 수 없는 팀")
|
||||
.join(", ")}
|
||||
</span>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
function stageLabel(stage: BracketRoundView["stage"], round?: number) {
|
||||
switch (stage) {
|
||||
case "pair":
|
||||
return "대진";
|
||||
case "round-robin":
|
||||
return `${round ?? 1}라운드`;
|
||||
case "upper":
|
||||
return `승자조 ${round ?? 1}라운드`;
|
||||
case "lower":
|
||||
return `패자조 ${round ?? 1}라운드`;
|
||||
case "grand-final":
|
||||
return "그랜드 파이널";
|
||||
case "reset-final":
|
||||
return "리셋 파이널";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import type {
|
||||
CompetitionTeamView,
|
||||
RoundRobinStandingView,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
|
||||
export function RoundRobinTable({
|
||||
standings,
|
||||
teamById,
|
||||
}: {
|
||||
standings: RoundRobinStandingView[];
|
||||
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
||||
}) {
|
||||
return (
|
||||
<div className="overflow-x-auto border border-base-content/10">
|
||||
<table className="w-full min-w-[36rem] text-left text-xs">
|
||||
<caption className="sr-only">라운드 로빈 공식 순위</caption>
|
||||
<thead className="border-b border-base-content/10 bg-base-200/40 text-base-content/40">
|
||||
<tr>
|
||||
<th scope="col" className="w-14 px-3 py-2 font-semibold">
|
||||
순위
|
||||
</th>
|
||||
<th scope="col" className="px-3 py-2 font-semibold">
|
||||
팀
|
||||
</th>
|
||||
<th scope="col" className="px-3 py-2 text-right font-semibold">
|
||||
전적
|
||||
</th>
|
||||
<th scope="col" className="px-3 py-2 text-right font-semibold">
|
||||
게임
|
||||
</th>
|
||||
<th scope="col" className="px-3 py-2 text-right font-semibold">
|
||||
득실
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-base-content/8">
|
||||
{standings.map((standing) => (
|
||||
<tr key={standing.teamId}>
|
||||
<td className="px-3 py-2.5 font-mono font-bold tabular-nums">
|
||||
{standing.rank}
|
||||
</td>
|
||||
<th scope="row" className="px-3 py-2.5 font-semibold">
|
||||
{teamById.get(standing.teamId)?.name ?? "알 수 없는 팀"}
|
||||
</th>
|
||||
<td className="px-3 py-2.5 text-right tabular-nums text-base-content/60">
|
||||
{standing.seriesWins}승 {standing.seriesLosses}패
|
||||
{standing.seriesDraws > 0 ? ` ${standing.seriesDraws}무` : ""}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-right tabular-nums text-base-content/60">
|
||||
{standing.gameWins}-{standing.gameLosses}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-right font-mono font-bold tabular-nums">
|
||||
{standing.gameDiff > 0 ? "+" : ""}
|
||||
{standing.gameDiff}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import type {
|
||||
CompetitionTeamView,
|
||||
SeriesProjection,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
|
||||
const STATUS_LABEL: Record<SeriesProjection["status"], string> = {
|
||||
inactive: "비활성",
|
||||
waiting: "대진 대기",
|
||||
ready: "경기 가능",
|
||||
"in-progress": "진행 중",
|
||||
completed: "종료",
|
||||
};
|
||||
|
||||
export function SeriesScoreCard({
|
||||
series,
|
||||
teamById,
|
||||
}: {
|
||||
series: SeriesProjection;
|
||||
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
||||
}) {
|
||||
const winnerTeamId =
|
||||
series.status === "completed" && series.outcome.type !== "draw"
|
||||
? series.outcome.winnerTeamId
|
||||
: null;
|
||||
|
||||
return (
|
||||
<article
|
||||
className="border border-base-content/10 bg-base-100"
|
||||
aria-label={`${series.code ?? "경기"} ${STATUS_LABEL[series.status]}`}
|
||||
>
|
||||
<header className="flex items-center justify-between gap-3 border-b border-base-content/8 px-3 py-2">
|
||||
<span className="truncate text-xs font-bold text-base-content/65">
|
||||
{series.code ?? "Series"}
|
||||
</span>
|
||||
<span className="shrink-0 text-[11px] text-base-content/40">
|
||||
{STATUS_LABEL[series.status]}
|
||||
</span>
|
||||
</header>
|
||||
<div className="divide-y divide-base-content/8">
|
||||
{series.entries.map((entry) => {
|
||||
const team = entry.teamId ? teamById.get(entry.teamId) : undefined;
|
||||
const isWinner = entry.teamId === winnerTeamId;
|
||||
return (
|
||||
<div
|
||||
key={entry.slot}
|
||||
className="grid grid-cols-[1.5rem_minmax(0,1fr)_2rem] items-center gap-2 px-3 py-2.5"
|
||||
>
|
||||
<span className="text-[10px] font-bold text-base-content/30">
|
||||
{entry.slot}
|
||||
</span>
|
||||
<span
|
||||
className={`truncate text-sm ${
|
||||
isWinner
|
||||
? "font-bold text-base-content"
|
||||
: "text-base-content/60"
|
||||
}`}
|
||||
>
|
||||
{team?.name ?? (entry.teamId ? "알 수 없는 팀" : "대기 중")}
|
||||
{isWinner && (
|
||||
<span className="ml-2 text-[10px] font-bold text-success">
|
||||
승리
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="text-right font-mono text-base font-bold tabular-nums text-base-content/75">
|
||||
{entry.gameWins}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user