diff --git a/apps/api/src/modules/competition/domain/series-graph.ts b/apps/api/src/modules/competition/domain/series-graph.ts index 0632dcaf..288de088 100644 --- a/apps/api/src/modules/competition/domain/series-graph.ts +++ b/apps/api/src/modules/competition/domain/series-graph.ts @@ -51,6 +51,11 @@ export interface SeriesDefinition { { position: 'B'; source: ParticipantSource }, ]; rule: SeriesRule; + schedule?: { + date: string; + time: string | null; + timeZone: 'Asia/Seoul'; + }; activation?: { type: 'grand-final-reset-required'; grandFinalSeriesId: string; diff --git a/apps/api/src/modules/competition/domain/series-projector.spec.ts b/apps/api/src/modules/competition/domain/series-projector.spec.ts index ceb38f89..bf414edc 100644 --- a/apps/api/src/modules/competition/domain/series-projector.spec.ts +++ b/apps/api/src/modules/competition/domain/series-projector.spec.ts @@ -1,6 +1,110 @@ import { projectSeries } from './series-projector'; describe('projectSeries', () => { + it.each([ + ['a known local time', '21:30'], + ['an unknown local time', null], + ] as const)('preserves an optional Series schedule with %s', (_, time) => { + const schedule = { + date: '2026-07-15', + time, + timeZone: 'Asia/Seoul' as const, + }; + const definition = { + ...seriesDefinition({ + id: `series-scheduled-${time ?? 'unknown'}`, + stage: 'upper', + rule: { type: 'first-to' as const, winsRequired: 1, maxGames: 1 }, + }), + schedule, + }; + + const projection = projectSeries({ + definition, + participants: ['team-8', 'team-3'], + facts: [], + }); + + expect(projection).toMatchObject({ + status: 'ready', + schedule, + }); + }); + + it('keeps an existing definition without a schedule explicitly unscheduled', () => { + const definition = seriesDefinition({ + id: 'series-unscheduled', + stage: 'upper', + rule: { type: 'first-to', winsRequired: 1, maxGames: 1 }, + }); + + const projection = projectSeries({ + definition, + participants: ['team-8', 'team-3'], + facts: [], + }); + + expect(projection).not.toHaveProperty('schedule'); + }); + + it.each([ + [ + 'an impossible calendar date', + { date: '2026-02-30', time: '21:30', timeZone: 'Asia/Seoul' }, + ], + [ + 'an out-of-range local time', + { date: '2026-07-15', time: '24:00', timeZone: 'Asia/Seoul' }, + ], + [ + 'a non-canonical time zone', + { date: '2026-07-15', time: '21:30', timeZone: 'UTC' }, + ], + ])('rejects a Series schedule with %s', (_, schedule) => { + const definition = { + ...seriesDefinition({ + id: `series-invalid-schedule-${schedule.date}-${schedule.time}`, + stage: 'upper', + rule: { type: 'first-to' as const, winsRequired: 1, maxGames: 1 }, + }), + schedule, + } as unknown as Parameters[0]['definition']; + + expectInvariant( + () => + projectSeries({ + definition, + participants: ['team-8', 'team-3'], + facts: [], + }), + 'SERIES_DEFINITION_INVALID', + ); + }); + + it.each([null, false, ''])( + 'rejects a non-object Series schedule value %p', + (schedule) => { + const definition = { + ...seriesDefinition({ + id: 'series-invalid-schedule-shape', + stage: 'upper', + rule: { type: 'first-to' as const, winsRequired: 1, maxGames: 1 }, + }), + schedule, + } as unknown as Parameters[0]['definition']; + + expectInvariant( + () => + projectSeries({ + definition, + participants: ['team-8', 'team-3'], + facts: [], + }), + 'SERIES_DEFINITION_INVALID', + ); + }, + ); + it('keeps a fixed-games pair in progress until every game slot is filled', () => { const definition = seriesDefinition({ id: 'series-pair', diff --git a/apps/api/src/modules/competition/domain/series-projector.ts b/apps/api/src/modules/competition/domain/series-projector.ts index aaf00dfb..5b207f48 100644 --- a/apps/api/src/modules/competition/domain/series-projector.ts +++ b/apps/api/src/modules/competition/domain/series-projector.ts @@ -13,6 +13,12 @@ export type SeriesRule = drawPolicy: 'allow' | 'tiebreak-required'; }; +export interface SeriesSchedule { + date: string; + time: string | null; + timeZone: 'Asia/Seoul'; +} + export interface SeriesDefinitionLike { id: string; code?: string; @@ -26,6 +32,7 @@ export interface SeriesDefinitionLike { source: Readonly>; }>; rule: SeriesRule; + schedule?: SeriesSchedule; gameSlots: ReadonlyArray<{ id: string; seriesId: string; @@ -75,6 +82,7 @@ interface SeriesProjectionBase { code?: string; stage: SeriesDefinitionLike['stage']; rule: SeriesRule; + schedule?: SeriesSchedule; entries: [SeriesProjectionEntry, SeriesProjectionEntry]; } @@ -311,6 +319,15 @@ function validateDefinition(definition: SeriesDefinitionLike): void { `Series ${definition.id} must define exactly the local A and B slots`, ); + const schedule: unknown = definition.schedule; + if (schedule !== undefined) { + assertCompetitionInvariant( + isSeriesSchedule(schedule), + 'SERIES_DEFINITION_INVALID', + `Series ${definition.id} has an invalid schedule`, + ); + } + const requiredSlots = definition.rule.type === 'fixed-games' ? definition.rule.gameCount @@ -753,6 +770,7 @@ function projectionBase( ...(definition.code ? { code: definition.code } : {}), stage: definition.stage, rule: definition.rule, + ...(definition.schedule ? { schedule: { ...definition.schedule } } : {}), entries: [ { slot: 'A', teamId: participants[0], gameWins: 0 }, { slot: 'B', teamId: participants[1], gameWins: 0 }, @@ -760,6 +778,35 @@ function projectionBase( }; } +function isValidLocalDate(value: string): boolean { + const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value); + if (!match) return false; + 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)); + return ( + date.getUTCFullYear() === year && + date.getUTCMonth() === month - 1 && + date.getUTCDate() === day + ); +} + +function isSeriesSchedule(value: unknown): value is SeriesSchedule { + if (typeof value !== 'object' || value === null || Array.isArray(value)) { + return false; + } + const schedule = value as Record; + return ( + typeof schedule.date === 'string' && + isValidLocalDate(schedule.date) && + (schedule.time === null || + (typeof schedule.time === 'string' && + /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(schedule.time))) && + schedule.timeZone === 'Asia/Seoul' + ); +} + function entriesFor( participants: [string, string], winsByTeam: Map, diff --git a/apps/web/src/components/competition/CompetitionGameHistory.tsx b/apps/web/src/components/competition/CompetitionGameHistory.tsx index d92bcd4c..74827145 100644 --- a/apps/web/src/components/competition/CompetitionGameHistory.tsx +++ b/apps/web/src/components/competition/CompetitionGameHistory.tsx @@ -55,14 +55,14 @@ export function CompetitionGameHistory({ to={detailPath} state={{ backTo: historyBackTo, - backLabel: "경기 결과로 돌아가기", + backLabel: "경기 일정·결과로 돌아가기", }} - className="block min-h-11 border-l-2 border-l-transparent px-2 py-2 text-xs text-base-content transition-colors hover:border-l-primary hover:bg-primary/[0.06] active:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary motion-reduce:transition-none" + className="grid min-h-14 items-center px-2 py-2 text-xs leading-5 text-base-content transition-colors hover:bg-primary/[0.06] active:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary motion-reduce:transition-none" > {content} ) : ( -
+
{content}
)} @@ -84,50 +84,57 @@ function GameHistoryRowContent({ duration: string | null; linked: boolean; }) { + const startedAt = formatCompetitionHistoryTime(game.startedAt); + return ( - - - {game.ordinal}게임 - - - + + {winnerName} 승 - - {duration ? ( - <> - 경기 시간 - {duration} - + + + + {game.ordinal}게임 + + {startedAt ? ( + ) : ( - <> + - 경기 시간 기록 없음 - + 시작 시각 기록 없음 + )} - {linked && ( - - 상세 분석 - ); } diff --git a/apps/web/src/components/competition/CompetitionResults.tsx b/apps/web/src/components/competition/CompetitionResults.tsx index 9a83983f..555c7d08 100644 --- a/apps/web/src/components/competition/CompetitionResults.tsx +++ b/apps/web/src/components/competition/CompetitionResults.tsx @@ -24,17 +24,18 @@ export function CompetitionResults({ const teamById = new Map( competition.teams.map((team) => [team.teamId, team]), ); + const seriesHistory = + view === "bracket" ? [] : createCompetitionSeriesHistory(projection); if (view === "games") { - const hasSeriesHistory = - createCompetitionSeriesHistory(projection).length > 0; + const hasSeriesHistory = seriesHistory.length > 0; return (
{hasSeriesHistory ? ( ) : ( @@ -42,7 +43,7 @@ export function CompetitionResults({ className="border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/45" role="status" > - 기록된 공식 경기가 없습니다. + 예정되거나 기록된 공식 경기가 없습니다.

)}
@@ -62,7 +63,7 @@ export function CompetitionResults({ Competition

- 공식 경기 결과 + 공식 경기 일정·결과

@@ -114,7 +115,7 @@ export function CompetitionResults({ )} diff --git a/apps/web/src/components/competition/CompetitionSeriesHistory.tsx b/apps/web/src/components/competition/CompetitionSeriesHistory.tsx index 13223879..3fa279f2 100644 --- a/apps/web/src/components/competition/CompetitionSeriesHistory.tsx +++ b/apps/web/src/components/competition/CompetitionSeriesHistory.tsx @@ -1,6 +1,5 @@ import type { CommunityId, - CompetitionProjection, CompetitionTeamView, MatchId, TeamId, @@ -9,14 +8,16 @@ import { ChevronDown } from "lucide-react"; import { useState } from "react"; import { useLocation } from "react-router"; import { - createCompetitionSeriesHistory, - formatCompetitionHistoryDayHeading, - formatCompetitionHistoryTime, + formatCompetitionHistoryDate, getSeriesHistoryRecordLabel, getSeriesHistoryResultLabel, getSeriesHistoryStatusLabel, + getSeriesHistoryTimePresentation, + isCompetitionHistoryCalendarDate, shouldDisplaySeriesHistoryScore, + type CompetitionSeriesHistoryDay, type CompetitionSeriesHistoryRow, + type CompetitionSeriesHistorySeries, } from "./competition-series-history"; import { CompetitionGameHistory } from "./CompetitionGameHistory"; import { bracketRoundLabel } from "./double-elimination-bracket-layout"; @@ -25,22 +26,29 @@ import { isSeriesEntryWinner } from "./series-score-card-model"; export function CompetitionSeriesHistory({ communityId, matchId, - projection, + history, teamById, }: { communityId: CommunityId; matchId: MatchId; - projection: CompetitionProjection; + history: CompetitionSeriesHistoryDay[]; teamById: ReadonlyMap; }) { const location = useLocation(); const historyPath = `${location.pathname}${location.search}`; - const history = createCompetitionSeriesHistory(projection); if (history.length === 0) return null; - const resultCount = history.reduce( - (count, day) => count + day.rows.length, - 0, - ); + + const rows = history.flatMap((day) => day.rows); + const anchorRow = + rows.find((row) => row.series.status === "in-progress") ?? + rows.find((row) => isFutureSeries(row.series)) ?? + rows.at(-1); + const jumpLabel = + anchorRow?.series.status === "in-progress" + ? "진행 중 경기로" + : anchorRow && isFutureSeries(anchorRow.series) + ? "다음 경기로" + : "최근 결과로"; return (
- 경기 결과 기록 + 경기 일정·결과

- 진행 중인 시리즈와 최종 결과를 실제 경기 기록 순서로 보여줍니다. + 예정 경기부터 최종 결과까지 날짜순으로 보여줍니다.

- {resultCount > 1 && ( + {rows.length > 1 && anchorRow && ( - 최신 결과로 + {jumpLabel}