feat: add competition series result history
This commit is contained in:
1 parent
aa675199af
commit
3c60081ece
5 files changed
+503
-44
No files matched your search
@@ -5,6 +5,7 @@ import type {
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import { Link } from "react-router";
|
||||
import { CompetitionSeriesHistory } from "./CompetitionSeriesHistory";
|
||||
import { DoubleEliminationBracket } from "./DoubleEliminationBracket";
|
||||
import { createCompetitionBracketLayout } from "./competition-display-layout";
|
||||
import { bracketRoundLabel } from "./double-elimination-bracket-layout";
|
||||
@@ -81,28 +82,10 @@ export function CompetitionResults({
|
||||
</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>
|
||||
)}
|
||||
<CompetitionSeriesHistory
|
||||
projection={projection}
|
||||
teamById={teamById}
|
||||
/>
|
||||
</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">;
|
||||
|
||||
const KOREAN_WEEKDAYS = [
|
||||
"일",
|
||||
"월",
|
||||
"화",
|
||||
"수",
|
||||
"목",
|
||||
"금",
|
||||
"토",
|
||||
] as const;
|
||||
|
||||
export function createCompetitionSeriesHistory(
|
||||
projection: HistoryProjection,
|
||||
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(
|
||||
durationSeconds: number,
|
||||
): string | null {
|
||||
@@ -109,6 +129,42 @@ export function formatSeriesGameDuration(
|
||||
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(
|
||||
left: CompetitionGameView,
|
||||
right: CompetitionGameView,
|
||||
|
||||
Reference in new issue
Block a user