- Set up React Router with routes for Home, Match Detail, and Auction pages - Integrate Tailwind CSS and daisyUI for application styling - Implement match management UI components using mock data - Add auction team-building simulation logic and associated types - Update project configuration to support the new UI framework
606 lines
21 KiB
TypeScript
606 lines
21 KiB
TypeScript
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";
|
|
|
|
// -- 티어 색상 --
|
|
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 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"
|
|
/>
|
|
<span>{positionLabel[pos]}</span>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
// -- 타이머 바 --
|
|
function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
|
|
const pct = (timer / maxTimer) * 100;
|
|
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"}`}
|
|
style={{ width: `${pct}%` }}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// -- 팀 패널 --
|
|
function TeamPanel({
|
|
team,
|
|
isActive,
|
|
isLeft,
|
|
}: {
|
|
team: AuctionTeam;
|
|
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";
|
|
|
|
return (
|
|
<div
|
|
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}`}
|
|
/>
|
|
|
|
{/* 헤더 */}
|
|
<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>
|
|
<span className="text-[10px] text-base-content/30">
|
|
팀장: {team.captainName}
|
|
</span>
|
|
</div>
|
|
<span className="text-xs font-bold text-amber-400 tabular-nums">
|
|
{formatPoints(team.points)}P
|
|
</span>
|
|
</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">
|
|
<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`}
|
|
alt=""
|
|
className="w-full h-full object-cover"
|
|
loading="lazy"
|
|
/>
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-[12px] font-medium text-base-content truncate block leading-tight">
|
|
{m.summonerName}
|
|
</span>
|
|
</div>
|
|
<PosBadge pos={m.assignedPosition} />
|
|
<span className="text-[10px] text-amber-400/60 tabular-nums w-8 text-right">
|
|
{m.cost}
|
|
</span>
|
|
</div>
|
|
))
|
|
)}
|
|
|
|
{/* 빈 슬롯 */}
|
|
{Array.from({ length: 4 - team.members.length }).map((_, i) => (
|
|
<div
|
|
key={`empty-${i}`}
|
|
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" />
|
|
<span className="ml-2 text-[10px] text-base-content/10">—</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// -- 현재 경매 선수 카드 --
|
|
function PlayerSpotlight({
|
|
player,
|
|
phase,
|
|
currentBid,
|
|
currentBidder,
|
|
}: {
|
|
player: AuctionPlayer;
|
|
phase: AuctionState["phase"];
|
|
currentBid: number;
|
|
currentBidder: "blue" | "red" | null;
|
|
}) {
|
|
const winRate =
|
|
player.recentStats.games > 0
|
|
? Math.round((player.recentStats.wins / player.recentStats.games) * 100)
|
|
: 0;
|
|
const kdaRatio =
|
|
player.recentStats.kda.deaths > 0
|
|
? (
|
|
(player.recentStats.kda.kills + player.recentStats.kda.assists) /
|
|
player.recentStats.kda.deaths
|
|
).toFixed(2)
|
|
: "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">
|
|
<img
|
|
src={`https://ddragon.leagueoflegends.com/cdn/16.7.1/img/profileicon/${player.profileIconId}.png`}
|
|
alt=""
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
</div>
|
|
<div className="flex-1">
|
|
<div className="flex items-center gap-2 mb-1">
|
|
<h3 className="text-lg font-bold text-base-content leading-tight">
|
|
{player.summonerName}
|
|
</h3>
|
|
<span className="text-[10px] text-base-content/25">
|
|
#{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>
|
|
<div className="flex items-center gap-1.5">
|
|
<PosBadge pos={player.mainPosition} />
|
|
<span className="inline-flex items-center gap-0.5 text-[11px] px-1.5 py-0.5 border border-base-content/8 text-base-content/35">
|
|
<img
|
|
src={positionIcon[player.subPosition]}
|
|
alt=""
|
|
className="w-3.5 h-3.5 object-contain inline"
|
|
/>{" "}
|
|
{positionLabel[player.subPosition]}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</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}
|
|
</div>
|
|
<div className="text-[10px] text-base-content/25">
|
|
Lv.{m.level} · {(m.points / 1000).toFixed(0)}K
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 최근 전적 */}
|
|
<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">
|
|
<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"}`}
|
|
>
|
|
{winRate}%
|
|
</span>
|
|
</div>
|
|
<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>
|
|
</div>
|
|
<div className="flex items-baseline justify-between">
|
|
<span className="text-[11px] text-base-content/40">KDA</span>
|
|
<span className="text-[12px] text-base-content/60 tabular-nums">
|
|
{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"}`}
|
|
>
|
|
({kdaRatio})
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div className="flex items-baseline justify-between">
|
|
<span className="text-[11px] text-base-content/40">평균 CS</span>
|
|
<span className="text-[12px] text-base-content/60 tabular-nums">
|
|
{player.recentStats.avgCs}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 현재 입찰 상태 */}
|
|
{(phase === "bidding" || 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" ? "낙찰가" : "현재 입찰가"}
|
|
</span>
|
|
<div className="flex items-center gap-2">
|
|
{currentBidder && (
|
|
<span
|
|
className={`text-[10px] font-bold uppercase ${currentBidder === "blue" ? "text-blue-400" : "text-red-400"}`}
|
|
>
|
|
{currentBidder === "blue" ? "블루" : "레드"}
|
|
</span>
|
|
)}
|
|
<span className="text-lg font-black text-amber-400 tabular-nums">
|
|
{currentBid > 0 ? formatPoints(currentBid) : "—"}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// -- 입찰 컨트롤 --
|
|
function BidControls({
|
|
state,
|
|
onBid,
|
|
}: {
|
|
state: AuctionState;
|
|
onBid: (side: "blue" | "red", amount: number) => void;
|
|
}) {
|
|
const [bidAmount, setBidAmount] = useState(100);
|
|
const minBid = state.currentBid + 10;
|
|
|
|
useEffect(() => {
|
|
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
|
|
}, [state.currentBid]);
|
|
|
|
if (state.phase !== "bidding") return null;
|
|
|
|
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) => (
|
|
<button
|
|
key={p}
|
|
onClick={() => setBidAmount(Math.max(minBid, p))}
|
|
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"
|
|
}`}
|
|
>
|
|
{p}P
|
|
</button>
|
|
))}
|
|
<input
|
|
type="number"
|
|
value={bidAmount}
|
|
onChange={(e) =>
|
|
setBidAmount(Math.max(minBid, Number(e.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"
|
|
/>
|
|
</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>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// -- 입찰 로그 --
|
|
function BidLog({ bids }: { bids: AuctionState["bids"] }) {
|
|
const endRef = useRef<HTMLDivElement>(null);
|
|
useEffect(() => {
|
|
endRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
}, [bids.length]);
|
|
|
|
if (bids.length === 0) return null;
|
|
|
|
return (
|
|
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
|
|
<div className="px-3 py-1.5 border-b border-base-content/8 bg-base-200/40">
|
|
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
|
입찰 기록
|
|
</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]">
|
|
<span
|
|
className={`font-bold uppercase ${b.side === "blue" ? "text-blue-400" : "text-red-400"}`}
|
|
>
|
|
{b.side === "blue" ? "블루" : "레드"}
|
|
</span>
|
|
<span className="text-base-content/30">→</span>
|
|
<span className="text-amber-400 tabular-nums font-semibold">
|
|
{formatPoints(b.amount)}P
|
|
</span>
|
|
</div>
|
|
))}
|
|
<div ref={endRef} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// -- 메인 --
|
|
export default function AuctionPage() {
|
|
const { id } = useParams();
|
|
const [state, setState] = useState<AuctionState | null>(null);
|
|
const auctionRef = useRef<ReturnType<typeof createMockAuction> | null>(null);
|
|
|
|
useEffect(() => {
|
|
const auction = createMockAuction((newState) => {
|
|
setState({ ...newState });
|
|
});
|
|
auctionRef.current = auction;
|
|
auction.start();
|
|
|
|
return () => {
|
|
auction.destroy();
|
|
};
|
|
}, [id]);
|
|
|
|
if (!state) {
|
|
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 handleBid = (side: "blue" | "red", amount: number) => {
|
|
auctionRef.current?.bid(side, amount);
|
|
};
|
|
|
|
const phaseLabel: Record<AuctionState["phase"], string> = {
|
|
waiting: "경매 준비 중...",
|
|
presenting: "다음 선수 등장",
|
|
bidding: "입찰 진행 중",
|
|
sold: "낙찰!",
|
|
complete: "경매 완료",
|
|
};
|
|
|
|
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"
|
|
>
|
|
<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="M15 19l-7-7 7-7"
|
|
/>
|
|
</svg>
|
|
내전 상세로
|
|
</Link>
|
|
|
|
{/* 경매 헤더 */}
|
|
<div className="mb-5 flex items-center justify-between flex-wrap gap-2">
|
|
<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} 선수
|
|
</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" && (
|
|
<span
|
|
className={`text-lg font-black tabular-nums ${state.timer <= 5 ? "text-red-500" : "text-base-content"}`}
|
|
>
|
|
{state.timer}s
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 타이머 바 */}
|
|
{state.phase === "bidding" && (
|
|
<TimerBar timer={state.timer} maxTimer={state.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"}
|
|
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" && (
|
|
<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">
|
|
경매 완료
|
|
</div>
|
|
<div className="text-xs text-base-content/40">
|
|
모든 선수가 팀에 배정되었습니다.
|
|
</div>
|
|
<Link
|
|
to={`/match/${id}`}
|
|
className="btn btn-primary btn-sm mt-4 px-6 text-[11px]"
|
|
>
|
|
결과 확인
|
|
</Link>
|
|
</div>
|
|
)}
|
|
|
|
{state.currentPlayer &&
|
|
(state.phase === "presenting" ||
|
|
state.phase === "bidding" ||
|
|
state.phase === "sold") && (
|
|
<>
|
|
<PlayerSpotlight
|
|
player={state.currentPlayer}
|
|
phase={state.phase}
|
|
currentBid={state.currentBid}
|
|
currentBidder={state.currentBidder}
|
|
/>
|
|
|
|
{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
|
|
</div>
|
|
)}
|
|
|
|
<BidControls state={state} onBid={handleBid} />
|
|
<BidLog bids={state.bids} />
|
|
</>
|
|
)}
|
|
</div>
|
|
|
|
{/* 레드팀 */}
|
|
<div className="w-full lg:w-56 shrink-0">
|
|
<TeamPanel
|
|
team={state.teams[1]}
|
|
isActive={state.currentBidder === "red"}
|
|
isLeft={false}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|