Files
lolympus-tournament-support/apps/web/src/pages/home-match-presentation.ts
T
dahyeon 664af15255 feat: refresh the home page and separate match event types
Add an inhouse hero, Hall of Fame, rankings, and event-specific schedules. Carry the event type through the API and admin tools, and improve results and player history displays.
2026-11-10 22:13:55 +09:00

104 lines
3.1 KiB
TypeScript

import type { MatchDetailResponse } 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',
});
export const HOME_MATCH_STATUS = {
recruiting: '모집 중',
'team-built': '팀빌딩',
'in-progress': '진행 중',
finished: '종료',
} as const;
type HomeMatchEnrollment = Pick<
MatchDetailResponse,
'status' | '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: string = HOME_MATCH_STATUS[match.status];
if (match.status === 'team-built') status = '팀 편성';
if (match.status === 'recruiting') {
if (match.joined) status = '신청 완료';
else if (!canApply) status = match.maxParticipants > 0 ? '정원 마감' : '모집 마감';
}
return { title, status, capacity, canApply };
}