This commit is contained in:
dahyeon committed 2026-04-24 23:18:56 -07:00
1 parent 30dfb7ce58
commit 5af2c80cd1
33 files changed
+3806 -1440

No files matched your search

+343 -176
View File
@@ -1,23 +1,28 @@
import { useParams, Link } from "react-router";
import { useEffect, useState } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Link, useNavigate, useParams } from 'react-router';
import { useAuction, useMatch, useMe } from '../api/hooks';
import {
getMatchById,
positionLabel,
positionIcon,
type MatchDetail,
type Participant,
type Position,
type Team,
type TierInfo,
} from "../mock";
buildDefaultPreferredPositions,
formatTierLabel,
getTierColorToken,
mapApiMatchToMatchDetail,
type MatchDetailView,
type ParticipantView,
type TeamView,
} from '../api/mappers';
import { DEFAULT_COMMUNITY_ID, useAuthUserId } from '../config';
import { apiFetch, ApiError } from '../lib/api';
import { positionIcon, positionLabel } from '../lib/league';
import type { Position } from '../api/types';
// -- 포지션 배지 --
function PosBadge({ pos, sub }: { pos: Position; sub?: boolean }) {
return (
<span
className={`inline-flex items-center gap-1.5 text-[11px] font-medium px-1.5 py-0.5 border ${
sub
? "border-base-content/8 text-base-content/35 bg-transparent"
: "border-primary/20 text-primary bg-primary/5"
? 'border-base-content/8 text-base-content/35 bg-transparent'
: 'border-primary/20 text-primary bg-primary/5'
}`}
>
<img
@@ -30,63 +35,60 @@ function PosBadge({ pos, sub }: { pos: Position; sub?: boolean }) {
);
}
// -- 티어 색상 --
function tierColor(tier: string): string {
if (tier.startsWith("챌린저")) return "text-amber-400";
if (tier.startsWith("그랜드마스터")) return "text-red-400";
if (tier.startsWith("마스터")) return "text-purple-400";
if (tier.startsWith("다이아")) return "text-cyan-400";
if (tier.startsWith("에메랄드")) return "text-emerald-400";
if (tier.startsWith("플래티넘")) return "text-teal-300";
if (tier.startsWith("골드")) return "text-yellow-400";
if (tier.startsWith("실버")) return "text-gray-300";
return "text-amber-700";
}
function TierCell({ participant }: { participant: ParticipantView }) {
if (!participant.tier) {
return (
<div className="text-[11px] text-base-content/25 whitespace-nowrap">
티어 정보 없음
</div>
);
}
// -- 티어 셀 (전시즌 / 현재 / 최고) --
function TierCell({ tier }: { tier: TierInfo }) {
return (
<div className="flex items-center gap-1.5 text-[11px] whitespace-nowrap">
<span className="text-base-content/25">{tier.previousSeason}</span>
<span className="text-base-content/15">→</span>
<span className={`font-bold ${tierColor(tier.current)}`}>
{tier.current}
</span>
<span className={`text-[10px] ${tierColor(tier.peak)} opacity-50`}>
({tier.peak})
<span className={`font-bold ${getTierColorToken(participant.tier)}`}>
{formatTierLabel(participant.tier)}
</span>
{participant.tier.leaguePoints > 0 && (
<span className="text-base-content/25">
{participant.tier.leaguePoints}LP
</span>
)}
</div>
);
}
// -- 상태 배지 --
function statusBadge(status: MatchDetail["status"]) {
function statusBadge(status: MatchDetailView['status']) {
switch (status) {
case "recruiting":
case 'recruiting':
return {
label: "모집 중",
cls: "bg-green-500/15 text-green-500 border-green-500/20",
label: '모집 중',
cls: 'bg-green-500/15 text-green-500 border-green-500/20',
};
case "team-built":
case 'team-built':
return {
label: "팀빌딩 완료",
cls: "bg-amber-500/15 text-amber-500 border-amber-500/20",
label: '팀빌딩 완료',
cls: 'bg-amber-500/15 text-amber-500 border-amber-500/20',
};
case "finished":
case 'in-progress':
return {
label: "종료",
cls: "bg-base-content/8 text-base-content/40 border-base-content/10",
label: '진행 중',
cls: 'bg-blue-500/15 text-blue-400 border-blue-500/20',
};
case 'finished':
return {
label: '종료',
cls: 'bg-base-content/8 text-base-content/40 border-base-content/10',
};
}
}
// -- 참가자 행 --
function ParticipantRow({
p,
participant,
index,
assignedPos,
}: {
p: Participant;
participant: ParticipantView;
index: number;
assignedPos?: Position;
}) {
@@ -99,7 +101,7 @@ function ParticipantRow({
<div className="flex items-center gap-2">
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
<img
src={`https://ddragon.leagueoflegends.com/cdn/16.7.1/img/profileicon/${p.profileIconId}.png`}
src={`https://ddragon.leagueoflegends.com/cdn/16.7.1/img/profileicon/${participant.profileIconId}.png`}
alt=""
className="w-full h-full object-cover"
loading="lazy"
@@ -107,16 +109,16 @@ function ParticipantRow({
</div>
<div className="min-w-0">
<span className="font-medium text-[13px] text-base-content truncate block leading-tight">
{p.summonerName}
{participant.summonerName}
</span>
<span className="text-[10px] text-base-content/25 leading-tight">
#{p.tag}
#{participant.tag}
</span>
</div>
</div>
</td>
<td className="py-2 px-3">
<TierCell tier={p.tier} />
<TierCell participant={participant} />
</td>
{assignedPos ? (
<td className="py-2 px-3">
@@ -125,10 +127,10 @@ function ParticipantRow({
) : (
<>
<td className="py-2 px-3">
<PosBadge pos={p.mainPosition} />
<PosBadge pos={participant.mainPosition} />
</td>
<td className="py-2 px-3">
<PosBadge pos={p.subPosition} sub />
<PosBadge pos={participant.subPosition} sub />
</td>
</>
)}
@@ -136,58 +138,90 @@ function ParticipantRow({
);
}
// -- 참가자 테이블 (팀빌딩 전) --
function ParticipantTable({ participants }: { participants: Participant[] }) {
function ParticipantTable({
participants,
maxParticipants,
joined,
canJoin,
onJoin,
isJoining,
}: {
participants: ParticipantView[];
maxParticipants: number;
joined: boolean;
canJoin: boolean;
onJoin: () => void;
isJoining: boolean;
}) {
return (
<div className="overflow-x-auto">
<table className="w-full text-left">
<thead>
<tr className="border-b border-base-content/10 bg-base-200/40 text-[11px] uppercase tracking-wider text-base-content/35 font-semibold">
<th className="py-2 px-3 w-8">#</th>
<th className="py-2 px-3">소환사</th>
<th className="py-2 px-3">전 시즌 → 현재 (최고)</th>
<th className="py-2 px-3">주 포지션</th>
<th className="py-2 px-3">부 포지션</th>
</tr>
</thead>
<tbody>
{participants.map((p, i) => (
<ParticipantRow key={p.id} p={p} index={i} />
))}
</tbody>
</table>
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
<div className="px-4 py-2.5 border-b border-base-content/10 bg-base-200/40 flex items-center justify-between gap-3">
<h3 className="text-[11px] font-bold uppercase tracking-wider text-base-content/40">
참가자 ({participants.length}/{maxParticipants})
</h3>
<button
type="button"
onClick={onJoin}
disabled={!canJoin || joined || isJoining}
className="btn btn-primary btn-xs px-4 text-[11px] font-semibold disabled:opacity-40"
>
{joined ? '참가 완료' : isJoining ? '신청 중...' : '참가 신청'}
</button>
</div>
<div className="overflow-x-auto">
<table className="w-full text-left">
<thead>
<tr className="border-b border-base-content/10 bg-base-200/40 text-[11px] uppercase tracking-wider text-base-content/35 font-semibold">
<th className="py-2 px-3 w-8">#</th>
<th className="py-2 px-3">소환사</th>
<th className="py-2 px-3">현재 티어</th>
<th className="py-2 px-3">주 포지션</th>
<th className="py-2 px-3">부 포지션</th>
</tr>
</thead>
<tbody>
{participants.map((participant, index) => (
<ParticipantRow
key={participant.id}
participant={participant}
index={index}
/>
))}
</tbody>
</table>
</div>
{participants.length < maxParticipants && (
<div className="px-4 py-2.5 border-t border-base-content/5 text-center bg-base-200/20">
<span className="text-[11px] text-base-content/25">
{maxParticipants - participants.length}자리 남음
</span>
</div>
)}
</div>
);
}
// -- 팀 카드 (팀빌딩 후) --
function TeamCard({
team,
side,
isWinner,
}: {
team: Team;
side: "blue" | "red";
team: TeamView;
isWinner?: boolean;
}) {
const borderColor =
side === "blue" ? "border-blue-500/25" : "border-red-500/25";
const headerBg = side === "blue" ? "bg-blue-500/8" : "bg-red-500/8";
const sideColor = side === "blue" ? "text-blue-400" : "text-red-400";
const accentBar = side === "blue" ? "bg-blue-500" : "bg-red-500";
team.side === 'blue' ? 'border-blue-500/25' : 'border-red-500/25';
const headerBg = team.side === 'blue' ? 'bg-blue-500/8' : 'bg-red-500/8';
const sideColor = team.side === 'blue' ? 'text-blue-400' : 'text-red-400';
const accentBar = team.side === 'blue' ? 'bg-blue-500' : 'bg-red-500';
return (
<div
className={`border ${borderColor} overflow-hidden bg-base-100 relative`}
>
<div className={`border ${borderColor} overflow-hidden bg-base-100 relative`}>
<div className={`absolute left-0 top-0 bottom-0 w-0.5 ${accentBar}`} />
<div
className={`${headerBg} px-4 py-2 flex items-center justify-between border-b ${borderColor}`}
>
<div className="flex items-center gap-2">
<span
className={`text-xs font-bold uppercase tracking-wide ${sideColor}`}
>
<span className={`text-xs font-bold uppercase tracking-wide ${sideColor}`}>
{team.name}
</span>
{isWinner && (
@@ -202,17 +236,17 @@ function TeamCard({
<tr className="border-b border-base-content/8 bg-base-200/30 text-[11px] uppercase tracking-wider text-base-content/35 font-semibold">
<th className="py-2 px-3 w-8">#</th>
<th className="py-2 px-3">소환사</th>
<th className="py-2 px-3">전 시즌 → 현재 (최고)</th>
<th className="py-2 px-3">현재 티어</th>
<th className="py-2 px-3">포지션</th>
</tr>
</thead>
<tbody>
{team.participants.map((p, i) => (
{team.participants.map((participant, index) => (
<ParticipantRow
key={p.id}
p={p}
index={i}
assignedPos={p.assignedPosition}
key={participant.id}
participant={participant}
index={index}
assignedPos={participant.assignedPosition}
/>
))}
</tbody>
@@ -221,7 +255,6 @@ function TeamCard({
);
}
// -- 사이드바 카드 --
function SideCard({
title,
children,
@@ -241,12 +274,95 @@ function SideCard({
);
}
// -- 메인 --
export default function MatchDetailPage() {
const { id } = useParams();
const match = getMatchById(Number(id));
const navigate = useNavigate();
const queryClient = useQueryClient();
const authUserId = useAuthUserId();
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
const meQuery = useMe();
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
const [blueCaptainUserId, setBlueCaptainUserId] = useState('');
const [redCaptainUserId, setRedCaptainUserId] = useState('');
if (!match) {
const joinMatchMutation = useMutation({
mutationFn: () =>
apiFetch(`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/participants`, {
method: 'POST',
body: JSON.stringify({
preferredPositions:
meQuery.data?.user?.preferredPositions.length
? meQuery.data.user.preferredPositions.slice(0, 5)
: buildDefaultPreferredPositions(),
}),
}),
onSuccess: async () => {
await Promise.all([
queryClient.invalidateQueries({
queryKey: ['match', DEFAULT_COMMUNITY_ID, id ?? null],
}),
queryClient.invalidateQueries({
queryKey: ['matches', DEFAULT_COMMUNITY_ID],
}),
]);
},
});
const startAuctionMutation = useMutation({
mutationFn: () =>
apiFetch(`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/auction`, {
method: 'POST',
body: JSON.stringify({
captains: [
{ side: 'blue', userId: blueCaptainUserId },
{ side: 'red', userId: redCaptainUserId },
],
initialPoints: 1000,
maxTimerSeconds: 30,
}),
}),
onSuccess: async () => {
await Promise.all([
queryClient.invalidateQueries({
queryKey: ['match', DEFAULT_COMMUNITY_ID, id ?? null],
}),
queryClient.invalidateQueries({
queryKey: ['auction', DEFAULT_COMMUNITY_ID, id ?? null],
}),
]);
navigate(`/match/${id}/auction`);
},
});
useEffect(() => {
const participants = matchQuery.data?.participants ?? [];
if (!blueCaptainUserId && participants[0]) {
setBlueCaptainUserId(participants[0].userId);
}
if (!redCaptainUserId && participants[1]) {
setRedCaptainUserId(participants[1].userId);
}
}, [blueCaptainUserId, redCaptainUserId, matchQuery.data?.participants]);
if (!DEFAULT_COMMUNITY_ID) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<span className="text-sm text-amber-600">
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
</span>
</main>
);
}
if (matchQuery.isLoading) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<span className="text-sm text-base-content/40">매치 정보를 불러오는 중...</span>
</main>
);
}
if (matchQuery.error || !matchQuery.data) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<h2 className="text-lg font-bold mb-2">내전을 찾을 수 없습니다</h2>
@@ -257,11 +373,24 @@ export default function MatchDetailPage() {
);
}
const match = mapApiMatchToMatchDetail(matchQuery.data);
const si = statusBadge(match.status);
const canManageAuction =
meQuery.data?.user?.role === 'owner' || meQuery.data?.user?.role === 'admin';
const auctionNotStarted =
auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404;
const showAuctionLink = Boolean(auctionQuery.data);
const canStartAuction =
canManageAuction &&
match.status === 'recruiting' &&
matchQuery.data.participants.length >= 2 &&
auctionNotStarted &&
blueCaptainUserId &&
redCaptainUserId &&
blueCaptainUserId !== redCaptainUserId;
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
{/* 뒤로가기 */}
<Link
to="/"
className="inline-flex items-center gap-1 text-xs text-base-content/40 hover:text-base-content transition-colors mb-5"
@@ -283,7 +412,6 @@ export default function MatchDetailPage() {
목록으로
</Link>
{/* 헤더 */}
<div className="mb-6 pb-5 border-b border-base-content/8">
<div className="flex items-center gap-2.5 flex-wrap mb-2">
<h1 className="text-xl sm:text-2xl font-bold text-base-content leading-tight">
@@ -295,43 +423,11 @@ export default function MatchDetailPage() {
{si.label}
</span>
</div>
<p className="text-sm text-base-content/50 mb-2.5">
{match.description}
</p>
<p className="text-sm text-base-content/50 mb-2.5">{match.description}</p>
<div className="flex items-center gap-3 text-xs text-base-content/40 flex-wrap">
<span className="flex items-center gap-1">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-3.5 w-3.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
{match.date} {match.time}
</span>
<span>{match.date} {match.time}</span>
<span className="text-base-content/15">|</span>
<span className="flex items-center gap-1">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-3.5 w-3.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"
/>
</svg>
<span>
{match.participants.length}/{match.maxParticipants}명
</span>
<span className="text-base-content/15">|</span>
@@ -341,12 +437,23 @@ export default function MatchDetailPage() {
</div>
</div>
{/* 결과 배너 (종료된 경우) */}
{match.status === "finished" && match.result && (
{joinMatchMutation.error instanceof Error && (
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
{joinMatchMutation.error.message}
</div>
)}
{startAuctionMutation.error instanceof Error && (
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
{startAuctionMutation.error.message}
</div>
)}
{match.status === 'finished' && match.result && (
<div className="mb-6 border border-base-content/10 bg-base-content/[0.02] p-5">
<div className="flex items-center justify-center gap-8">
<div
className={`text-center ${match.result.winner === "블루팀" ? "text-blue-400" : "text-blue-400/30"}`}
className={`text-center ${match.result.winner === '블루팀' ? 'text-blue-400' : 'text-blue-400/30'}`}
>
<div className="text-3xl font-black tabular-nums">
{match.result.blueScore}
@@ -359,7 +466,7 @@ export default function MatchDetailPage() {
VS
</div>
<div
className={`text-center ${match.result.winner === "레드팀" ? "text-red-400" : "text-red-400/30"}`}
className={`text-center ${match.result.winner === '레드팀' ? 'text-red-400' : 'text-red-400/30'}`}
>
<div className="text-3xl font-black tabular-nums">
{match.result.redScore}
@@ -376,70 +483,131 @@ export default function MatchDetailPage() {
)}
<div className="flex flex-col lg:flex-row gap-5">
{/* 좌측: 참가자 / 팀 */}
<div className="flex-1 min-w-0">
{match.status === "recruiting" ? (
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
<div className="px-4 py-2.5 border-b border-base-content/10 bg-base-200/40 flex items-center justify-between">
<h3 className="text-[11px] font-bold uppercase tracking-wider text-base-content/40">
참가자 ({match.participants.length}/{match.maxParticipants})
</h3>
<button className="btn btn-primary btn-xs px-4 text-[11px] font-semibold">
참가 신청
</button>
</div>
<ParticipantTable participants={match.participants} />
{match.participants.length < match.maxParticipants && (
<div className="px-4 py-2.5 border-t border-base-content/5 text-center bg-base-200/20">
<span className="text-[11px] text-base-content/25">
{match.maxParticipants - match.participants.length}자리 남음
</span>
<div className="flex-1 min-w-0 space-y-4">
{match.status === 'recruiting' ? (
<>
<ParticipantTable
participants={match.participants}
maxParticipants={match.maxParticipants}
joined={match.joined}
canJoin={Boolean(authUserId)}
onJoin={() => joinMatchMutation.mutate()}
isJoining={joinMatchMutation.isPending}
/>
{canManageAuction && (
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
<div>
<h3 className="text-[11px] font-bold uppercase tracking-wider text-base-content/40">
경매 시작
</h3>
<p className="mt-1 text-xs text-base-content/40">
두 팀장을 선택하면 경매를 시작할 수 있습니다.
</p>
</div>
{showAuctionLink ? (
<Link to={`/match/${match.id}/auction`} className="btn btn-primary btn-sm px-5 text-xs">
경매 페이지 열기
</Link>
) : (
<div className="grid sm:grid-cols-2 gap-3">
<label className="text-xs text-base-content/45">
블루팀 팀장
<select
className="mt-1 w-full border border-base-content/10 bg-transparent px-2 py-2 text-sm"
value={blueCaptainUserId}
onChange={(event) => setBlueCaptainUserId(event.target.value)}
>
<option value="">선택하세요</option>
{matchQuery.data.participants.map((participant) => (
<option key={`blue-${participant.userId}`} value={participant.userId}>
{participant.gameName ?? participant.userId}
</option>
))}
</select>
</label>
<label className="text-xs text-base-content/45">
레드팀 팀장
<select
className="mt-1 w-full border border-base-content/10 bg-transparent px-2 py-2 text-sm"
value={redCaptainUserId}
onChange={(event) => setRedCaptainUserId(event.target.value)}
>
<option value="">선택하세요</option>
{matchQuery.data.participants.map((participant) => (
<option key={`red-${participant.userId}`} value={participant.userId}>
{participant.gameName ?? participant.userId}
</option>
))}
</select>
</label>
<div className="sm:col-span-2 flex items-center gap-3">
<button
type="button"
className="btn btn-primary btn-sm px-5 text-xs"
disabled={!canStartAuction || startAuctionMutation.isPending}
onClick={() => startAuctionMutation.mutate()}
>
{startAuctionMutation.isPending ? '시작 중...' : '경매 시작'}
</button>
{!authUserId && (
<span className="text-xs text-amber-600">
Dev Auth에 owner/admin User ID를 먼저 입력해주세요.
</span>
)}
</div>
</div>
)}
</div>
)}
</div>
</>
) : (
<div className="space-y-4">
{match.teams?.map((team, i) => (
{match.teams.map((team) => (
<TeamCard
key={team.name}
key={team.side}
team={team}
side={i === 0 ? "blue" : "red"}
isWinner={
match.status === "finished"
match.status === 'finished'
? match.result?.winner === team.name
: undefined
}
/>
))}
{showAuctionLink && (
<div className="flex justify-end">
<Link to={`/match/${match.id}/auction`} className="btn btn-primary btn-sm px-5 text-xs">
경매 페이지 열기
</Link>
</div>
)}
</div>
)}
</div>
{/* 우측: 사이드바 */}
<div className="w-full lg:w-64 shrink-0 space-y-4">
{/* 일정 */}
{match.schedule && match.schedule.length > 0 && (
{match.schedule.length > 0 && (
<SideCard title="일정">
<ul className="space-y-2">
{match.schedule.map((s, i) => (
<li key={i} className="flex items-start gap-2.5 text-[13px]">
{match.schedule.map((item, index) => (
<li key={index} className="flex items-start gap-2.5 text-[13px]">
<span className="font-mono text-[11px] text-base-content/30 w-11 shrink-0 pt-px">
{s.time}
{item.time}
</span>
<span className="text-base-content/60">{s.label}</span>
<span className="text-base-content/60">{item.label}</span>
</li>
))}
</ul>
</SideCard>
)}
{/* 상품 */}
{match.prizes && match.prizes.length > 0 && (
{match.prizes.length > 0 && (
<SideCard title="상품">
<ul className="space-y-1.5">
{match.prizes.map((prize, i) => (
{match.prizes.map((prize, index) => (
<li
key={i}
key={index}
className="flex items-start gap-2 text-[13px] text-base-content/60"
>
<span className="text-amber-400 shrink-0 text-xs">▸</span>
@@ -450,13 +618,12 @@ export default function MatchDetailPage() {
</SideCard>
)}
{/* 안내사항 */}
{match.notices && match.notices.length > 0 && (
{match.notices.length > 0 && (
<SideCard title="안내사항">
<ul className="space-y-1.5">
{match.notices.map((notice, i) => (
{match.notices.map((notice, index) => (
<li
key={i}
key={index}
className="flex items-start gap-2 text-[13px] text-base-content/60"
>
<span className="text-base-content/20 shrink-0">•</span>