feat: add competition series result history

This commit is contained in:
dahyeon committed 2026-07-13 09:39:26 +00:00
1 parent aa675199af
commit 3c60081ece
5 files changed
+503 -44

No files matched your search

@@ -5,6 +5,7 @@ import type {
TeamId, TeamId,
} from "@lolympus/contracts"; } from "@lolympus/contracts";
import { Link } from "react-router"; import { Link } from "react-router";
import { CompetitionSeriesHistory } from "./CompetitionSeriesHistory";
import { DoubleEliminationBracket } from "./DoubleEliminationBracket"; import { DoubleEliminationBracket } from "./DoubleEliminationBracket";
import { createCompetitionBracketLayout } from "./competition-display-layout"; import { createCompetitionBracketLayout } from "./competition-display-layout";
import { bracketRoundLabel } from "./double-elimination-bracket-layout"; import { bracketRoundLabel } from "./double-elimination-bracket-layout";
@@ -81,28 +82,10 @@ export function CompetitionResults({
</p> </p>
)} )}
{projection.games.length > 0 && ( <CompetitionSeriesHistory
<div className="border border-base-content/10 bg-base-content/[0.02] p-4"> projection={projection}
<h3 className="text-xs font-bold uppercase tracking-wider text-base-content/40"> teamById={teamById}
완료된 게임 />
</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> </section>
); );
} }
@@ -0,0 +1,332 @@
import type {
CompetitionProjection,
CompetitionTeamView,
TeamId,
} from "@lolympus/contracts";
import { ChevronDown } from "lucide-react";
import {
createCompetitionSeriesHistory,
formatCompetitionHistoryDate,
formatCompetitionHistoryTime,
formatSeriesGameDuration,
getSeriesHistoryStatusLabel,
shouldDisplaySeriesHistoryScore,
type CompetitionSeriesHistoryRow,
} from "./competition-series-history";
import { bracketRoundLabel } from "./double-elimination-bracket-layout";
import { isSeriesEntryWinner } from "./series-score-card-model";
export function CompetitionSeriesHistory({
projection,
teamById,
}: {
projection: CompetitionProjection;
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
}) {
const history = createCompetitionSeriesHistory(projection);
if (history.length === 0) return null;
return (
<section
className="border border-base-content/10 bg-base-100"
aria-labelledby="competition-series-history-heading"
>
<header className="border-b border-base-content/10 px-4 py-3">
<h3
id="competition-series-history-heading"
className="text-sm font-bold"
>
경기 결과 기록
</h3>
<p className="mt-0.5 text-xs text-content-muted">
진행 중인 시리즈와 종료 결과를 실제 경기 기록 순서로 보여줍니다.
</p>
</header>
<div>
{history.map((day) => {
const headingId = `competition-history-${day.dateKey}`;
return (
<section key={day.dateKey} aria-labelledby={headingId}>
<h4
id={headingId}
className="border-b border-base-content/10 bg-base-200/60 px-4 py-3 text-sm font-bold"
>
{day.dateKey === "unknown" ? (
formatCompetitionHistoryDate(day.dateKey)
) : (
<time dateTime={day.dateKey}>
{formatCompetitionHistoryDate(day.dateKey)}
</time>
)}
</h4>
<ol className="divide-y divide-base-content/10">
{day.rows.map((row) => (
<li key={row.series.seriesId}>
<SeriesHistoryRow row={row} teamById={teamById} />
</li>
))}
</ol>
</section>
);
})}
</div>
</section>
);
}
function SeriesHistoryRow({
row,
teamById,
}: {
row: CompetitionSeriesHistoryRow;
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
}) {
if (row.games.length === 0) {
return (
<SeriesSummary row={row} teamById={teamById} hasGameDetails={false} />
);
}
return (
<details className="group">
<summary className="list-none cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-base-content/70 [&::-webkit-details-marker]:hidden">
<SeriesSummary row={row} teamById={teamById} hasGameDetails />
</summary>
<GameHistory games={row.games} teamById={teamById} />
</details>
);
}
function SeriesSummary({
row,
teamById,
hasGameDetails,
}: {
row: CompetitionSeriesHistoryRow;
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
hasGameDetails: boolean;
}) {
const { series } = row;
const statusLabel = getSeriesHistoryStatusLabel(series);
const timeLabel =
row.timestampSource === "game-start"
? formatCompetitionHistoryTime(row.occurredAt)
: null;
const roundLabel = bracketRoundLabel(
series.stage.type,
series.stage.roundNumber,
);
return (
<span className="block px-4 py-3 lg:grid lg:min-h-18 lg:grid-cols-[4.5rem_5rem_9rem_minmax(0,1fr)_6.5rem] lg:items-center lg:gap-4">
<span className="flex min-w-0 items-center gap-2 lg:contents">
<HistoryTime
occurredAt={row.occurredAt}
timeLabel={timeLabel}
/>
<StatusLabel
label={statusLabel}
inProgress={series.status === "in-progress"}
/>
<span className="min-w-0 break-words text-xs leading-4 text-content-muted">
{roundLabel}
</span>
</span>
<span className="mt-3 block lg:mt-0">
<SeriesMatchup row={row} teamById={teamById} />
</span>
<span className="mt-2 flex min-h-6 items-center justify-end text-xs font-bold text-content-muted lg:mt-0">
{hasGameDetails ? (
<>
<span className="group-open:hidden">{row.games.length}게임 보기</span>
<span className="hidden group-open:inline">게임 접기</span>
<ChevronDown
className="ml-1 h-4 w-4 transition-transform group-open:rotate-180 motion-reduce:transition-none"
aria-hidden="true"
/>
</>
) : (
<span>개별 기록 없음</span>
)}
</span>
</span>
);
}
function HistoryTime({
occurredAt,
timeLabel,
}: {
occurredAt: string;
timeLabel: string | null;
}) {
return timeLabel ? (
<time
dateTime={occurredAt}
className="shrink-0 font-mono text-sm font-bold tabular-nums"
>
{timeLabel}
</time>
) : (
<span className="shrink-0 text-sm text-content-muted">
<span aria-hidden="true">—</span>
<span className="sr-only">시작 시간 기록 없음</span>
</span>
);
}
function StatusLabel({
label,
inProgress,
}: {
label: string;
inProgress: boolean;
}) {
return (
<span
className={`shrink-0 px-1.5 py-0.5 text-xs font-bold ${
inProgress
? "border-l-2 border-primary bg-primary/10 text-base-content"
: "border-l-2 border-base-content/15 bg-base-200 text-base-content"
}`}
>
{label}
</span>
);
}
function SeriesMatchup({
row,
teamById,
}: {
row: CompetitionSeriesHistoryRow;
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
}) {
const [entryA, entryB] = row.series.entries;
const teamAName = teamName(entryA.teamId, teamById);
const teamBName = teamName(entryB.teamId, teamById);
const teamAWon = isSeriesEntryWinner(row.series, entryA.teamId);
const teamBWon = isSeriesEntryWinner(row.series, entryB.teamId);
const showScore = shouldDisplaySeriesHistoryScore(row.series);
const officialWinnerTeamId =
row.series.status === "completed" && row.series.outcome.type !== "draw"
? row.series.outcome.winnerTeamId
: null;
const winnerAnnouncement = officialWinnerTeamId
? `, ${teamName(officialWinnerTeamId, teamById)} 승`
: "";
const accessibleResult = showScore
? `${teamAName} ${entryA.gameWins} 대 ${entryB.gameWins} ${teamBName}${winnerAnnouncement}`
: `${teamAName} 대 ${teamBName}, ${getSeriesHistoryStatusLabel(row.series)}${winnerAnnouncement}`;
return (
<>
<span
className="grid grid-cols-[minmax(0,1fr)_3.5rem_minmax(0,1fr)] items-center gap-2"
aria-hidden="true"
>
<TeamName name={teamAName} winner={teamAWon} align="right" />
<span className="flex items-center justify-center gap-1 font-mono text-base font-bold tabular-nums">
{showScore ? (
<>
<span
className={
teamAWon ? "text-base-content" : "text-content-muted"
}
>
{entryA.gameWins}
</span>
<span className="text-content-disabled">:</span>
<span
className={
teamBWon ? "text-base-content" : "text-content-muted"
}
>
{entryB.gameWins}
</span>
</>
) : (
<span className="text-content-disabled">—</span>
)}
</span>
<TeamName name={teamBName} winner={teamBWon} align="left" />
</span>
<span className="sr-only">{accessibleResult}</span>
</>
);
}
function TeamName({
name,
winner,
align,
}: {
name: string;
winner: boolean;
align: "left" | "right";
}) {
return (
<span
className={`min-w-0 break-words text-sm leading-5 ${
align === "right" ? "text-right" : "text-left"
} ${winner ? "font-bold text-base-content" : "text-content-subtle"}`}
aria-hidden="true"
>
{name}
{winner && (
<span className="ml-1 text-xs font-bold text-base-content">승</span>
)}
</span>
);
}
function GameHistory({
games,
teamById,
}: {
games: CompetitionSeriesHistoryRow["games"];
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
}) {
return (
<ol className="border-t border-base-content/10 bg-base-content/[0.02] px-4 py-1">
{games.map((game) => {
const duration = formatSeriesGameDuration(game.durationSeconds);
return (
<li
key={game.id}
className="grid grid-cols-[3.75rem_3.25rem_minmax(0,1fr)_3.5rem] items-center gap-2 border-b border-base-content/8 py-2 text-xs last:border-b-0 md:grid-cols-[4.5rem_4rem_minmax(0,1fr)_4.5rem] md:gap-4"
>
<span className="font-bold text-content-muted">
Game {game.ordinal}
</span>
<time
dateTime={game.startedAt}
className="font-mono tabular-nums text-content-muted"
>
{formatCompetitionHistoryTime(game.startedAt) ?? "—"}
</time>
<span className="min-w-0 break-words font-semibold">
{teamName(game.winnerTeamId, teamById)} 승
</span>
<span
className="text-right font-mono tabular-nums text-content-muted"
aria-label={duration ? `경기 시간 ${duration}` : "경기 시간 기록 없음"}
>
{duration ?? "—"}
</span>
</li>
);
})}
</ol>
);
}
function teamName(
teamId: TeamId,
teamById: ReadonlyMap<TeamId, CompetitionTeamView>,
): string {
return teamById.get(teamId)?.name ?? "알 수 없는 팀";
}
@@ -24,6 +24,16 @@ export interface CompetitionSeriesHistoryDay {
type HistoryProjection = Pick<CompetitionProjection, "series" | "games">; type HistoryProjection = Pick<CompetitionProjection, "series" | "games">;
const KOREAN_WEEKDAYS = [
"일",
"월",
"화",
"수",
"목",
"금",
"토",
] as const;
export function createCompetitionSeriesHistory( export function createCompetitionSeriesHistory(
projection: HistoryProjection, projection: HistoryProjection,
timeZone = "Asia/Seoul", timeZone = "Asia/Seoul",
@@ -95,6 +105,16 @@ export function getSeriesHistoryStatusLabel(
} }
} }
export function shouldDisplaySeriesHistoryScore(
series: CompetitionSeriesHistorySeries,
): boolean {
if (series.status === "in-progress") return true;
if (series.outcome.type === "played") return true;
return (
series.outcome.type === "draw" && series.outcome.basis.type === "played"
);
}
export function formatSeriesGameDuration( export function formatSeriesGameDuration(
durationSeconds: number, durationSeconds: number,
): string | null { ): string | null {
@@ -109,6 +129,42 @@ export function formatSeriesGameDuration(
return `${minutes}:${padNumber(seconds)}`; return `${minutes}:${padNumber(seconds)}`;
} }
export function formatCompetitionHistoryDate(dateKey: string): string {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateKey);
if (!match) return "일시 정보 없음";
const year = Number(match[1]);
const month = Number(match[2]);
const day = Number(match[3]);
const date = new Date(Date.UTC(year, month - 1, day));
if (
date.getUTCFullYear() !== year ||
date.getUTCMonth() !== month - 1 ||
date.getUTCDate() !== day
) {
return "일시 정보 없음";
}
return `${padNumber(month)}월 ${padNumber(day)}일 (${KOREAN_WEEKDAYS[date.getUTCDay()]})`;
}
export function formatCompetitionHistoryTime(
value: IsoDateTime,
timeZone = "Asia/Seoul",
): string | null {
const date = new Date(value);
if (Number.isNaN(date.getTime())) return null;
const parts = new Intl.DateTimeFormat("en-US", {
timeZone,
hour: "2-digit",
minute: "2-digit",
hourCycle: "h23",
}).formatToParts(date);
const part = (type: Intl.DateTimeFormatPartTypes) =>
parts.find((entry) => entry.type === type)?.value;
const hour = part("hour");
const minute = part("minute");
return hour && minute ? `${hour}:${minute}` : null;
}
function compareGames( function compareGames(
left: CompetitionGameView, left: CompetitionGameView,
right: CompetitionGameView, right: CompetitionGameView,
@@ -10,9 +10,13 @@ import type {
} from "@lolympus/contracts"; } from "@lolympus/contracts";
import { import {
createCompetitionSeriesHistory, createCompetitionSeriesHistory,
formatCompetitionHistoryDate,
formatCompetitionHistoryTime,
formatSeriesGameDuration, formatSeriesGameDuration,
getSeriesHistoryStatusLabel, getSeriesHistoryStatusLabel,
shouldDisplaySeriesHistoryScore,
} from "../src/components/competition/competition-series-history.ts"; } from "../src/components/competition/competition-series-history.ts";
import { isSeriesEntryWinner } from "../src/components/competition/series-score-card-model.ts";
test("aggregates Games under their Series and preserves Series slot scores", () => { test("aggregates Games under their Series and preserves Series slot scores", () => {
const teamA = teamId("team-a"); const teamA = teamId("team-a");
@@ -265,6 +269,80 @@ test("returns explicit status labels for played and adjudicated outcomes", () =>
); );
}); });
test("shows a numeric score only for played records", () => {
const teamA = teamId("team-a");
const teamB = teamId("team-b");
const playedDraw = completedSeries({
id: "played-draw",
teamA,
teamB,
scoreA: 1,
scoreB: 1,
outcome: "draw",
});
const administrativeDraw = {
...playedDraw,
seriesId: seriesId("administrative-draw"),
outcome: {
...playedDraw.outcome,
basis: {
type: "administrative" as const,
decisionFactId: "draw-fact" as never,
},
},
};
assert.equal(
shouldDisplaySeriesHistoryScore(
inProgressSeries("running-score", teamA, teamB, 1, 0),
),
true,
);
assert.equal(
shouldDisplaySeriesHistoryScore(
completedSeries({
id: "played-score",
teamA,
teamB,
scoreA: 2,
scoreB: 1,
}),
),
true,
);
assert.equal(shouldDisplaySeriesHistoryScore(playedDraw), true);
assert.equal(shouldDisplaySeriesHistoryScore(administrativeDraw), false);
assert.equal(
shouldDisplaySeriesHistoryScore(
completedSeries({
id: "forfeit-score",
teamA,
teamB,
scoreA: 1,
scoreB: 1,
outcome: "forfeit",
}),
),
false,
);
});
test("uses the official outcome winner even when adjudicated score order differs", () => {
const teamA = teamId("official-winner");
const teamB = teamId("score-leader");
const series = completedSeries({
id: "adjudicated-winner",
teamA,
teamB,
scoreA: 0,
scoreB: 1,
outcome: "forfeit",
});
assert.equal(isSeriesEntryWinner(series, teamA), true);
assert.equal(isSeriesEntryWinner(series, teamB), false);
});
test("formats recorded Game duration and omits unknown legacy zero values", () => { test("formats recorded Game duration and omits unknown legacy zero values", () => {
assert.equal(formatSeriesGameDuration(1_875), "31:15"); assert.equal(formatSeriesGameDuration(1_875), "31:15");
assert.equal(formatSeriesGameDuration(3_661), "1:01:01"); assert.equal(formatSeriesGameDuration(3_661), "1:01:01");
@@ -272,6 +350,15 @@ test("formats recorded Game duration and omits unknown legacy zero values", () =
assert.equal(formatSeriesGameDuration(-1), null); assert.equal(formatSeriesGameDuration(-1), null);
}); });
test("formats history dates and times explicitly in Asia/Seoul", () => {
assert.equal(formatCompetitionHistoryDate("2026-07-13"), "07월 13일 (월)");
assert.equal(
formatCompetitionHistoryTime("2026-07-12T15:05:00.000Z"),
"00:05",
);
assert.equal(formatCompetitionHistoryDate("unknown"), "일시 정보 없음");
});
function playedSeriesWithGame({ function playedSeriesWithGame({
id, id,
displayOrder, displayOrder,
+23 -22
View File
@@ -27,13 +27,13 @@ and preserve all current Competition/API contracts.
**Acceptance criteria:** **Acceptance criteria:**
- [ ] Tests cover Series aggregation, ordinal Game order, KST date boundaries, - [x] Tests cover Series aggregation, ordinal Game order, KST date boundaries,
chronological order, outcome variants, and deterministic fallbacks. chronological order, outcome variants, and deterministic fallbacks.
- [ ] The focused test fails because the model module does not yet exist. - [x] The focused test fails because the model module does not yet exist.
**Verification:** **Verification:**
- [ ] Run the focused Node test and record the expected RED failure. - [x] Run the focused Node test and record the expected RED failure.
**Files likely touched:** **Files likely touched:**
@@ -43,14 +43,14 @@ and preserve all current Competition/API contracts.
**Acceptance criteria:** **Acceptance criteria:**
- [ ] Only recorded in-progress and completed Series are returned. - [x] Only recorded in-progress and completed Series are returned.
- [ ] Date grouping and format helpers are explicitly KST-aware. - [x] Date grouping and format helpers are explicitly KST-aware.
- [ ] Decision outcomes and missing legacy durations remain distinguishable. - [x] Decision outcomes and missing legacy durations remain distinguishable.
**Verification:** **Verification:**
- [ ] Focused history tests pass. - [x] Focused history tests pass.
- [ ] Existing web tests still pass. - [x] Existing web tests still pass.
**Files likely touched:** **Files likely touched:**
@@ -59,7 +59,7 @@ and preserve all current Competition/API contracts.
### Checkpoint: Model ### Checkpoint: Model
- [ ] Pure tests pass without a React or browser dependency. - [x] Pure tests pass without a React or browser dependency.
### Phase 2: Responsive Result UI ### Phase 2: Responsive Result UI
@@ -67,16 +67,16 @@ and preserve all current Competition/API contracts.
**Acceptance criteria:** **Acceptance criteria:**
- [ ] Desktop uses a flat schedule-like row; mobile stacks metadata and matchup - [x] Desktop uses a flat schedule-like row; mobile stacks metadata and matchup
without horizontal scrolling. without horizontal scrolling.
- [ ] Status and official winner are communicated with visible text and typography, - [x] Status and official winner are communicated with visible text and typography,
not color alone. not color alone.
- [ ] Game-less decisions do not show fake start times or `0 : 0`. - [x] Game-less decisions do not show fake start times or `0 : 0`.
**Verification:** **Verification:**
- [ ] Changed component files pass ESLint. - [x] Changed component files pass ESLint.
- [ ] Web build succeeds. - [x] Web build succeeds.
**Files likely touched:** **Files likely touched:**
@@ -86,15 +86,16 @@ and preserve all current Competition/API contracts.
**Acceptance criteria:** **Acceptance criteria:**
- [ ] Each Series with Games exposes a native keyboard-operable disclosure. - [x] Each Series with Games exposes a native keyboard-operable disclosure.
- [ ] Games use Series-local ordinal, team-ID winner lookup, and omit unknown - [x] Games use Series-local ordinal, team-ID winner lookup, and omit unknown
zero-duration values. zero-duration values.
- [ ] The old completed-Game mini-card block is removed. - [x] The old completed-Game mini-card block is removed.
**Verification:** **Verification:**
- [ ] Full web tests, lint, and build pass. - [x] Full web tests, changed-file lint, and build pass. Repository-wide lint remains
- [ ] Source review checks heading order, disclosure semantics, and 320px layout. blocked by pre-existing errors outside this change.
- [x] Source review checks heading order, disclosure semantics, and 320px layout.
**Files likely touched:** **Files likely touched:**
@@ -103,9 +104,9 @@ and preserve all current Competition/API contracts.
### Checkpoint: Complete ### Checkpoint: Complete
- [ ] All specification success criteria are met. - [x] All specification success criteria are met.
- [ ] Git diff contains only the feature spec, plan, tests, model, and UI integration. - [x] Git diff contains only the feature spec, plan, tests, model, and UI integration.
- [ ] Unrelated working-tree files are unchanged. - [x] Unrelated working-tree files are unchanged.
## Risks and Mitigations ## Risks and Mitigations