feat: improve tournament workflows and prune outdated docs
This commit is contained in:
1 parent
da7b502936
commit
38a89b5374
53 files changed
+3308
-3276
No files matched your search
+413
-422
@@ -1,149 +1,252 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
CalendarDays,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Map as MapIcon,
|
||||
Users,
|
||||
} from 'lucide-react';
|
||||
import { Link } from 'react-router';
|
||||
import { mapApiMatchToMatchDetail } from '../api/mappers';
|
||||
import { useCommunity, useMatches, useMatchesPage } from '../api/hooks';
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchSummaryResponse,
|
||||
} from '@lolympus/contracts';
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import { Link, useSearchParams } from 'react-router';
|
||||
import { useMatches, useMatchesPage } from '../api/hooks';
|
||||
import { mapIdToLabel } from '../api/mappers';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
import {
|
||||
Button,
|
||||
EmptyNote,
|
||||
ErrorNote,
|
||||
MetaDot,
|
||||
PageBody,
|
||||
PageHero,
|
||||
Panel,
|
||||
PanelHeader,
|
||||
Pill,
|
||||
PlainPage,
|
||||
Skeleton,
|
||||
type PillTone,
|
||||
} from '../ui';
|
||||
import {
|
||||
getHistoryMatchTitle,
|
||||
getHomeMatchEnrollment,
|
||||
getHomeMatchSchedule,
|
||||
HOME_MATCH_STATUS,
|
||||
} from './home-match-presentation';
|
||||
|
||||
const UPCOMING_GRID_MATCH_LIMIT = 3;
|
||||
const UPCOMING_MATCH_LIST_LIMIT = UPCOMING_GRID_MATCH_LIMIT + 1;
|
||||
const UPCOMING_MATCH_LIST_LIMIT = 4;
|
||||
const HISTORY_MATCH_PAGE_SIZE = 10;
|
||||
const HOME_HISTORY_LIMIT = 5;
|
||||
const DEFAULT_MAP_ID = 11;
|
||||
|
||||
const STATUS_PRESENTATION: Record<
|
||||
string,
|
||||
{ label: string; tone: PillTone; live?: boolean }
|
||||
> = {
|
||||
recruiting: { label: '모집중', tone: 'live', live: true },
|
||||
'team-built': { label: '팀빌딩', tone: 'gold' },
|
||||
'in-progress': { label: '진행중', tone: 'accent', live: true },
|
||||
finished: { label: '종료', tone: 'neutral' },
|
||||
};
|
||||
const DECISION_LABELS = {
|
||||
walkover: '부전승',
|
||||
forfeit: '기권승',
|
||||
administrative: '판정승',
|
||||
draw: '무승부',
|
||||
} as const;
|
||||
|
||||
function StatusPill({ status, onInk }: { status: string; onInk?: boolean }) {
|
||||
const presentation = STATUS_PRESENTATION[status] ?? {
|
||||
label: status,
|
||||
tone: 'neutral' as const,
|
||||
};
|
||||
const tone =
|
||||
onInk && presentation.tone === 'neutral' ? 'ink' : presentation.tone;
|
||||
function NextMatch({ match }: { match?: MatchDetailResponse }) {
|
||||
if (!match) {
|
||||
return (
|
||||
<h1 className="text-sm font-medium text-content-muted">
|
||||
예정된 내전이 없습니다
|
||||
</h1>
|
||||
);
|
||||
}
|
||||
|
||||
const schedule = getHomeMatchSchedule(match.scheduledAt);
|
||||
const enrollment = getHomeMatchEnrollment(match);
|
||||
const href = `/match/${match._id}`;
|
||||
|
||||
return (
|
||||
<Pill tone={tone} dot={presentation.live} pulse={presentation.live}>
|
||||
{presentation.label}
|
||||
</Pill>
|
||||
<header className="flex flex-col gap-3 rounded-xl border border-line bg-card p-4 sm:flex-row sm:items-center sm:justify-between sm:gap-6 sm:p-5">
|
||||
<div className="min-w-0">
|
||||
<p className="flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm text-content-muted">
|
||||
<span className="font-semibold">다음 내전</span>
|
||||
{schedule && (
|
||||
<time
|
||||
dateTime={match.scheduledAt}
|
||||
className="tabular font-semibold text-content"
|
||||
>
|
||||
{schedule.date} · {schedule.time}
|
||||
</time>
|
||||
)}
|
||||
</p>
|
||||
<h1 className="mt-1 break-words text-xl font-bold leading-snug sm:text-2xl">
|
||||
{match.title}
|
||||
</h1>
|
||||
<p className="tabular mt-1 flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm text-content-muted">
|
||||
{match.status !== 'recruiting' && (
|
||||
<span>{HOME_MATCH_STATUS[match.status]} ·</span>
|
||||
)}
|
||||
<span>{enrollment.capacity} ·</span>
|
||||
<strong className="font-semibold text-content">
|
||||
{enrollment.label}
|
||||
</strong>
|
||||
{match.mapId !== DEFAULT_MAP_ID && (
|
||||
<span>· {mapIdToLabel(match.mapId)}</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
{enrollment.canApply ? (
|
||||
<div className="shrink-0">
|
||||
<Button label="참가 신청" variant="primary" size="md" href={href} />
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
to={href}
|
||||
className="inline-flex min-h-10 w-fit shrink-0 items-center gap-1 text-sm font-semibold text-content hover:underline"
|
||||
>
|
||||
내전 보기
|
||||
<ChevronRight className="size-4" aria-hidden="true" />
|
||||
</Link>
|
||||
)}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
function formatCompactDateTime(dateLike: string) {
|
||||
const date = new Date(dateLike);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
|
||||
const weekday = new Intl.DateTimeFormat('ko-KR', {
|
||||
weekday: 'short',
|
||||
}).format(date);
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
|
||||
return `${date.getMonth() + 1}/${date.getDate()} (${weekday}) ${hours}:${minutes}`;
|
||||
function UpcomingMatches({ matches }: { matches: MatchDetailResponse[] }) {
|
||||
return (
|
||||
<Panel>
|
||||
<PanelHeader title="이어지는 내전" />
|
||||
<ul className="divide-y divide-line">
|
||||
{matches.map((match) => {
|
||||
const schedule = getHomeMatchSchedule(match.scheduledAt);
|
||||
const { capacity, label } = getHomeMatchEnrollment(match);
|
||||
return (
|
||||
<li key={match._id}>
|
||||
<Link
|
||||
to={`/match/${match._id}`}
|
||||
className="group grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 px-4 py-3 transition-colors hover:bg-sunken sm:grid-cols-[8rem_minmax(0,1fr)_auto_1rem] sm:px-5"
|
||||
>
|
||||
<time
|
||||
dateTime={match.scheduledAt}
|
||||
className="tabular col-start-1 text-xs text-content-muted"
|
||||
>
|
||||
{schedule?.compact ?? '일정 미정'}
|
||||
</time>
|
||||
<h3 className="col-start-1 mt-0.5 truncate text-[15px] font-semibold text-content group-hover:underline sm:col-start-2 sm:row-start-1 sm:mt-0">
|
||||
{match.title}
|
||||
</h3>
|
||||
<p className="tabular col-start-1 mt-1 text-[13px] text-content-muted sm:col-start-3 sm:row-start-1 sm:mt-0">
|
||||
{match.status === 'recruiting'
|
||||
? label
|
||||
: HOME_MATCH_STATUS[match.status]}{' '}
|
||||
· {capacity}
|
||||
</p>
|
||||
<ChevronRight
|
||||
className="col-start-2 row-span-3 row-start-1 size-4 text-content-muted sm:col-start-4 sm:row-span-1"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
|
||||
/** 정원 대비 신청 인원. 숫자와 막대를 함께 보여 남은 자리를 바로 읽게 한다. */
|
||||
function CapacityMeter({
|
||||
current,
|
||||
max,
|
||||
onInk = false,
|
||||
}: {
|
||||
current: number;
|
||||
max: number;
|
||||
onInk?: boolean;
|
||||
}) {
|
||||
const ratio = max > 0 ? Math.min(1, current / max) : 0;
|
||||
const isFull = max > 0 && current >= max;
|
||||
|
||||
return (
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="tabular whitespace-nowrap">
|
||||
<strong className={onInk ? 'text-on-ink' : 'text-content'}>
|
||||
{current}
|
||||
</strong>
|
||||
/{max}명
|
||||
</span>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`h-1.5 w-16 overflow-hidden rounded-full ${onInk ? 'bg-white/15' : 'bg-sunken-strong'}`}
|
||||
function HistoryResult({ match }: { match: MatchSummaryResponse }) {
|
||||
const result = match.historyResult;
|
||||
if (match.status === 'finished' && result) {
|
||||
switch (result.type) {
|
||||
case 'score': {
|
||||
const label = result.winnerTeamName
|
||||
? `${result.winnerTeamName} 승`
|
||||
: undefined;
|
||||
return (
|
||||
<span className="flex min-w-0 items-baseline gap-1.5">
|
||||
<strong className="tabular shrink-0 font-bold text-content">
|
||||
{result.teamAWins}:{result.teamBWins}
|
||||
</strong>
|
||||
{label && (
|
||||
<span
|
||||
className="min-w-0 break-words text-content-muted md:truncate"
|
||||
title={label}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
case 'winners': {
|
||||
const label = result.teamNames.join(', ');
|
||||
return (
|
||||
<span className="flex min-w-0 items-baseline gap-1.5">
|
||||
<strong className="shrink-0 font-semibold text-content">
|
||||
{result.teamNames.length > 1 ? '공동 1위' : '우승'}
|
||||
</strong>
|
||||
<span
|
||||
className="min-w-0 break-words text-content-muted md:truncate"
|
||||
title={label}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
case 'decision': {
|
||||
return (
|
||||
<span className="flex min-w-0 items-baseline gap-1.5">
|
||||
<strong className="shrink-0 font-semibold text-content">
|
||||
{DECISION_LABELS[result.decision]}
|
||||
</strong>
|
||||
{result.winnerTeamName && (
|
||||
<span
|
||||
className="min-w-0 break-words text-content-muted md:truncate"
|
||||
title={result.winnerTeamName}
|
||||
>
|
||||
{result.winnerTeamName}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match.status === 'team-built' || match.status === 'in-progress') {
|
||||
return (
|
||||
<Pill
|
||||
tone={match.status === 'in-progress' ? 'live' : 'neutral'}
|
||||
dot={match.status === 'in-progress'}
|
||||
>
|
||||
<span
|
||||
className={`block h-full rounded-full ${isFull ? 'bg-brand-coral' : 'bg-brand-leaf'}`}
|
||||
style={{ width: `${ratio * 100}%` }}
|
||||
/>
|
||||
</span>
|
||||
{HOME_MATCH_STATUS[match.status]}
|
||||
</Pill>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span className="text-content-muted">
|
||||
{HOME_MATCH_STATUS[match.status]}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function HistoryTableColGroup() {
|
||||
return (
|
||||
<colgroup>
|
||||
<col className="w-[168px]" />
|
||||
<col />
|
||||
<col className="w-[96px]" />
|
||||
<col className="w-[132px]" />
|
||||
<col className="w-[72px]" />
|
||||
</colgroup>
|
||||
);
|
||||
}
|
||||
|
||||
function HistoryTableHeader() {
|
||||
return (
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">날짜</th>
|
||||
<th scope="col">내전</th>
|
||||
<th scope="col">상태</th>
|
||||
<th scope="col">맵</th>
|
||||
<th scope="col" className="!text-right">
|
||||
참가
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
);
|
||||
}
|
||||
|
||||
function HistoryRecordsSkeleton({
|
||||
rows = HISTORY_MATCH_PAGE_SIZE,
|
||||
}: {
|
||||
rows?: number;
|
||||
}) {
|
||||
const historySkeletons = Array.from({ length: rows });
|
||||
|
||||
function HistoryTableColumns() {
|
||||
return (
|
||||
<>
|
||||
<div className="hidden overflow-x-auto md:block">
|
||||
<table className="lts-table table-fixed">
|
||||
<HistoryTableColGroup />
|
||||
<HistoryTableHeader />
|
||||
<colgroup>
|
||||
<col className="w-36" />
|
||||
<col />
|
||||
<col className="w-44" />
|
||||
<col className="w-16" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">일정</th>
|
||||
<th scope="col">내전</th>
|
||||
<th scope="col">결과</th>
|
||||
<th scope="col" className="!text-right">
|
||||
참가
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function HistoryRecordsSkeleton({ limit }: { limit: number }) {
|
||||
const rows = Array.from({ length: limit });
|
||||
return (
|
||||
<>
|
||||
<div className="hidden md:block">
|
||||
<table className="lts-table table-fixed" aria-hidden="true">
|
||||
<HistoryTableColumns />
|
||||
<tbody>
|
||||
{historySkeletons.map((_, index) => (
|
||||
{rows.map((_, index) => (
|
||||
<tr key={index}>
|
||||
<td>
|
||||
<Skeleton width={96} height={14} index={index} />
|
||||
@@ -152,10 +255,7 @@ function HistoryRecordsSkeleton({
|
||||
<Skeleton width="60%" height={14} index={index} />
|
||||
</td>
|
||||
<td>
|
||||
<Skeleton width={48} height={20} radius="rounded" />
|
||||
</td>
|
||||
<td>
|
||||
<Skeleton width={80} height={14} index={index} />
|
||||
<Skeleton width={56} height={14} index={index} />
|
||||
</td>
|
||||
<td>
|
||||
<Skeleton width={28} height={14} className="ml-auto" />
|
||||
@@ -165,8 +265,8 @@ function HistoryRecordsSkeleton({
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="divide-y divide-line md:hidden">
|
||||
{historySkeletons.map((_, index) => (
|
||||
<div className="divide-y divide-line md:hidden" aria-hidden="true">
|
||||
{rows.map((_, index) => (
|
||||
<div key={index} className="space-y-2 px-4 py-3">
|
||||
<Skeleton width={110} height={12} index={index} />
|
||||
<Skeleton width="70%" height={16} index={index} />
|
||||
@@ -177,22 +277,78 @@ function HistoryRecordsSkeleton({
|
||||
);
|
||||
}
|
||||
|
||||
function HomePageSkeleton() {
|
||||
function HistoryRecords({ matches }: { matches: MatchSummaryResponse[] }) {
|
||||
if (matches.length === 0) {
|
||||
return <EmptyNote size="sm" title="아직 내전 기록이 없습니다." />;
|
||||
}
|
||||
|
||||
const rows = matches.map((match) => {
|
||||
const schedule = getHomeMatchSchedule(match.scheduledAt);
|
||||
return {
|
||||
match,
|
||||
title: getHistoryMatchTitle(match.title, schedule),
|
||||
href: `/match/${match._id}`,
|
||||
schedule: schedule?.compact ?? '일정 미정',
|
||||
map:
|
||||
match.mapId === DEFAULT_MAP_ID ? undefined : mapIdToLabel(match.mapId),
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div aria-busy="true" aria-live="polite">
|
||||
<span className="sr-only">매치 목록을 불러오는 중...</span>
|
||||
<PageHero
|
||||
eyebrow="다음 내전"
|
||||
title={<span className="opacity-0">내전을 불러오는 중</span>}
|
||||
meta={<span className="opacity-0">일정</span>}
|
||||
/>
|
||||
<PageBody className="space-y-5">
|
||||
<Panel>
|
||||
<PanelHeader title="지난 내전" />
|
||||
<HistoryRecordsSkeleton />
|
||||
</Panel>
|
||||
</PageBody>
|
||||
</div>
|
||||
<>
|
||||
<div className="hidden md:block">
|
||||
<table className="lts-table table-fixed">
|
||||
<HistoryTableColumns />
|
||||
<tbody>
|
||||
{rows.map(({ match, title, href, schedule, map }) => (
|
||||
<tr key={match._id} className="transition-colors hover:bg-sunken">
|
||||
<td className="tabular whitespace-nowrap text-[13px] text-content-muted">
|
||||
<time dateTime={match.scheduledAt}>{schedule}</time>
|
||||
</td>
|
||||
<td>
|
||||
<Link
|
||||
to={href}
|
||||
className="block truncate font-semibold text-content hover:underline"
|
||||
title={match.title}
|
||||
>
|
||||
{title}
|
||||
</Link>
|
||||
{map && <p className="text-xs text-content-muted">{map}</p>}
|
||||
</td>
|
||||
<td className="text-[13px]">
|
||||
<HistoryResult match={match} />
|
||||
</td>
|
||||
<td className="tabular whitespace-nowrap text-right text-[13px] text-content-muted">
|
||||
{match.participants.length}명
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<ul className="divide-y divide-line md:hidden">
|
||||
{rows.map(({ match, title, href, schedule, map }) => (
|
||||
<li key={match._id}>
|
||||
<Link
|
||||
to={href}
|
||||
className="group block px-4 py-3 transition-colors hover:bg-sunken"
|
||||
>
|
||||
<div className="tabular flex flex-wrap justify-between gap-x-3 text-xs text-content-muted">
|
||||
<time dateTime={match.scheduledAt}>{schedule}</time>
|
||||
<span>{match.participants.length}명</span>
|
||||
</div>
|
||||
<p className="mt-0.5 break-words text-[15px] font-semibold leading-snug text-content group-hover:underline">
|
||||
{title}
|
||||
</p>
|
||||
<div className="mt-1 flex flex-wrap items-baseline gap-x-2 gap-y-1 text-[13px]">
|
||||
<HistoryResult match={match} />
|
||||
{map && <span className="text-content-muted">· {map}</span>}
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -213,13 +369,10 @@ function HistoryPagination({
|
||||
onPrevious,
|
||||
onNext,
|
||||
}: HistoryPaginationProps) {
|
||||
const hasPrevious = page > 1;
|
||||
const hasNext = page < pageCount;
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-3 border-t border-line px-4 py-2.5 sm:px-5">
|
||||
<span className="tabular text-xs text-content-subtle">
|
||||
총 {total}개 · {page} / {pageCount}
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-t border-line px-4 py-2.5 sm:px-5">
|
||||
<span className="tabular text-xs text-content-muted">
|
||||
총 {total.toLocaleString('ko-KR')}개 · {page} / {pageCount}
|
||||
</span>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
@@ -227,7 +380,7 @@ function HistoryPagination({
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon={<ChevronLeft className="size-4" aria-hidden="true" />}
|
||||
isDisabled={!hasPrevious || isFetching}
|
||||
isDisabled={page <= 1 || isFetching}
|
||||
onClick={onPrevious}
|
||||
/>
|
||||
<Button
|
||||
@@ -235,7 +388,7 @@ function HistoryPagination({
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
endContent={<ChevronRight className="size-4" aria-hidden="true" />}
|
||||
isDisabled={!hasNext || isFetching}
|
||||
isDisabled={page >= pageCount || isFetching}
|
||||
onClick={onNext}
|
||||
/>
|
||||
</div>
|
||||
@@ -245,29 +398,38 @@ function HistoryPagination({
|
||||
|
||||
export default function HomePage() {
|
||||
const [timelineNow] = useState(() => new Date().toISOString());
|
||||
const [historyPage, setHistoryPage] = useState(1);
|
||||
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
|
||||
const upcomingMatchesQuery = useMatches(
|
||||
{
|
||||
limit: UPCOMING_MATCH_LIST_LIMIT,
|
||||
scheduledFrom: timelineNow,
|
||||
sort: 'asc',
|
||||
},
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
);
|
||||
const historyMatchesQuery = useMatchesPage(
|
||||
{
|
||||
limit: HISTORY_MATCH_PAGE_SIZE,
|
||||
page: historyPage,
|
||||
scheduledTo: timelineNow,
|
||||
sort: 'desc',
|
||||
},
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
);
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const showArchive = searchParams.get('history') === 'all';
|
||||
const requestedPage = Number(searchParams.get('page'));
|
||||
const historyPage =
|
||||
showArchive && Number.isSafeInteger(requestedPage) && requestedPage > 0
|
||||
? requestedPage
|
||||
: 1;
|
||||
const historyLimit = showArchive
|
||||
? HISTORY_MATCH_PAGE_SIZE
|
||||
: HOME_HISTORY_LIMIT;
|
||||
function setHistoryPage(page: number) {
|
||||
const params = new URLSearchParams(searchParams);
|
||||
if (page > 1) params.set('page', String(page));
|
||||
else params.delete('page');
|
||||
setSearchParams(params, { preventScrollReset: true });
|
||||
}
|
||||
const upcomingMatchesQuery = useMatches({
|
||||
limit: UPCOMING_MATCH_LIST_LIMIT,
|
||||
scheduledFrom: timelineNow,
|
||||
sort: 'asc',
|
||||
});
|
||||
const historyMatchesQuery = useMatchesPage({
|
||||
limit: historyLimit,
|
||||
page: historyPage,
|
||||
scheduledTo: timelineNow,
|
||||
sort: 'desc',
|
||||
includeResults: true,
|
||||
});
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
<PlainPage className="py-16">
|
||||
<PlainPage className="lts-overview py-16">
|
||||
<ErrorNote
|
||||
title="커뮤니티가 설정되지 않았습니다"
|
||||
description="apps/web/.env.development의 VITE_DEFAULT_COMMUNITY_ID를 먼저 설정해주세요."
|
||||
@@ -276,277 +438,106 @@ export default function HomePage() {
|
||||
);
|
||||
}
|
||||
|
||||
if (upcomingMatchesQuery.isLoading) {
|
||||
return <HomePageSkeleton />;
|
||||
}
|
||||
|
||||
if (upcomingMatchesQuery.error) {
|
||||
return (
|
||||
<PlainPage className="py-16">
|
||||
<ErrorNote
|
||||
title="매치 목록을 불러오지 못했습니다"
|
||||
action={
|
||||
<Button
|
||||
label="다시 시도"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => void upcomingMatchesQuery.refetch()}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</PlainPage>
|
||||
);
|
||||
}
|
||||
|
||||
const upcomingMatches =
|
||||
upcomingMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
|
||||
const historyMatches =
|
||||
historyMatchesQuery.data?.matches.map((match) => ({
|
||||
...mapApiMatchToMatchDetail(match),
|
||||
rawStatus: match.status,
|
||||
compactDateTime: formatCompactDateTime(match.scheduledAt),
|
||||
})) ?? [];
|
||||
const [nextMatch, ...upcomingMatches] = upcomingMatchesQuery.data ?? [];
|
||||
const historyTotal = historyMatchesQuery.data?.total ?? 0;
|
||||
const historyLimit =
|
||||
historyMatchesQuery.data?.limit ?? HISTORY_MATCH_PAGE_SIZE;
|
||||
const historyPageCount = Math.max(1, Math.ceil(historyTotal / historyLimit));
|
||||
const historyPageCount = Math.max(
|
||||
1,
|
||||
Math.ceil(historyTotal / (historyMatchesQuery.data?.limit ?? historyLimit)),
|
||||
);
|
||||
const isHistoryPageLoading =
|
||||
historyMatchesQuery.isLoading ||
|
||||
(historyMatchesQuery.isFetching && historyMatchesQuery.isPlaceholderData);
|
||||
const hasHistoryError =
|
||||
Boolean(historyMatchesQuery.error) && !historyMatchesQuery.data;
|
||||
const goToPreviousHistoryPage = () =>
|
||||
setHistoryPage((page) => Math.max(1, page - 1));
|
||||
const goToNextHistoryPage = () => setHistoryPage((page) => page + 1);
|
||||
const nextMatch = upcomingMatches[0];
|
||||
const upcomingCards = upcomingMatches.slice(1, 1 + UPCOMING_GRID_MATCH_LIMIT);
|
||||
const statsPath = `/communities/${DEFAULT_COMMUNITY_ID}/internal-stats`;
|
||||
const communityName = communityQuery.data?.name ?? 'LOLYMPUS';
|
||||
|
||||
return (
|
||||
<>
|
||||
{nextMatch ? (
|
||||
<PageHero
|
||||
eyebrow="다음 내전"
|
||||
title={
|
||||
<Link to={`/match/${nextMatch.id}`} className="hover:underline">
|
||||
{nextMatch.title}
|
||||
</Link>
|
||||
}
|
||||
badges={<StatusPill status={nextMatch.status} onInk />}
|
||||
meta={
|
||||
<>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<CalendarDays className="size-4" aria-hidden="true" />
|
||||
{nextMatch.date} {nextMatch.time}
|
||||
</span>
|
||||
<MetaDot />
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<MapIcon className="size-4" aria-hidden="true" />
|
||||
{nextMatch.map}
|
||||
</span>
|
||||
<MetaDot />
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<Users className="size-4" aria-hidden="true" />
|
||||
<CapacityMeter
|
||||
current={nextMatch.participants.length}
|
||||
max={nextMatch.maxParticipants}
|
||||
onInk
|
||||
/>
|
||||
</span>
|
||||
</>
|
||||
}
|
||||
description={nextMatch.description || undefined}
|
||||
actions={
|
||||
<Button
|
||||
label={
|
||||
nextMatch.status === 'recruiting'
|
||||
? '참가 신청하러 가기'
|
||||
: '내전 보기'
|
||||
}
|
||||
variant="primary"
|
||||
size="lg"
|
||||
href={`/match/${nextMatch.id}`}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<PlainPage className="lts-overview space-y-5 pt-5 pb-16 sm:pt-6">
|
||||
{showArchive ? (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<h1 className="text-2xl font-bold">전체 내전 일정</h1>
|
||||
<Link to="/" className="text-sm font-semibold hover:underline">
|
||||
내전 홈
|
||||
</Link>
|
||||
</div>
|
||||
) : upcomingMatchesQuery.isLoading ? (
|
||||
<h1 className="text-sm text-content-muted" aria-busy="true">
|
||||
내전 일정을 불러오는 중
|
||||
</h1>
|
||||
) : upcomingMatchesQuery.isError && !upcomingMatchesQuery.data ? (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="text-sm text-content-muted">
|
||||
내전 일정을 불러오지 못했습니다
|
||||
</h1>
|
||||
<button
|
||||
type="button"
|
||||
className="min-h-8 text-sm font-semibold underline"
|
||||
onClick={() => void upcomingMatchesQuery.refetch()}
|
||||
>
|
||||
다시 시도
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<PageHero
|
||||
eyebrow={communityName}
|
||||
title="예정된 내전이 없습니다"
|
||||
meta="새 내전이 열리면 이곳에 가장 먼저 표시됩니다."
|
||||
actions={
|
||||
<Button
|
||||
label="내전 전적 보기"
|
||||
variant="primary"
|
||||
size="lg"
|
||||
href={statsPath}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<NextMatch match={nextMatch} />
|
||||
)}
|
||||
|
||||
<PageBody className="space-y-5">
|
||||
{upcomingCards.length > 0 && (
|
||||
<Panel>
|
||||
<PanelHeader title="이어지는 내전" count={upcomingCards.length} />
|
||||
<ul className="grid divide-y divide-line sm:grid-cols-3 sm:divide-x sm:divide-y-0">
|
||||
{upcomingCards.map((match) => (
|
||||
<li key={match.id} className="min-w-0">
|
||||
<Link
|
||||
to={`/match/${match.id}`}
|
||||
className="group block h-full px-4 py-4 transition-colors hover:bg-sunken sm:px-5"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<h3 className="min-w-0 truncate text-[15px] font-bold text-content group-hover:text-primary">
|
||||
{match.title}
|
||||
</h3>
|
||||
<StatusPill status={match.status} />
|
||||
</div>
|
||||
<p className="mt-2 text-[13px] text-content-muted">
|
||||
{match.date} {match.time}
|
||||
</p>
|
||||
<div className="mt-1 flex items-center gap-2 text-[13px] text-content-subtle">
|
||||
<span>{match.map}</span>
|
||||
<MetaDot />
|
||||
<CapacityMeter
|
||||
current={match.participants.length}
|
||||
max={match.maxParticipants}
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Panel>
|
||||
)}
|
||||
{!showArchive && upcomingMatches.length > 0 && (
|
||||
<UpcomingMatches matches={upcomingMatches} />
|
||||
)}
|
||||
|
||||
<Panel aria-busy={isHistoryPageLoading} aria-live="polite">
|
||||
<PanelHeader
|
||||
title="지난 내전"
|
||||
count={historyTotal > 0 ? historyTotal : undefined}
|
||||
actions={
|
||||
<Link
|
||||
to={statsPath}
|
||||
className="inline-flex items-center gap-0.5 text-[13px] font-semibold text-primary hover:underline"
|
||||
>
|
||||
전적·순위 보기
|
||||
<ChevronRight className="size-4" aria-hidden="true" />
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
{isHistoryPageLoading ? (
|
||||
<HistoryRecordsSkeleton rows={HISTORY_MATCH_PAGE_SIZE} />
|
||||
) : hasHistoryError ? (
|
||||
<div className="p-4">
|
||||
<ErrorNote
|
||||
title="지난 내전 기록을 불러오지 못했습니다"
|
||||
action={
|
||||
<Button
|
||||
label="다시 시도"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => void historyMatchesQuery.refetch()}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* 데스크톱: 표 */}
|
||||
<div className="hidden overflow-x-auto md:block">
|
||||
<table className="lts-table table-fixed">
|
||||
<HistoryTableColGroup />
|
||||
<HistoryTableHeader />
|
||||
<tbody>
|
||||
{historyMatches.length > 0 ? (
|
||||
historyMatches.map((match) => (
|
||||
<tr
|
||||
key={match.id}
|
||||
className="transition-colors hover:bg-sunken"
|
||||
>
|
||||
<td className="tabular whitespace-nowrap text-[13px] text-content-muted">
|
||||
{match.compactDateTime || match.date}
|
||||
</td>
|
||||
<td>
|
||||
<Link
|
||||
to={`/match/${match.id}`}
|
||||
className="block truncate font-semibold text-content hover:text-primary"
|
||||
>
|
||||
{match.title}
|
||||
</Link>
|
||||
</td>
|
||||
<td>
|
||||
<StatusPill status={match.rawStatus} />
|
||||
</td>
|
||||
<td className="truncate text-[13px] text-content-muted">
|
||||
{match.map}
|
||||
</td>
|
||||
<td className="tabular whitespace-nowrap text-right text-[13px] text-content-muted">
|
||||
{match.participants.length}명
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={5}>
|
||||
<EmptyNote
|
||||
size="sm"
|
||||
title="아직 내전 기록이 없습니다."
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* 모바일: 목록 */}
|
||||
<div className="divide-y divide-line md:hidden">
|
||||
{historyMatches.length > 0 ? (
|
||||
historyMatches.map((match) => (
|
||||
<Link
|
||||
key={match.id}
|
||||
to={`/match/${match.id}`}
|
||||
className="block px-4 py-3 transition-colors hover:bg-sunken"
|
||||
>
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="tabular text-xs text-content-subtle">
|
||||
{match.compactDateTime ||
|
||||
`${match.date} ${match.time}`}
|
||||
</div>
|
||||
<div className="mt-0.5 break-words text-[15px] font-semibold leading-snug text-content">
|
||||
{match.title}
|
||||
</div>
|
||||
</div>
|
||||
<StatusPill status={match.rawStatus} />
|
||||
</div>
|
||||
<div className="mt-1.5 flex items-center gap-2 text-xs text-content-subtle">
|
||||
<span>{match.map}</span>
|
||||
<MetaDot />
|
||||
<span>{match.participants.length}명</span>
|
||||
</div>
|
||||
</Link>
|
||||
))
|
||||
) : (
|
||||
<EmptyNote size="sm" title="아직 내전 기록이 없습니다." />
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{!hasHistoryError && historyTotal > 0 && (
|
||||
<HistoryPagination
|
||||
page={historyPage}
|
||||
pageCount={historyPageCount}
|
||||
total={historyTotal}
|
||||
isFetching={historyMatchesQuery.isFetching}
|
||||
onPrevious={goToPreviousHistoryPage}
|
||||
onNext={goToNextHistoryPage}
|
||||
<Panel aria-busy={isHistoryPageLoading} aria-live="polite">
|
||||
<PanelHeader
|
||||
title={showArchive ? '지난 일정 전체' : '최근 내전 일정'}
|
||||
actions={
|
||||
<Link
|
||||
to={statsPath}
|
||||
className="inline-flex items-center gap-0.5 text-[13px] font-semibold text-content-muted hover:text-content hover:underline"
|
||||
>
|
||||
전적 검색
|
||||
<ChevronRight className="size-4" aria-hidden="true" />
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
{isHistoryPageLoading ? (
|
||||
<HistoryRecordsSkeleton limit={historyLimit} />
|
||||
) : hasHistoryError ? (
|
||||
<div className="p-4">
|
||||
<ErrorNote
|
||||
title="지난 내전 기록을 불러오지 못했습니다"
|
||||
action={
|
||||
<Button
|
||||
label="다시 시도"
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => void historyMatchesQuery.refetch()}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Panel>
|
||||
</PageBody>
|
||||
</>
|
||||
</div>
|
||||
) : (
|
||||
<HistoryRecords matches={historyMatchesQuery.data?.matches ?? []} />
|
||||
)}
|
||||
{showArchive && !hasHistoryError && historyTotal > 0 && (
|
||||
<HistoryPagination
|
||||
page={historyPage}
|
||||
pageCount={historyPageCount}
|
||||
total={historyTotal}
|
||||
isFetching={historyMatchesQuery.isFetching}
|
||||
onPrevious={() => setHistoryPage(Math.max(1, historyPage - 1))}
|
||||
onNext={() => setHistoryPage(historyPage + 1)}
|
||||
/>
|
||||
)}
|
||||
{!showArchive && historyTotal > HOME_HISTORY_LIMIT && (
|
||||
<div className="border-t border-line px-4 py-2.5 text-right sm:px-5">
|
||||
<Link
|
||||
to="/?history=all"
|
||||
className="text-sm text-content-muted hover:underline"
|
||||
>
|
||||
전체 일정 기록
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</Panel>
|
||||
</PlainPage>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user