feat: improve series score card presentation

Show outcome-aware labels and scores, prioritize readable match names, and provide complete accessible summaries for bracket cards.
This commit is contained in:
dahyeon committed 2026-07-13 23:16:43 -07:00
1 parent 43c25c05cd
commit 03e88a03bc
3 files changed
+437 -25

No files matched your search

@@ -4,14 +4,37 @@ import type {
TeamId,
} from "@lolympus/contracts";
import { SERIES_SCORE_CARD_GEOMETRY } from "./series-score-card-geometry";
import { isSeriesEntryWinner } from "./series-score-card-model";
import {
formatSeriesScore,
getSeriesScoreCardAccessibleLabel,
getSeriesScoreCardIdentity,
getSeriesScoreCardPresentation,
isSeriesEntryWinner,
type SeriesScoreCardTone,
} from "./series-score-card-model";
const STATUS_LABEL: Record<SeriesProjection["status"], string> = {
inactive: "비활성",
waiting: "대진 대기",
ready: "경기 가능",
"in-progress": "진행 중",
completed: "종료",
const CARD_TONE_CLASS: Record<SeriesScoreCardTone, string> = {
muted: "",
ready: "border-l-2 border-l-success/70",
live: "border-l-2 border-l-primary/70",
completed: "",
adjudicated: "",
};
const HEADER_TONE_CLASS: Record<SeriesScoreCardTone, string> = {
muted: "",
ready: "bg-success/[0.035]",
live: "bg-primary/[0.04]",
completed: "",
adjudicated: "",
};
const STATUS_TONE_CLASS: Record<SeriesScoreCardTone, string> = {
muted: "border-base-content/10 bg-base-200 text-content-muted",
ready: "border-success/30 bg-success/10 text-base-content",
live: "border-primary/30 bg-primary/10 text-base-content",
completed: "border-base-content/10 bg-base-200 text-content-muted",
adjudicated: "border-warning/35 bg-warning/10 text-base-content",
};
export function SeriesScoreCard({
@@ -19,25 +42,31 @@ export function SeriesScoreCard({
displayLabel,
teamById,
variant = "default",
accessibilityLabel,
}: {
series: SeriesProjection;
displayLabel?: string;
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
variant?: "default" | "bracket";
accessibilityLabel?: string;
}) {
const isBracket = variant === "bracket";
const seriesLabel = series.code ?? displayLabel;
const identity = getSeriesScoreCardIdentity(series, displayLabel);
const presentation = getSeriesScoreCardPresentation(series);
const cardAccessibilityLabel =
accessibilityLabel ??
getSeriesScoreCardAccessibleLabel(series, displayLabel, teamById);
return (
<article
className="border border-base-content/10 bg-base-100"
aria-label={`${seriesLabel ?? "경기"} ${STATUS_LABEL[series.status]}`}
className={`border border-base-content/10 bg-base-100 ${CARD_TONE_CLASS[presentation.tone]}`}
aria-label={cardAccessibilityLabel}
style={
isBracket ? { height: SERIES_SCORE_CARD_GEOMETRY.height } : undefined
}
>
<header
className={`flex items-center justify-between gap-3 border-b border-base-content/8 ${
className={`flex items-center justify-between gap-2 border-b border-base-content/8 ${HEADER_TONE_CLASS[presentation.tone]} ${
isBracket ? "px-2" : "px-3 py-2"
}`}
style={
@@ -47,19 +76,39 @@ export function SeriesScoreCard({
}
>
<span
className="truncate text-xs font-bold text-base-content/65"
title={seriesLabel ?? "Series"}
className="min-w-0"
title={
identity.code
? `${identity.label} (${identity.code})`
: identity.label
}
>
{seriesLabel ?? "Series"}
<span className="block truncate text-[11px] font-bold leading-3 text-base-content/75">
{identity.label}
</span>
{identity.code && (
<span className="mt-0.5 block truncate font-mono text-[9px] leading-[10px] text-content-subtle">
{identity.code}
</span>
)}
</span>
<span className="shrink-0 text-[11px] text-base-content/40">
{STATUS_LABEL[series.status]}
<span
className={`inline-flex shrink-0 items-center gap-1 border px-1 py-0.5 text-[10px] font-bold leading-3 ${STATUS_TONE_CLASS[presentation.tone]}`}
>
{(presentation.tone === "ready" || presentation.tone === "live") && (
<span
className={`size-1.5 ${presentation.tone === "ready" ? "bg-success" : "bg-primary"}`}
aria-hidden="true"
/>
)}
{presentation.label}
</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 = isSeriesEntryWinner(series, entry.teamId);
const score = formatSeriesScore(series, entry.gameWins);
const teamName =
team?.name ?? (entry.teamId ? "알 수 없는 팀" : "대기 중");
return isBracket ? (
@@ -67,6 +116,7 @@ export function SeriesScoreCard({
key={entry.slot}
entry={entry}
isWinner={isWinner}
score={score}
teamName={teamName}
/>
) : (
@@ -74,6 +124,7 @@ export function SeriesScoreCard({
key={entry.slot}
entry={entry}
isWinner={isWinner}
score={score}
teamName={teamName}
/>
);
@@ -86,10 +137,12 @@ export function SeriesScoreCard({
function DefaultEntryRow({
entry,
isWinner,
score,
teamName,
}: {
entry: SeriesProjection["entries"][number];
isWinner: boolean;
score: string;
teamName: string;
}) {
return (
@@ -99,15 +152,17 @@ function DefaultEntryRow({
</span>
<span
className={`truncate text-sm ${
isWinner ? "font-bold text-base-content" : "text-base-content/60"
isWinner ? "font-bold text-base-content" : "text-content-subtle"
}`}
>
{teamName}
{isWinner && (
<span className="ml-2 text-[10px] font-bold text-success">승리</span>
<span className="ml-2 text-[10px] font-bold text-base-content">
승리
</span>
)}
</span>
<Score gameWins={entry.gameWins} />
<Score score={score} />
</div>
);
}
@@ -115,10 +170,12 @@ function DefaultEntryRow({
function BracketEntryRow({
entry,
isWinner,
score,
teamName,
}: {
entry: SeriesProjection["entries"][number];
isWinner: boolean;
score: string;
teamName: string;
}) {
return (
@@ -131,24 +188,27 @@ function BracketEntryRow({
</span>
<span
className={`line-clamp-2 break-words text-[13px] leading-4 ${
isWinner ? "font-bold text-base-content" : "text-base-content/60"
isWinner ? "font-bold text-base-content" : "text-content-subtle"
}`}
title={teamName}
>
{teamName}
</span>
<span className="text-center text-[10px] font-bold text-success">
<span className="text-center text-[10px] font-bold text-base-content">
{isWinner ? "승리" : null}
</span>
<Score gameWins={entry.gameWins} />
<Score score={score} />
</div>
);
}
function Score({ gameWins }: { gameWins: number }) {
function Score({ score }: { score: string }) {
return (
<span className="text-right font-mono text-base font-bold tabular-nums text-base-content/75">
{gameWins}
<span
className="text-right font-mono text-base font-bold tabular-nums text-base-content/75"
aria-label={score === "—" ? "점수 없음" : `${score}승`}
>
{score}
</span>
);
}
@@ -1,5 +1,80 @@
import type { SeriesProjection, TeamId } from "@lolympus/contracts";
export type SeriesScoreCardTone =
| "muted"
| "ready"
| "live"
| "completed"
| "adjudicated";
export interface SeriesScoreCardPresentation {
label: string;
tone: SeriesScoreCardTone;
showScore: boolean;
}
export function getSeriesScoreCardIdentity(
series: SeriesProjection,
displayLabel?: string,
): { label: string; code: string | undefined } {
const label = displayLabel ?? series.code ?? "Series";
return {
label,
code: series.code && series.code !== label ? series.code : undefined,
};
}
export function getSeriesScoreCardPresentation(
series: SeriesProjection,
): SeriesScoreCardPresentation {
switch (series.status) {
case "inactive":
return { label: "비활성", tone: "muted", showScore: false };
case "waiting":
return { label: "대진 대기", tone: "muted", showScore: false };
case "ready":
return { label: "경기 가능", tone: "ready", showScore: false };
case "in-progress":
return { label: "진행 중", tone: "live", showScore: true };
case "completed":
return completedSeriesPresentation(series);
}
}
export function formatSeriesScore(
series: SeriesProjection,
gameWins: number,
): string {
return getSeriesScoreCardPresentation(series).showScore
? String(gameWins)
: "—";
}
export function getSeriesScoreCardAccessibleLabel(
series: SeriesProjection,
displayLabel: string | undefined,
teamById: ReadonlyMap<TeamId, { readonly name: string }>,
): string {
const identity = getSeriesScoreCardIdentity(series, displayLabel);
const presentation = getSeriesScoreCardPresentation(series);
const identityLabel = identity.code
? `${identity.label}, 코드 ${identity.code}`
: identity.label;
const entries = series.entries.map((entry) => {
const teamName = entry.teamId
? (teamById.get(entry.teamId)?.name ?? "알 수 없는 팀")
: "대기 중";
const score = formatSeriesScore(series, entry.gameWins);
const scoreLabel = score === "—" ? "점수 없음" : `${score}승`;
const winnerLabel = isSeriesEntryWinner(series, entry.teamId)
? ", 승리"
: "";
return `${entry.slot} ${teamName}, ${scoreLabel}${winnerLabel}.`;
});
return `${identityLabel}, ${presentation.label}. ${entries.join(" ")}`;
}
export function isSeriesEntryWinner(
series: SeriesProjection,
teamId: TeamId | null,
@@ -11,3 +86,26 @@ export function isSeriesEntryWinner(
series.outcome.winnerTeamId === teamId
);
}
function completedSeriesPresentation(
series: Extract<SeriesProjection, { status: "completed" }>,
): SeriesScoreCardPresentation {
switch (series.outcome.type) {
case "played":
return { label: "종료", tone: "completed", showScore: true };
case "draw": {
const played = series.outcome.basis.type === "played";
return {
label: "무승부",
tone: played ? "completed" : "adjudicated",
showScore: played,
};
}
case "walkover":
return { label: "부전승", tone: "adjudicated", showScore: false };
case "forfeit":
return { label: "기권승", tone: "adjudicated", showScore: false };
case "administrative":
return { label: "판정", tone: "adjudicated", showScore: false };
}
}
@@ -0,0 +1,254 @@
import assert from "node:assert/strict";
import test from "node:test";
import type {
CompetitionFactId,
SeriesId,
SeriesProjection,
TeamId,
} from "@lolympus/contracts";
import {
formatSeriesScore,
getSeriesScoreCardAccessibleLabel,
getSeriesScoreCardIdentity,
getSeriesScoreCardPresentation,
} from "../src/components/competition/series-score-card-model.ts";
const TEAM_A = "team-a" as TeamId;
const TEAM_B = "team-b" as TeamId;
test("presents future and active Series with distinct status hierarchy", () => {
const inactive = pendingSeries("inactive", "inactive");
const waiting = pendingSeries("waiting", "waiting");
const ready = readySeries("ready");
const inProgress = inProgressSeries("running", 1, 0);
assert.deepEqual(getSeriesScoreCardPresentation(inactive), {
label: "비활성",
tone: "muted",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(waiting), {
label: "대진 대기",
tone: "muted",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(ready), {
label: "경기 가능",
tone: "ready",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(inProgress), {
label: "진행 중",
tone: "live",
showScore: true,
});
assert.equal(formatSeriesScore(waiting, 0), "—");
assert.equal(formatSeriesScore(ready, 0), "—");
assert.equal(formatSeriesScore(inProgress, 0), "0");
});
test("prioritizes a human-readable match name and keeps the code as metadata", () => {
const series = readySeries("WB_R2_M2");
assert.deepEqual(
getSeriesScoreCardIdentity(series, "브래킷 상위 2R · 2경기"),
{
label: "브래킷 상위 2R · 2경기",
code: "WB_R2_M2",
},
);
assert.deepEqual(getSeriesScoreCardIdentity(series), {
label: "WB_R2_M2",
code: undefined,
});
});
test("shows numeric scores only for played completed outcomes", () => {
const played = completedSeries("played", 2, 1);
const playedDraw = completedDraw("played", 1, 1);
const administrativeDraw = completedDraw("administrative", 0, 0);
assert.deepEqual(getSeriesScoreCardPresentation(played), {
label: "종료",
tone: "completed",
showScore: true,
});
assert.deepEqual(getSeriesScoreCardPresentation(playedDraw), {
label: "무승부",
tone: "completed",
showScore: true,
});
assert.deepEqual(getSeriesScoreCardPresentation(administrativeDraw), {
label: "무승부",
tone: "adjudicated",
showScore: false,
});
assert.equal(formatSeriesScore(played, 2), "2");
assert.equal(formatSeriesScore(playedDraw, 1), "1");
assert.equal(formatSeriesScore(administrativeDraw, 0), "—");
});
test("names adjudicated outcomes without inferring from their scores", () => {
const walkover = completedSeries("walkover", 0, 0);
const forfeit = completedSeries("forfeit", 0, 1);
const administrative = completedSeries("administrative", 1, 0);
assert.deepEqual(getSeriesScoreCardPresentation(walkover), {
label: "부전승",
tone: "adjudicated",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(forfeit), {
label: "기권승",
tone: "adjudicated",
showScore: false,
});
assert.deepEqual(getSeriesScoreCardPresentation(administrative), {
label: "판정",
tone: "adjudicated",
showScore: false,
});
assert.equal(getSeriesScoreCardPresentation(walkover).showScore, false);
assert.equal(getSeriesScoreCardPresentation(forfeit).showScore, false);
assert.equal(getSeriesScoreCardPresentation(administrative).showScore, false);
assert.equal(formatSeriesScore(walkover, 0), "—");
assert.equal(formatSeriesScore(forfeit, 1), "—");
assert.equal(formatSeriesScore(administrative, 1), "—");
});
test("summarizes status, teams, scores, and winner for a focus target", () => {
const series = completedSeries("played", 2, 1);
const teamById = new Map([
[TEAM_A, { name: "나물장수" }],
[TEAM_B, { name: "원딜미아요" }],
]);
assert.equal(
getSeriesScoreCardAccessibleLabel(
series,
"브래킷 1라운드 · 1경기",
teamById,
),
"브래킷 1라운드 · 1경기, 코드 PLAYED, 종료. A 나물장수, 2승, 승리. B 원딜미아요, 1승.",
);
});
test("announces an adjudicated official winner without a numeric score", () => {
const series = completedSeries("forfeit", 0, 1);
const teamById = new Map([
[TEAM_A, { name: "나물장수" }],
[TEAM_B, { name: "원딜미아요" }],
]);
assert.equal(
getSeriesScoreCardAccessibleLabel(
series,
"브래킷 1라운드 · 1경기",
teamById,
),
"브래킷 1라운드 · 1경기, 코드 FORFEIT, 기권승. A 나물장수, 점수 없음, 승리. B 원딜미아요, 점수 없음.",
);
});
function baseSeries(id: string) {
return {
seriesId: id as SeriesId,
code: id.toUpperCase(),
stage: { type: "upper" as const, roundNumber: 1, displayOrder: 1 },
rule: { type: "first-to" as const, winsRequired: 2, maxGames: 3 },
};
}
function pendingSeries(
id: string,
status: "inactive" | "waiting",
): SeriesProjection {
return {
...baseSeries(id),
status,
entries: [
{ slot: "A", teamId: null, gameWins: 0 },
{ slot: "B", teamId: null, gameWins: 0 },
],
};
}
function readySeries(id: string): SeriesProjection {
return {
...baseSeries(id),
status: "ready",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: 0 },
{ slot: "B", teamId: TEAM_B, gameWins: 0 },
],
};
}
function inProgressSeries(
id: string,
scoreA: number,
scoreB: number,
): SeriesProjection {
return {
...baseSeries(id),
status: "in-progress",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
};
}
function completedSeries(
outcome: "played" | "walkover" | "forfeit" | "administrative",
scoreA: number,
scoreB: number,
): SeriesProjection {
const sharedOutcome = {
winnerTeamId: TEAM_A,
loserTeamId: TEAM_B,
completedAt: "2026-07-13T00:00:00.000Z",
};
return {
...baseSeries(outcome),
status: "completed",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
outcome:
outcome === "played"
? { ...sharedOutcome, type: outcome, decidedByGameIds: [] }
: {
...sharedOutcome,
type: outcome,
decisionFactId: `${outcome}-fact` as CompetitionFactId,
},
};
}
function completedDraw(
basis: "played" | "administrative",
scoreA: number,
scoreB: number,
): SeriesProjection {
return {
...baseSeries(`${basis}-draw`),
status: "completed",
entries: [
{ slot: "A", teamId: TEAM_A, gameWins: scoreA },
{ slot: "B", teamId: TEAM_B, gameWins: scoreB },
],
outcome: {
type: "draw",
basis:
basis === "played"
? { type: basis, decidedByGameIds: [] }
: {
type: basis,
decisionFactId: "draw-fact" as CompetitionFactId,
},
completedAt: "2026-07-13T00:00:00.000Z",
},
};
}