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

+313 -249
View File
@@ -1,89 +1,72 @@
import { useEffect, useRef, useState } from "react";
import { useParams, Link } from "react-router";
import { createMockAuction } from "../auction-mock";
import type {
AuctionState,
AuctionPlayer,
AuctionTeam,
} from "../auction-types";
import { positionIcon, positionLabel, type Position } from "../mock";
import { useEffect, useRef, useState } from 'react';
import { Link, useParams } from 'react-router';
import { useAuction, useMatch, useMe } from '../api/hooks';
import {
formatTierLabel,
getTierColorToken,
mapApiAuctionToAuctionState,
type AuctionStateView,
} from '../api/mappers';
import { useAuctionSocket } from '../api/useAuctionSocket';
import { DEFAULT_COMMUNITY_ID, setDevCaptainSide, useDevCaptainSide } from '../config';
import { ApiError } from '../lib/api';
import { positionIcon, positionLabel } from '../lib/league';
import type { Position } from '../api/types';
// -- 티어 색상 --
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 formatPoints(n: number): string {
return n.toLocaleString();
function formatPoints(value: number) {
return value.toLocaleString();
}
function PosBadge({ pos }: { pos: Position }) {
return (
<span className="inline-flex items-center gap-1.5 text-[11px] font-medium px-1.5 py-0.5 border border-primary/20 text-primary bg-primary/5">
<img
src={positionIcon[pos]}
alt=""
className="w-3.5 h-3.5 object-contain"
/>
<img src={positionIcon[pos]} alt="" className="w-3.5 h-3.5 object-contain" />
<span>{positionLabel[pos]}</span>
</span>
);
}
// -- 타이머 바 --
function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
const pct = (timer / maxTimer) * 100;
const pct = maxTimer > 0 ? (timer / maxTimer) * 100 : 0;
const urgent = timer <= 5;
return (
<div className="w-full h-1.5 bg-base-content/5">
<div
className={`h-full transition-all duration-1000 linear ${urgent ? "bg-red-500" : "bg-primary"}`}
className={`h-full transition-all duration-1000 linear ${urgent ? 'bg-red-500' : 'bg-primary'}`}
style={{ width: `${pct}%` }}
/>
</div>
);
}
// -- 팀 패널 --
function TeamPanel({
team,
isActive,
isLeft,
}: {
team: AuctionTeam;
team: AuctionStateView['teams'][number];
isActive: boolean;
isLeft: boolean;
}) {
const borderColor =
team.side === "blue" ? "border-blue-500/25" : "border-red-500/25";
const accentBar = team.side === "blue" ? "bg-blue-500" : "bg-red-500";
const sideColor = team.side === "blue" ? "text-blue-400" : "text-red-400";
const headerBg = team.side === "blue" ? "bg-blue-500/8" : "bg-red-500/8";
team.side === 'blue' ? 'border-blue-500/25' : 'border-red-500/25';
const accentBar = team.side === 'blue' ? 'bg-blue-500' : 'bg-red-500';
const sideColor = team.side === 'blue' ? 'text-blue-400' : 'text-red-400';
const headerBg = team.side === 'blue' ? 'bg-blue-500/8' : 'bg-red-500/8';
return (
<div
className={`border ${borderColor} bg-base-100 relative ${isActive ? "ring-1 ring-primary/30" : ""}`}
className={`border ${borderColor} bg-base-100 relative ${isActive ? 'ring-1 ring-primary/30' : ''}`}
>
<div
className={`absolute ${isLeft ? "left-0" : "right-0"} top-0 bottom-0 w-0.5 ${accentBar}`}
className={`absolute ${isLeft ? 'left-0' : 'right-0'} top-0 bottom-0 w-0.5 ${accentBar}`}
/>
{/* 헤더 */}
<div className={`${headerBg} px-3 py-2 border-b ${borderColor}`}>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<span
className={`text-[11px] font-bold uppercase tracking-wide ${sideColor}`}
>
{team.side === "blue" ? "블루팀" : "레드팀"}
<span className={`text-[11px] font-bold uppercase tracking-wide ${sideColor}`}>
{team.side === 'blue' ? '블루팀' : '레드팀'}
</span>
<span className="text-[10px] text-base-content/30">
팀장: {team.captainName}
@@ -95,18 +78,17 @@ function TeamPanel({
</div>
</div>
{/* 멤버 목록 */}
<div className="divide-y divide-base-content/5">
{team.members.length === 0 ? (
<div className="px-3 py-6 text-center text-[11px] text-base-content/20">
아직 멤버가 없습니다
</div>
) : (
team.members.map((m) => (
<div key={m.id} className="px-3 py-1.5 flex items-center gap-2">
team.members.map((member) => (
<div key={`${member.userId}-${member.assignedPosition}`} className="px-3 py-1.5 flex items-center gap-2">
<div className="w-6 h-6 bg-base-content/10 overflow-hidden shrink-0">
<img
src={`https://ddragon.leagueoflegends.com/cdn/16.7.1/img/profileicon/${m.profileIconId}.png`}
src={`https://ddragon.leagueoflegends.com/cdn/16.7.1/img/profileicon/${member.profileIconId}.png`}
alt=""
className="w-full h-full object-cover"
loading="lazy"
@@ -114,21 +96,20 @@ function TeamPanel({
</div>
<div className="flex-1 min-w-0">
<span className="text-[12px] font-medium text-base-content truncate block leading-tight">
{m.summonerName}
{member.summonerName}
</span>
</div>
<PosBadge pos={m.assignedPosition} />
<PosBadge pos={member.assignedPosition} />
<span className="text-[10px] text-amber-400/60 tabular-nums w-8 text-right">
{m.cost}
{member.cost}
</span>
</div>
))
)}
{/* 빈 슬롯 */}
{Array.from({ length: 4 - team.members.length }).map((_, i) => (
{Array.from({ length: Math.max(0, 4 - team.members.length) }).map((_, index) => (
<div
key={`empty-${i}`}
key={`empty-${team.side}-${index}`}
className="px-3 py-1.5 h-[34px] flex items-center"
>
<div className="w-6 h-6 border border-dashed border-base-content/8 shrink-0" />
@@ -140,18 +121,14 @@ function TeamPanel({
);
}
// -- 현재 경매 선수 카드 --
function PlayerSpotlight({
player,
phase,
currentBid,
currentBidder,
state,
}: {
player: AuctionPlayer;
phase: AuctionState["phase"];
currentBid: number;
currentBidder: "blue" | "red" | null;
state: AuctionStateView;
}) {
const player = state.currentPlayer;
if (!player) return null;
const winRate =
player.recentStats.games > 0
? Math.round((player.recentStats.wins / player.recentStats.games) * 100)
@@ -162,11 +139,10 @@ function PlayerSpotlight({
(player.recentStats.kda.kills + player.recentStats.kda.assists) /
player.recentStats.kda.deaths
).toFixed(2)
: "Perfect";
: 'Perfect';
return (
<div className="border border-base-content/10 bg-base-100">
{/* 선수 프로필 */}
<div className="p-5 border-b border-base-content/8">
<div className="flex items-start gap-4">
<div className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0">
@@ -185,19 +161,8 @@ function PlayerSpotlight({
#{player.tag}
</span>
</div>
<div className="flex items-center gap-1.5 text-[11px] mb-2">
<span className="text-base-content/25">
{player.tier.previousSeason}
</span>
<span className="text-base-content/15">→</span>
<span className={`font-bold ${tierColor(player.tier.current)}`}>
{player.tier.current}
</span>
<span
className={`text-[10px] ${tierColor(player.tier.peak)} opacity-50`}
>
({player.tier.peak})
</span>
<div className={`text-[11px] mb-2 font-bold ${getTierColorToken(player.tier)}`}>
{formatTierLabel(player.tier)}
</div>
<div className="flex items-center gap-1.5">
<PosBadge pos={player.mainPosition} />
@@ -206,7 +171,7 @@ function PlayerSpotlight({
src={positionIcon[player.subPosition]}
alt=""
className="w-3.5 h-3.5 object-contain inline"
/>{" "}
/>{' '}
{positionLabel[player.subPosition]}
</span>
</div>
@@ -214,38 +179,41 @@ function PlayerSpotlight({
</div>
</div>
{/* 스탯 그리드 */}
<div className="grid grid-cols-2 divide-x divide-base-content/5">
{/* 숙련도 */}
<div className="p-4">
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
숙련도 높은 챔피언
</h4>
<div className="space-y-2">
{player.masteries.map((m) => (
<div key={m.championId} 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/champion/${m.championId}.png`}
alt={m.championName}
className="w-full h-full object-cover"
loading="lazy"
/>
</div>
<div className="flex-1 min-w-0">
<div className="text-[12px] font-medium text-base-content truncate">
{m.championName}
{player.masteries.length > 0 ? (
player.masteries.map((mastery) => (
<div key={mastery.championId} 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/champion/${mastery.championId}.png`}
alt={mastery.championName}
className="w-full h-full object-cover"
loading="lazy"
/>
</div>
<div className="text-[10px] text-base-content/25">
Lv.{m.level} · {(m.points / 1000).toFixed(0)}K
<div className="flex-1 min-w-0">
<div className="text-[12px] font-medium text-base-content truncate">
{mastery.championName}
</div>
<div className="text-[10px] text-base-content/25">
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
</div>
</div>
</div>
))
) : (
<div className="text-[11px] text-base-content/25">
숙련도 데이터가 없습니다.
</div>
))}
)}
</div>
</div>
{/* 최근 전적 */}
<div className="p-4">
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
최근 솔로랭크
@@ -254,7 +222,7 @@ function PlayerSpotlight({
<div className="flex items-baseline justify-between">
<span className="text-[11px] text-base-content/40">승률</span>
<span
className={`text-sm font-bold tabular-nums ${winRate >= 55 ? "text-blue-400" : winRate >= 50 ? "text-base-content" : "text-red-400"}`}
className={`text-sm font-bold tabular-nums ${winRate >= 55 ? 'text-blue-400' : winRate >= 50 ? 'text-base-content' : 'text-red-400'}`}
>
{winRate}%
</span>
@@ -262,12 +230,8 @@ function PlayerSpotlight({
<div className="flex items-baseline justify-between">
<span className="text-[11px] text-base-content/40">전적</span>
<span className="text-[12px] text-base-content/60 tabular-nums">
<span className="text-blue-400">
{player.recentStats.wins}W
</span>{" "}
<span className="text-red-400">
{player.recentStats.losses}L
</span>
<span className="text-blue-400">{player.recentStats.wins}W</span>{' '}
<span className="text-red-400">{player.recentStats.losses}L</span>
</span>
</div>
<div className="flex items-baseline justify-between">
@@ -276,7 +240,7 @@ function PlayerSpotlight({
{player.recentStats.kda.kills}/{player.recentStats.kda.deaths}/
{player.recentStats.kda.assists}
<span
className={`ml-1 font-bold ${Number(kdaRatio) >= 3 ? "text-emerald-400" : "text-base-content/50"}`}
className={`ml-1 font-bold ${Number(kdaRatio) >= 3 ? 'text-emerald-400' : 'text-base-content/50'}`}
>
({kdaRatio})
</span>
@@ -292,23 +256,22 @@ function PlayerSpotlight({
</div>
</div>
{/* 현재 입찰 상태 */}
{(phase === "bidding" || phase === "sold") && (
{(state.phase === 'bidding' || state.phase === 'sold') && (
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
<div className="flex items-center justify-between">
<span className="text-[11px] text-base-content/30 uppercase tracking-wider font-semibold">
{phase === "sold" ? "낙찰가" : "현재 입찰가"}
{state.phase === 'sold' ? '낙찰가' : '현재 입찰가'}
</span>
<div className="flex items-center gap-2">
{currentBidder && (
{state.currentBidder && (
<span
className={`text-[10px] font-bold uppercase ${currentBidder === "blue" ? "text-blue-400" : "text-red-400"}`}
className={`text-[10px] font-bold uppercase ${state.currentBidder === 'blue' ? 'text-blue-400' : 'text-red-400'}`}
>
{currentBidder === "blue" ? "블루" : "레드"}
{state.currentBidder === 'blue' ? '블루' : '레드'}
</span>
)}
<span className="text-lg font-black text-amber-400 tabular-nums">
{currentBid > 0 ? formatPoints(currentBid) : "—"}
{state.currentBid > 0 ? formatPoints(state.currentBid) : '—'}
</span>
</div>
</div>
@@ -318,80 +281,86 @@ function PlayerSpotlight({
);
}
// -- 입찰 컨트롤 --
function BidControls({
state,
captainSide,
onBid,
}: {
state: AuctionState;
onBid: (side: "blue" | "red", amount: number) => void;
state: AuctionStateView;
captainSide: 'spectator' | 'blue' | 'red';
onBid: (side: 'blue' | 'red', amount: number) => void;
}) {
const [bidAmount, setBidAmount] = useState(100);
const minBid = state.currentBid + 10;
const activeTeam =
captainSide === 'blue'
? state.teams[0]
: captainSide === 'red'
? state.teams[1]
: null;
useEffect(() => {
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
}, [state.currentBid]);
}, [state.currentBid, minBid]);
if (state.phase !== "bidding") return null;
if (state.phase !== 'bidding') return null;
if (!activeTeam) {
return (
<div className="border border-base-content/10 bg-base-100 px-4 py-3 text-sm text-base-content/40">
관전자 모드입니다. 우측 상단에서 조작자 역할을 선택하면 입찰할 수 있습니다.
</div>
);
}
const presets = [50, 100, 150, 200, 300, 500];
return (
<div className="border border-base-content/10 bg-base-100 p-4">
<div className="flex items-center gap-2 mb-3 flex-wrap">
{presets.map((p) => (
{presets.map((preset) => (
<button
key={p}
onClick={() => setBidAmount(Math.max(minBid, p))}
key={preset}
onClick={() => setBidAmount(Math.max(minBid, preset))}
className={`text-[11px] px-2.5 py-1 border transition-colors ${
bidAmount === p
? "border-primary/40 bg-primary/10 text-primary"
: "border-base-content/10 text-base-content/40 hover:border-base-content/20"
bidAmount === preset
? 'border-primary/40 bg-primary/10 text-primary'
: 'border-base-content/10 text-base-content/40 hover:border-base-content/20'
}`}
>
{p}P
{preset}P
</button>
))}
<input
type="number"
value={bidAmount}
onChange={(e) =>
setBidAmount(Math.max(minBid, Number(e.target.value)))
onChange={(event) =>
setBidAmount(Math.max(minBid, Number(event.target.value)))
}
min={minBid}
className="w-20 text-xs px-2 py-1 border border-base-content/10 bg-transparent text-base-content tabular-nums text-right focus:outline-none focus:border-primary/30"
className="w-24 text-xs px-2 py-1 border border-base-content/10 bg-transparent text-base-content tabular-nums text-right focus:outline-none focus:border-primary/30"
/>
</div>
<div className="grid grid-cols-2 gap-2">
<button
onClick={() => onBid("blue", bidAmount)}
disabled={
bidAmount > state.teams[0].points || bidAmount <= state.currentBid
}
className="py-2 text-xs font-bold uppercase tracking-wide border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
>
블루 입찰 ({formatPoints(bidAmount)}P)
</button>
<button
onClick={() => onBid("red", bidAmount)}
disabled={
bidAmount > state.teams[1].points || bidAmount <= state.currentBid
}
className="py-2 text-xs font-bold uppercase tracking-wide border border-red-500/30 bg-red-500/10 text-red-400 hover:bg-red-500/20 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
>
레드 입찰 ({formatPoints(bidAmount)}P)
</button>
</div>
<button
onClick={() => onBid(activeTeam.side, bidAmount)}
disabled={bidAmount > activeTeam.points || bidAmount <= state.currentBid}
className={`w-full py-2 text-xs font-bold uppercase tracking-wide border transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${
activeTeam.side === 'blue'
? 'border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20'
: 'border-red-500/30 bg-red-500/10 text-red-400 hover:bg-red-500/20'
}`}
>
{activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 입찰 ({formatPoints(bidAmount)}P)
</button>
</div>
);
}
// -- 입찰 로그 --
function BidLog({ bids }: { bids: AuctionState["bids"] }) {
function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
const endRef = useRef<HTMLDivElement>(null);
useEffect(() => {
endRef.current?.scrollIntoView({ behavior: "smooth" });
endRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [bids.length]);
if (bids.length === 0) return null;
@@ -404,16 +373,16 @@ function BidLog({ bids }: { bids: AuctionState["bids"] }) {
</span>
</div>
<div className="max-h-28 overflow-y-auto p-2 space-y-0.5">
{bids.map((b, i) => (
<div key={i} className="flex items-center gap-2 text-[11px]">
{bids.map((bid, index) => (
<div key={`${bid.side}-${bid.timestamp}-${index}`} className="flex items-center gap-2 text-[11px]">
<span
className={`font-bold uppercase ${b.side === "blue" ? "text-blue-400" : "text-red-400"}`}
className={`font-bold uppercase ${bid.side === 'blue' ? 'text-blue-400' : 'text-red-400'}`}
>
{b.side === "blue" ? "블루" : "레드"}
{bid.side === 'blue' ? '블루' : '레드'}
</span>
<span className="text-base-content/30">→</span>
<span className="text-amber-400 tabular-nums font-semibold">
{formatPoints(b.amount)}P
{formatPoints(bid.amount)}P
</span>
</div>
))}
@@ -423,47 +392,89 @@ function BidLog({ bids }: { bids: AuctionState["bids"] }) {
);
}
// -- 메인 --
export default function AuctionPage() {
const { id } = useParams();
const [state, setState] = useState<AuctionState | null>(null);
const auctionRef = useRef<ReturnType<typeof createMockAuction> | null>(null);
const meQuery = useMe();
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
const socket = useAuctionSocket(id);
const captainSide = useDevCaptainSide();
const [now, setNow] = useState(() => Date.now());
const [assignedPosition, setAssignedPosition] = useState<Position>('MID');
useEffect(() => {
const auction = createMockAuction((newState) => {
setState({ ...newState });
});
auctionRef.current = auction;
auction.start();
const timer = window.setInterval(() => setNow(Date.now()), 1000);
return () => window.clearInterval(timer);
}, []);
return () => {
auction.destroy();
};
}, [id]);
const liveAuction = socket.auction ?? auctionQuery.data ?? null;
const auctionState =
liveAuction && matchQuery.data
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data, new Date(now))
: null;
if (!state) {
useEffect(() => {
if (auctionState?.currentPlayer) {
setAssignedPosition(auctionState.currentPlayer.mainPosition);
}
}, [auctionState?.currentPlayer?.id]);
if (!DEFAULT_COMMUNITY_ID) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<span className="text-sm text-base-content/40">연결 중...</span>
<span className="text-sm text-amber-600">
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
</span>
</main>
);
}
const handleBid = (side: "blue" | "red", amount: number) => {
auctionRef.current?.bid(side, amount);
};
if (matchQuery.isLoading || (auctionQuery.isLoading && !socket.auction)) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<span className="text-sm text-base-content/40">경매를 연결하는 중...</span>
</main>
);
}
const phaseLabel: Record<AuctionState["phase"], string> = {
waiting: "경매 준비 중...",
presenting: "다음 선수 등장",
bidding: "입찰 진행 중",
sold: "낙찰!",
complete: "경매 완료",
if (auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404 && !socket.auction) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<h2 className="text-lg font-bold mb-2">경매가 아직 시작되지 않았습니다</h2>
<Link to={`/match/${id}`} className="btn btn-primary btn-sm mt-4 px-5 text-xs">
내전 상세로 돌아가기
</Link>
</main>
);
}
if (!auctionState || !matchQuery.data) {
return (
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
<span className="text-sm text-red-500">
경매 상태를 불러오지 못했습니다.
</span>
</main>
);
}
const canManageAuction =
import.meta.env.DEV ||
meQuery.data?.user?.role === 'owner' ||
meQuery.data?.user?.role === 'admin';
const phaseLabel: Record<AuctionStateView['phase'], string> = {
waiting: '경매 준비 중...',
presenting: '다음 선수 등장',
bidding: '입찰 진행 중',
sold: '낙찰!',
complete: '경매 완료',
};
const errorMessage =
socket.error ??
(auctionQuery.error instanceof Error ? auctionQuery.error.message : null);
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
{/* 뒤로가기 */}
<Link
to={`/match/${id}`}
className="inline-flex items-center gap-1 text-xs text-base-content/40 hover:text-base-content transition-colors mb-4"
@@ -485,65 +496,77 @@ export default function AuctionPage() {
내전 상세로
</Link>
{/* 경매 헤더 */}
<div className="mb-5 flex items-center justify-between flex-wrap gap-2">
{errorMessage && (
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
{errorMessage}
</div>
)}
<div className="mb-5 flex items-start justify-between flex-wrap gap-3">
<div>
<h1 className="text-xl font-bold text-base-content leading-tight">
경매 팀빌딩
</h1>
<p className="text-[11px] text-base-content/30 mt-0.5">
{state.currentPlayerIndex + 1} / {state.totalPlayers} 선수
{Math.min(auctionState.currentPlayerIndex + 1, Math.max(auctionState.totalPlayers, 1))} /{' '}
{auctionState.totalPlayers} 선수
</p>
</div>
<div className="flex items-center gap-2">
<span
className={`inline-flex items-center text-[11px] font-semibold px-2 py-1 border ${
state.phase === "bidding"
? "border-green-500/20 bg-green-500/10 text-green-400"
: state.phase === "sold"
? "border-amber-500/20 bg-amber-500/10 text-amber-400"
: "border-base-content/10 bg-base-content/5 text-base-content/40"
}`}
>
{phaseLabel[state.phase]}
</span>
{state.phase === "bidding" && (
<div className="flex flex-col items-end gap-2">
<div className="flex items-center gap-2">
<span
className={`text-lg font-black tabular-nums ${state.timer <= 5 ? "text-red-500" : "text-base-content"}`}
className={`inline-flex items-center text-[11px] font-semibold px-2 py-1 border ${
auctionState.phase === 'bidding'
? 'border-green-500/20 bg-green-500/10 text-green-400'
: auctionState.phase === 'sold'
? 'border-amber-500/20 bg-amber-500/10 text-amber-400'
: 'border-base-content/10 bg-base-content/5 text-base-content/40'
}`}
>
{state.timer}s
{phaseLabel[auctionState.phase]}
</span>
)}
{auctionState.phase === 'bidding' && (
<span
className={`text-lg font-black tabular-nums ${auctionState.timer <= 5 ? 'text-red-500' : 'text-base-content'}`}
>
{auctionState.timer}s
</span>
)}
</div>
<div className="flex items-center gap-2 text-xs text-base-content/40">
<span>소켓: {socket.connectionStatus}</span>
{import.meta.env.DEV && (
<select
value={captainSide}
onChange={(event) =>
setDevCaptainSide(event.target.value as 'spectator' | 'blue' | 'red')
}
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
>
<option value="spectator">관전자</option>
<option value="blue">블루팀장</option>
<option value="red">레드팀장</option>
</select>
)}
</div>
</div>
</div>
{/* 타이머 바 */}
{state.phase === "bidding" && (
<TimerBar timer={state.timer} maxTimer={state.maxTimer} />
{auctionState.phase === 'bidding' && (
<TimerBar timer={auctionState.timer} maxTimer={auctionState.maxTimer} />
)}
{/* 메인 3컬럼 */}
<div className="flex flex-col lg:flex-row gap-4 mt-4">
{/* 블루팀 */}
<div className="w-full lg:w-56 shrink-0">
<TeamPanel
team={state.teams[0]}
isActive={state.currentBidder === "blue"}
team={auctionState.teams[0]}
isActive={auctionState.currentBidder === 'blue'}
isLeft
/>
</div>
{/* 중앙: 선수 카드 */}
<div className="flex-1 min-w-0 space-y-4">
{state.phase === "waiting" && (
<div className="border border-base-content/10 bg-base-100 p-12 text-center">
<div className="text-base-content/20 text-sm">
경매가 곧 시작됩니다...
</div>
</div>
)}
{state.phase === "complete" && (
{auctionState.phase === 'complete' ? (
<div className="border border-base-content/10 bg-base-100 p-8 text-center">
<div className="text-lg font-bold text-base-content mb-2">
경매 완료
@@ -558,44 +581,85 @@ export default function AuctionPage() {
결과 확인
</Link>
</div>
)}
) : (
<>
<PlayerSpotlight state={auctionState} />
{state.currentPlayer &&
(state.phase === "presenting" ||
state.phase === "bidding" ||
state.phase === "sold") && (
<>
<PlayerSpotlight
player={state.currentPlayer}
phase={state.phase}
currentBid={state.currentBid}
currentBidder={state.currentBidder}
/>
{auctionState.phase === 'sold' && auctionState.currentBidder && (
<div
className={`text-center py-3 border text-sm font-bold ${
auctionState.currentBidder === 'blue'
? 'border-blue-500/20 bg-blue-500/8 text-blue-400'
: 'border-red-500/20 bg-red-500/8 text-red-400'
}`}
>
{auctionState.currentBidder === 'blue' ? '블루팀' : '레드팀'} 낙찰
{' '}— {formatPoints(auctionState.currentBid)}P
</div>
)}
{state.phase === "sold" && state.currentBidder && (
<div
className={`text-center py-3 border text-sm font-bold ${
state.currentBidder === "blue"
? "border-blue-500/20 bg-blue-500/8 text-blue-400"
: "border-red-500/20 bg-red-500/8 text-red-400"
}`}
>
{state.currentBidder === "blue" ? "블루팀" : "레드팀"} 낙찰
— {formatPoints(state.currentBid)}P
<BidControls
state={auctionState}
captainSide={captainSide}
onBid={(side, amount) => socket.placeBid({ side, amount })}
/>
<BidLog bids={auctionState.bids} />
{canManageAuction && (
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
Auction Controls
</div>
)}
<BidControls state={state} onBid={handleBid} />
<BidLog bids={state.bids} />
</>
)}
{auctionState.phase === 'presenting' && (
<button
type="button"
className="btn btn-primary btn-sm px-5 text-xs"
onClick={() => socket.openBidding()}
>
입찰 열기
</button>
)}
{auctionState.phase === 'bidding' && (
<div className="flex flex-wrap items-center gap-3">
<select
value={assignedPosition}
onChange={(event) => setAssignedPosition(event.target.value as Position)}
className="border border-base-content/10 bg-transparent px-2 py-2 text-xs"
>
<option value="TOP">탑</option>
<option value="JGL">정글</option>
<option value="MID">미드</option>
<option value="ADC">원딜</option>
<option value="SUP">서폿</option>
</select>
<button
type="button"
className="btn btn-primary btn-sm px-5 text-xs"
onClick={() => socket.markSold(assignedPosition)}
>
낙찰 처리
</button>
</div>
)}
{auctionState.phase === 'sold' && (
<button
type="button"
className="btn btn-primary btn-sm px-5 text-xs"
onClick={() => socket.next()}
>
다음 선수
</button>
)}
</div>
)}
</>
)}
</div>
{/* 레드팀 */}
<div className="w-full lg:w-56 shrink-0">
<TeamPanel
team={state.teams[1]}
isActive={state.currentBidder === "red"}
team={auctionState.teams[1]}
isActive={auctionState.currentBidder === 'red'}
isLeft={false}
/>
</div>
+159 -90
View File
@@ -1,19 +1,19 @@
import { Link } from "react-router";
import {
nextMatchSummary,
upcomingMatches,
pastMatches,
} from "../mock";
import { Link } from 'react-router';
import { mapApiMatchToMatchDetail } from '../api/mappers';
import { useMatches } from '../api/hooks';
import { DEFAULT_COMMUNITY_ID } from '../config';
function StatusBadge({ status }: { status: string }) {
const styles: Record<string, string> = {
"모집 중": "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-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 (
<span
className={`inline-flex items-center text-[11px] font-semibold px-1.5 py-0.5 border ${styles[status] ?? "bg-base-content/10 text-base-content/50 border-base-content/10"}`}
className={`inline-flex items-center text-[11px] font-semibold px-1.5 py-0.5 border ${styles[status] ?? 'bg-base-content/10 text-base-content/50 border-base-content/10'}`}
>
{status}
</span>
@@ -28,88 +28,146 @@ function MapBadge({ map }: { map: string }) {
);
}
function getStatusLabel(status: string) {
switch (status) {
case 'recruiting':
return '모집중';
case 'team-built':
return '팀빌딩';
case 'in-progress':
return '진행중';
case 'finished':
return '종료';
default:
return status;
}
}
export default function HomePage() {
const upcomingMatchesQuery = useMatches({ limit: 20 }, DEFAULT_COMMUNITY_ID);
const finishedMatchesQuery = useMatches(
{ status: 'finished', limit: 10 },
DEFAULT_COMMUNITY_ID,
);
if (!DEFAULT_COMMUNITY_ID) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-16">
<div className="border border-amber-500/20 bg-amber-500/10 p-5 text-sm text-amber-700">
`apps/web/.env.development`의 `VITE_DEFAULT_COMMUNITY_ID`를 먼저 설정해주세요.
</div>
</main>
);
}
if (upcomingMatchesQuery.isLoading || finishedMatchesQuery.isLoading) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
<span className="text-sm text-base-content/40">매치 목록을 불러오는 중...</span>
</main>
);
}
if (upcomingMatchesQuery.error || finishedMatchesQuery.error) {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-20 text-center">
<span className="text-sm text-red-500">
매치 목록을 불러오지 못했습니다.
</span>
</main>
);
}
const upcomingMatches =
upcomingMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
const finishedMatches =
finishedMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
const nextMatch = upcomingMatches[0];
const upcomingCards = nextMatch ? upcomingMatches.slice(1) : upcomingMatches;
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6">
{/* 다음 내전 (Hero) */}
<section className="pt-8 pb-6">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
다음 내전
</h2>
<Link to={`/match/${nextMatchSummary.id}`} className="block group">
<div className="border border-base-content/10 bg-base-200/50 hover:bg-base-200 transition-colors">
<div className="p-5 sm:p-6">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4">
<div className="space-y-2.5">
<div className="flex items-center gap-2.5 flex-wrap">
<h3 className="text-xl sm:text-2xl font-bold text-base-content leading-tight">
{nextMatchSummary.title}
</h3>
<StatusBadge status={nextMatchSummary.status} />
{nextMatch ? (
<Link to={`/match/${nextMatch.id}`} className="block group">
<div className="border border-base-content/10 bg-base-200/50 hover:bg-base-200 transition-colors">
<div className="p-5 sm:p-6">
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4">
<div className="space-y-2.5">
<div className="flex items-center gap-2.5 flex-wrap">
<h3 className="text-xl sm:text-2xl font-bold text-base-content leading-tight">
{nextMatch.title}
</h3>
<StatusBadge status={getStatusLabel(nextMatch.status)} />
</div>
<p className="text-sm text-base-content/50 max-w-xl leading-relaxed">
{nextMatch.description}
</p>
<div className="flex items-center gap-3 text-xs text-base-content/40 flex-wrap">
<span>{nextMatch.date} {nextMatch.time}</span>
<span className="text-base-content/15">|</span>
<span>
{nextMatch.participants.length}/{nextMatch.maxParticipants}명
</span>
<span className="text-base-content/15">|</span>
<MapBadge map={nextMatch.map} />
</div>
</div>
<p className="text-sm text-base-content/50 max-w-xl leading-relaxed">
{nextMatchSummary.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>
{nextMatchSummary.date} {nextMatchSummary.time}
<div className="sm:shrink-0">
<span className="btn btn-primary btn-sm px-6 text-xs font-semibold">
상세 보기
</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>
{nextMatchSummary.participants}/{nextMatchSummary.maxParticipants}명
</span>
<span className="text-base-content/15">|</span>
<MapBadge map={nextMatchSummary.map} />
</div>
</div>
<div className="sm:shrink-0">
<span className="btn btn-primary btn-sm px-6 text-xs font-semibold">
상세 보기
</span>
</div>
</div>
</div>
</Link>
) : (
<div className="border border-base-content/10 bg-base-100 px-5 py-10 text-center text-sm text-base-content/40">
아직 등록된 내전이 없습니다.
</div>
</Link>
)}
</section>
{/* 예정된 내전 */}
<section className="pb-6">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
예정된 내전
</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-px bg-base-content/10 border border-base-content/10">
{upcomingMatches.map((match) => (
<Link key={match.id} to={`/match/${match.id}`}>
<div className="bg-base-100 hover:bg-base-200/50 transition-colors cursor-pointer h-full p-4">
<div className="flex items-center justify-between mb-2.5">
<h3 className="text-sm font-bold text-base-content truncate mr-2">
{match.title}
</h3>
<StatusBadge status={match.status} />
</div>
<div className="space-y-1 text-xs text-base-content/40">
<div className="flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" className="h-3 w-3" 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}
{upcomingCards.length > 0 ? (
upcomingCards.map((match) => (
<Link key={match.id} to={`/match/${match.id}`}>
<div className="bg-base-100 hover:bg-base-200/50 transition-colors cursor-pointer h-full p-4">
<div className="flex items-center justify-between mb-2.5">
<h3 className="text-sm font-bold text-base-content truncate mr-2">
{match.title}
</h3>
<StatusBadge status={getStatusLabel(match.status)} />
</div>
<div className="flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" className="h-3 w-3" 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>
{match.participants}/{match.maxParticipants}명
<div className="space-y-1 text-xs text-base-content/40">
<div>{match.date} {match.time}</div>
<div>
{match.participants.length}/{match.maxParticipants}명
</div>
</div>
<div className="mt-2.5">
<MapBadge map={match.map} />
</div>
</div>
<div className="mt-2.5">
<MapBadge map={match.map} />
</div>
</div>
</Link>
))}
</Link>
))
) : (
<div className="bg-base-100 px-4 py-6 text-sm text-base-content/35 col-span-full">
예정된 추가 매치가 없습니다.
</div>
)}
</div>
</section>
{/* 지난 내전 기록 */}
<section className="pb-12">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
지난 내전 기록
@@ -126,33 +184,44 @@ export default function HomePage() {
</tr>
</thead>
<tbody>
{pastMatches.map((match) => (
<tr
key={match.id}
className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02] transition-colors"
>
<td className="py-2.5 px-4 text-xs text-base-content/40 whitespace-nowrap">
{match.date}
</td>
<td className="py-2.5 px-4">
<Link
to={`/match/${match.id}`}
className="text-sm font-medium text-base-content hover:text-primary transition-colors"
>
{match.title}
</Link>
</td>
<td className="py-2.5 px-4">
<MapBadge map={match.map} />
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.participants}명
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.result}
{finishedMatches.length > 0 ? (
finishedMatches.map((match) => (
<tr
key={match.id}
className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02] transition-colors"
>
<td className="py-2.5 px-4 text-xs text-base-content/40 whitespace-nowrap">
{match.date}
</td>
<td className="py-2.5 px-4">
<Link
to={`/match/${match.id}`}
className="text-sm font-medium text-base-content hover:text-primary transition-colors"
>
{match.title}
</Link>
</td>
<td className="py-2.5 px-4">
<MapBadge map={match.map} />
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.participants.length}명
</td>
<td className="py-2.5 px-4 text-xs text-base-content/50">
{match.result ? `${match.result.winner} 승리` : '-'}
</td>
</tr>
))
) : (
<tr>
<td
colSpan={5}
className="py-6 px-4 text-sm text-base-content/35 text-center"
>
아직 종료된 내전 기록이 없습니다.
</td>
</tr>
))}
)}
</tbody>
</table>
</div>
+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>