Files
lolympus-tournament-support/apps/web/src/pages/home-match-presentation.ts
T
dahyeon 0d7617e2d2 feat: connect tournament views to APIs and recover archived stats
Remove development previews and complete hall of fame, match history, official results, and multi-kill API integration.

Fix active match pagination and team-ready controls, preserve basic scoreboards, and recover statistics when Riot archives arrive.

Use bounded in-process cache invalidation retries and add the Riot match lookup index migration with regression coverage.
2026-11-11 02:00:35 +09:00

112 lines
3.4 KiB
TypeScript

import type { MatchDetailResponse, MatchEventStage } from '@lolympus/contracts';
const scheduleFormatter = new Intl.DateTimeFormat('ko-KR', {
timeZone: 'Asia/Seoul',
month: 'numeric',
day: 'numeric',
weekday: 'short',
hour: '2-digit',
minute: '2-digit',
hourCycle: 'h23',
});
const MATCH_STAGE_LABEL: Record<MatchEventStage, string> = {
recruiting: '모집 중',
auction: '경매 중',
'team-ready': '팀 편성 완료',
'team-check': '팀빌딩 상태 확인 필요',
'in-progress': '진행 중',
finished: '종료',
};
export function getMatchStageLabel(
match: Pick<MatchDetailResponse, 'status' | 'eventProgress'>,
) {
return MATCH_STAGE_LABEL[match.eventProgress?.stage ??
(match.status === 'team-built' ? 'team-check' : match.status)];
}
type HomeMatchEnrollment = Pick<
MatchDetailResponse,
'status' | 'eventProgress' | 'joined' | 'participants' | 'maxParticipants'
>;
export function getHomeMatchSchedule(scheduledAt: string) {
const value = new Date(scheduledAt);
if (Number.isNaN(value.getTime())) return;
const { month, day, weekday, hour, minute } = Object.fromEntries(
scheduleFormatter
.formatToParts(value)
.map(({ type, value }) => [type, value]),
);
const time = `${hour}:${minute}`;
return {
date: `${month}월 ${day}일 (${weekday})`,
compact: `${month}/${day} (${weekday}) ${time}`,
month,
day,
weekday,
hour,
minute,
time,
};
}
export function getHistoryMatchTitle(
title: string,
schedule: ReturnType<typeof getHomeMatchSchedule>,
) {
if (!schedule) return title;
// Only shorten a generic date-based title when its entire date and time match the row.
const generic =
/^(\d{1,2})\/(\d{1,2})\s*\(([월화수목금토일])\)\s*(\d{1,2})(?:시(?:\s*(\d{1,2})분)?|:(\d{2}))\s*(정기\s*내전|내전)$/u.exec(
title.trim(),
);
if (!generic) return title;
const [, month, day, weekday, hour, minutes, colonMinutes, name] = generic;
return Number(month) === Number(schedule.month) &&
Number(day) === Number(schedule.day) &&
weekday === schedule.weekday &&
Number(hour) === Number(schedule.hour) &&
Number(minutes ?? colonMinutes ?? 0) === Number(schedule.minute)
? name
: title;
}
export function getHomeMatchEnrollment(match: HomeMatchEnrollment) {
const current = match.participants.length;
const remaining = match.maxParticipants - current;
const isRecruiting = match.status === 'recruiting';
const canApply = isRecruiting && remaining > 0 && !match.joined;
const capacity =
match.maxParticipants > 0
? `${current}/${match.maxParticipants}명`
: `${current}명`;
const label =
isRecruiting && match.joined
? '참가 완료'
: canApply
? `${remaining}자리 남음`
: '모집 마감';
return { canApply, capacity, label };
}
export function getNextMatchBanner(
match: HomeMatchEnrollment & Pick<MatchDetailResponse, 'title'>,
) {
const { canApply, capacity } = getHomeMatchEnrollment(match);
const regularTitle = /^(?:[월화수목금토일]요일\s*(?:정기\s*)?|정기\s*)내전$/u;
const title = regularTitle.test(match.title.trim()) ? '정기 내전' : match.title;
let status = getMatchStageLabel(match);
if (match.status === 'recruiting') {
if (match.joined) status = '신청 완료';
else if (!canApply) status = match.maxParticipants > 0 ? '정원 마감' : '모집 마감';
}
return { title, status, capacity, canApply };
}