import { useState } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { Link } from 'react-router'; import { mapApiMatchToMatchDetail } from '../api/mappers'; import { useMatches, useMatchesPage, useMe } from '../api/hooks'; import { DEFAULT_COMMUNITY_ID } from '../config'; const UPCOMING_GRID_MATCH_LIMIT = 3; const UPCOMING_MATCH_LIST_LIMIT = UPCOMING_GRID_MATCH_LIMIT + 1; const HISTORY_MATCH_PAGE_SIZE = 10; const EMPTY_SCHEDULE_TEXT = '예정된 매치가 없습니다.'; const HISTORY_TABLE_ROW_CLASS = 'h-10 border-b border-base-content/5 last:border-b-0'; const SECTION_HEADING_CLASS = 'text-xs font-bold text-base-content/40 uppercase tracking-widest'; const ADMIN_LINK_CLASS = 'text-xs font-bold text-base-content/35 hover:text-primary'; const STATS_LINK_CLASS = 'text-xs font-bold text-primary hover:underline'; const STATUS_BADGE_CLASS = 'inline-flex items-center whitespace-nowrap text-xs font-semibold px-1.5 py-0.5 border'; const MAP_BADGE_CLASS = 'inline-flex items-center whitespace-nowrap text-xs px-1.5 py-0.5 border'; const NEXT_MATCH_TITLE_CLASS = 'text-xl sm:text-2xl font-bold text-base-content leading-tight'; const NEXT_MATCH_DESCRIPTION_CLASS = 'text-sm text-base-content/50 max-w-xl leading-relaxed'; const NEXT_MATCH_META_CLASS = 'flex items-center gap-3 text-xs text-base-content/40 flex-wrap'; const NEXT_MATCH_PARTICIPANT_BADGE_CLASS = 'inline-flex items-center whitespace-nowrap bg-accent text-accent-content px-1.5 py-0.5 font-semibold'; const DETAIL_BUTTON_CLASS = 'btn btn-secondary btn-sm px-6 text-xs font-semibold'; const UPCOMING_CARD_FRAME_CLASS = 'bg-base-100 h-full p-4 min-h-[135px]'; const UPCOMING_CARD_TITLE_CLASS = 'text-sm font-bold text-base-content truncate mr-2'; const UPCOMING_CARD_META_CLASS = 'space-y-1 text-xs text-base-content/40'; const HISTORY_MOBILE_DATE_CLASS = 'text-xs font-medium text-base-content/40'; const HISTORY_MOBILE_TITLE_CLASS = 'mt-1 text-sm font-semibold leading-snug text-base-content break-words'; const HISTORY_MOBILE_META_CLASS = 'flex flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-base-content/45'; function SkeletonText({ children, className = '', skeletonClassName, }: { children: string; className?: string; skeletonClassName: string; }) { return ( {children} ); } function SkeletonBadge({ children, className, }: { children: string; className: string; }) { return ( {children} ); } function HistoryTableColGroup() { return ( ); } function HistoryTableHeader() { return ( 날짜 내전 상태 맵 참가 결과 ); } function HistoryRecordsSkeleton({ rows = HISTORY_MATCH_PAGE_SIZE, }: { rows?: number; }) { const historySkeletons = Array.from({ length: rows }); return ( <>
{historySkeletons.map((_, index) => ( ))}
2026년 6월 8일 월 정기 내전 팀빌딩 소환사의 협곡 10명 1팀 승리
{historySkeletons.map((_, index) => (
6/8 (월) 21:00 정기 내전
팀빌딩
소환사의 협곡 · 10명 · 1팀 승리
))}
); } function HomePageSkeleton() { const upcomingSkeletons = Array.from({ length: UPCOMING_GRID_MATCH_LIMIT }); return (
매치 목록을 불러오는 중...

다음 내전

내전 전적 보기
롤림푸스 경매 테스트 매치 모집중
Socket.IO 경매 페이지 검증용으로 생성된 매치입니다.
6월 11일 21:00 | 10/10명 | 소환사의 협곡
상세 보기

예정된 내전

{upcomingSkeletons.map((_, index) => (
정기 내전 모집중
6월 11일 21:00 10/10명
소환사의 협곡
))}

지난 내전 기록

); } function StatusBadge({ status }: { status: string }) { const styles: Record = { 모집중: 'bg-green-500/15 text-green-500 border-green-500/20', 팀빌딩: 'bg-amber-500/15 text-amber-500 border-amber-500/20', 진행중: 'bg-blue-500/15 text-blue-400 border-blue-500/20', 종료: 'bg-base-content/8 text-base-content/40 border-base-content/10', }; return ( {status} ); } function MapBadge({ map }: { map: string }) { return ( {map} ); } function getStatusLabel(status: string) { switch (status) { case 'recruiting': return '모집중'; case 'team-built': return '팀빌딩'; case 'in-progress': return '진행중'; case 'finished': return '종료'; default: return status; } } 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 HistoryMetaText({ map, participants, }: { map: string; participants: number; }) { return (
{map} · {participants}명
); } interface HistoryPaginationProps { page: number; pageCount: number; total: number; isFetching: boolean; onPrevious: () => void; onNext: () => void; } function HistoryPagination({ page, pageCount, total, isFetching, onPrevious, onNext, }: HistoryPaginationProps) { const hasPrevious = page > 1; const hasNext = page < pageCount; return (
총 {total}개 · {page}/{pageCount}페이지
); } export default function HomePage() { const [timelineNow] = useState(() => new Date().toISOString()); const [historyPage, setHistoryPage] = useState(1); 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 meQuery = useMe(); if (!DEFAULT_COMMUNITY_ID) { return (
`apps/web/.env.development`의 `VITE_DEFAULT_COMMUNITY_ID`를 먼저 설정해주세요.
); } if (upcomingMatchesQuery.isLoading) { return ; } if (upcomingMatchesQuery.error) { return (
매치 목록을 불러오지 못했습니다.
); } const upcomingMatches = upcomingMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? []; const historyMatches = historyMatchesQuery.data?.matches.map((match) => ({ ...mapApiMatchToMatchDetail(match), compactDateTime: formatCompactDateTime(match.scheduledAt), })) ?? []; 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 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 = (nextMatch ? upcomingMatches.slice(1) : upcomingMatches ).slice(0, UPCOMING_GRID_MATCH_LIMIT); const currentUser = meQuery.data?.memberships.find( (membership) => membership.community?._id === DEFAULT_COMMUNITY_ID, )?.user ?? null; const canManage = currentUser?.role === 'owner' || currentUser?.role === 'admin'; return (

다음 내전

{canManage && ( 내전 관리 )} 내전 전적 보기
{nextMatch ? (

{nextMatch.title}

{nextMatch.description}

{nextMatch.date} {nextMatch.time} | {nextMatch.participants.length}/{nextMatch.maxParticipants}명 |
상세 보기
) : (
{EMPTY_SCHEDULE_TEXT}
)}

예정된 내전

{upcomingCards.length > 0 ? ( upcomingCards.map((match) => (

{match.title}

{match.date} {match.time}
{match.participants.length}/{match.maxParticipants}명
)) ) : (
{EMPTY_SCHEDULE_TEXT}
)}

지난 내전 기록

{isHistoryPageLoading ? ( ) : hasHistoryError ? (
지난 내전 기록을 불러오지 못했습니다.
) : ( <> {/* 데스크톱: 테이블 */}
{historyMatches.length > 0 ? ( historyMatches.map((match) => ( )) ) : ( )}
{match.date} {match.title} {match.participants.length}명 공식 결과
아직 내전 기록이 없습니다.
{/* 모바일: 카드 리스트 */}
{historyMatches.length > 0 ? ( historyMatches.map((match) => { return (
{match.compactDateTime || `${match.date} ${match.time}`}
{match.title}
); }) ) : (
아직 내전 기록이 없습니다.
)}
)} {!hasHistoryError && historyTotal > 0 && (
)}
); }