From 03e88a03bcb6045304aab943f73c7dded5e8cf2d Mon Sep 17 00:00:00 2001 From: dahyeon Date: Mon, 13 Jul 2026 23:16:43 -0700 Subject: [PATCH] feat: improve series score card presentation Show outcome-aware labels and scores, prioritize readable match names, and provide complete accessible summaries for bracket cards. --- .../competition/SeriesScoreCard.tsx | 110 ++++++-- .../competition/series-score-card-model.ts | 98 +++++++ apps/web/test/series-score-card-model.test.ts | 254 ++++++++++++++++++ 3 files changed, 437 insertions(+), 25 deletions(-) create mode 100644 apps/web/test/series-score-card-model.test.ts diff --git a/apps/web/src/components/competition/SeriesScoreCard.tsx b/apps/web/src/components/competition/SeriesScoreCard.tsx index a336846c..4d48a418 100644 --- a/apps/web/src/components/competition/SeriesScoreCard.tsx +++ b/apps/web/src/components/competition/SeriesScoreCard.tsx @@ -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 = { - inactive: "비활성", - waiting: "대진 대기", - ready: "경기 가능", - "in-progress": "진행 중", - completed: "종료", +const CARD_TONE_CLASS: Record = { + muted: "", + ready: "border-l-2 border-l-success/70", + live: "border-l-2 border-l-primary/70", + completed: "", + adjudicated: "", +}; + +const HEADER_TONE_CLASS: Record = { + muted: "", + ready: "bg-success/[0.035]", + live: "bg-primary/[0.04]", + completed: "", + adjudicated: "", +}; + +const STATUS_TONE_CLASS: Record = { + 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; 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 (
- {seriesLabel ?? "Series"} + + {identity.label} + + {identity.code && ( + + {identity.code} + + )} - - {STATUS_LABEL[series.status]} + + {(presentation.tone === "ready" || presentation.tone === "live") && ( +
{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({ {teamName} {isWinner && ( - 승리 + + 승리 + )} - +
); } @@ -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({ {teamName} - + {isWinner ? "승리" : null} - + ); } -function Score({ gameWins }: { gameWins: number }) { +function Score({ score }: { score: string }) { return ( - - {gameWins} + + {score} ); } diff --git a/apps/web/src/components/competition/series-score-card-model.ts b/apps/web/src/components/competition/series-score-card-model.ts index 8da11519..dfd6d419 100644 --- a/apps/web/src/components/competition/series-score-card-model.ts +++ b/apps/web/src/components/competition/series-score-card-model.ts @@ -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, +): 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, +): 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 }; + } +} diff --git a/apps/web/test/series-score-card-model.test.ts b/apps/web/test/series-score-card-model.test.ts new file mode 100644 index 00000000..a8b1105e --- /dev/null +++ b/apps/web/test/series-score-card-model.test.ts @@ -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", + }, + }; +}