.
This commit is contained in:
1 parent
30dfb7ce58
commit
5af2c80cd1
33 files changed
+3806
-1440
No files matched your search
+25
-10
@@ -1,21 +1,35 @@
|
||||
import { BrowserRouter, Routes, Route } from "react-router";
|
||||
import HomePage from "./pages/HomePage";
|
||||
import MatchDetailPage from "./pages/MatchDetailPage";
|
||||
import AuctionPage from "./pages/AuctionPage";
|
||||
import { BrowserRouter, Link, Route, Routes } from 'react-router';
|
||||
import DevAuthSwitcher from './components/DevAuthSwitcher';
|
||||
import { DEFAULT_COMMUNITY_ID } from './config';
|
||||
import { useCommunity } from './api/hooks';
|
||||
import HomePage from './pages/HomePage';
|
||||
import MatchDetailPage from './pages/MatchDetailPage';
|
||||
import AuctionPage from './pages/AuctionPage';
|
||||
|
||||
function App() {
|
||||
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
|
||||
const communityLabel = communityQuery.data?.name ?? 'LOLYMPUS';
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div className="min-h-screen bg-base-100">
|
||||
{/* Navbar */}
|
||||
<nav className="bg-base-100 border-b border-base-content/10 sticky top-0 z-50">
|
||||
<div className="max-w-5xl mx-auto px-4 sm:px-6 flex items-center h-11">
|
||||
<a
|
||||
<div className="max-w-5xl mx-auto px-4 sm:px-6 flex items-center justify-between h-11">
|
||||
<Link
|
||||
className="text-sm font-bold tracking-tight text-base-content"
|
||||
href="/"
|
||||
to="/"
|
||||
>
|
||||
LOLYMPUS
|
||||
</a>
|
||||
{communityLabel}
|
||||
</Link>
|
||||
{DEFAULT_COMMUNITY_ID ? (
|
||||
<span className="text-[10px] uppercase tracking-wider text-base-content/25">
|
||||
API Live
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] uppercase tracking-wider text-amber-500/70">
|
||||
Set `VITE_DEFAULT_COMMUNITY_ID`
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -24,6 +38,7 @@ function App() {
|
||||
<Route path="/match/:id" element={<MatchDetailPage />} />
|
||||
<Route path="/match/:id/auction" element={<AuctionPage />} />
|
||||
</Routes>
|
||||
<DevAuthSwitcher />
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { DEFAULT_COMMUNITY_ID, useAuthUserId } from '../config';
|
||||
import { apiFetch } from '../lib/api';
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiCommunity,
|
||||
ApiMatch,
|
||||
MatchStatus,
|
||||
MatchesResponse,
|
||||
MeResponse,
|
||||
} from './types';
|
||||
|
||||
interface MatchesQueryOptions {
|
||||
status?: MatchStatus;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
function createMatchesPath(
|
||||
communityId: string,
|
||||
options: MatchesQueryOptions = {},
|
||||
) {
|
||||
const searchParams = new URLSearchParams();
|
||||
if (options.status) searchParams.set('status', options.status);
|
||||
if (options.limit) searchParams.set('limit', String(options.limit));
|
||||
|
||||
const queryString = searchParams.toString();
|
||||
return `/communities/${communityId}/matches${queryString ? `?${queryString}` : ''}`;
|
||||
}
|
||||
|
||||
export function useCommunity(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useQuery({
|
||||
queryKey: ['community', communityId],
|
||||
queryFn: () => apiFetch<ApiCommunity>(`/communities/${communityId}`),
|
||||
enabled: Boolean(communityId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMatches(
|
||||
options: MatchesQueryOptions,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['matches', communityId, options.status ?? null, options.limit ?? null],
|
||||
queryFn: async () => {
|
||||
const response = await apiFetch<MatchesResponse>(
|
||||
createMatchesPath(communityId, options),
|
||||
);
|
||||
return response.matches;
|
||||
},
|
||||
enabled: Boolean(communityId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMatch(matchId: string | undefined, communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useQuery({
|
||||
queryKey: ['match', communityId, matchId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiMatch>(`/communities/${communityId}/matches/${matchId}`),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAuction(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['auction', communityId, matchId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiAuction>(`/communities/${communityId}/matches/${matchId}/auction`),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useMe() {
|
||||
const authUserId = useAuthUserId();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['me', authUserId],
|
||||
queryFn: () => apiFetch<MeResponse>('/me'),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiAuctionPlayerSnapshot,
|
||||
ApiAuctionTeam,
|
||||
ApiMatch,
|
||||
ApiMatchParticipant,
|
||||
ApiPositionPreference,
|
||||
ApiTierInfo,
|
||||
MatchStatus,
|
||||
Position,
|
||||
TeamSide,
|
||||
} from './types';
|
||||
import { POSITION_ORDER, sideLabel } from '../lib/league';
|
||||
|
||||
export interface ParticipantView {
|
||||
id: string;
|
||||
userId: string;
|
||||
summonerName: string;
|
||||
tag: string;
|
||||
tier?: ApiTierInfo;
|
||||
mainPosition: Position;
|
||||
subPosition: Position;
|
||||
profileIconId: number;
|
||||
}
|
||||
|
||||
export interface TeamParticipantView extends ParticipantView {
|
||||
assignedPosition: Position;
|
||||
cost?: number;
|
||||
}
|
||||
|
||||
export interface TeamView {
|
||||
side: TeamSide;
|
||||
name: string;
|
||||
participants: TeamParticipantView[];
|
||||
}
|
||||
|
||||
export interface MatchDetailView {
|
||||
id: string;
|
||||
title: string;
|
||||
date: string;
|
||||
time: string;
|
||||
status: MatchStatus;
|
||||
description: string;
|
||||
map: string;
|
||||
maxParticipants: number;
|
||||
joined: boolean;
|
||||
participants: ParticipantView[];
|
||||
teams: TeamView[];
|
||||
result?: {
|
||||
winner: string;
|
||||
blueScore: number;
|
||||
redScore: number;
|
||||
};
|
||||
prizes: string[];
|
||||
notices: string[];
|
||||
schedule: { time: string; label: string }[];
|
||||
}
|
||||
|
||||
export interface AuctionPlayerView extends ParticipantView {
|
||||
masteries: {
|
||||
championName: string;
|
||||
championId: string;
|
||||
level: number;
|
||||
points: number;
|
||||
}[];
|
||||
recentStats: {
|
||||
games: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
kda: {
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
};
|
||||
avgCs: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AuctionTeamView {
|
||||
side: TeamSide;
|
||||
captainUserId: string;
|
||||
captainName: string;
|
||||
points: number;
|
||||
members: (AuctionPlayerView & {
|
||||
assignedPosition: Position;
|
||||
cost: number;
|
||||
})[];
|
||||
}
|
||||
|
||||
export interface AuctionStateView {
|
||||
matchId: string;
|
||||
phase: ApiAuction['phase'];
|
||||
teams: [AuctionTeamView, AuctionTeamView];
|
||||
currentPlayer: AuctionPlayerView | null;
|
||||
currentPlayerIndex: number;
|
||||
totalPlayers: number;
|
||||
auctionOrder: AuctionPlayerView[];
|
||||
bids: {
|
||||
side: TeamSide;
|
||||
amount: number;
|
||||
timestamp: string;
|
||||
}[];
|
||||
currentBid: number;
|
||||
currentBidder: TeamSide | null;
|
||||
timer: number;
|
||||
maxTimer: number;
|
||||
deadline?: string;
|
||||
}
|
||||
|
||||
const MAP_LABELS: Record<number, string> = {
|
||||
11: '소환사의 협곡',
|
||||
12: '칼바람 나락',
|
||||
21: '소환사의 협곡',
|
||||
22: '전략적 팀 전투',
|
||||
};
|
||||
|
||||
const TIER_NAMES: Record<string, string> = {
|
||||
IRON: '아이언',
|
||||
BRONZE: '브론즈',
|
||||
SILVER: '실버',
|
||||
GOLD: '골드',
|
||||
PLATINUM: '플래티넘',
|
||||
EMERALD: '에메랄드',
|
||||
DIAMOND: '다이아',
|
||||
MASTER: '마스터',
|
||||
GRANDMASTER: '그랜드마스터',
|
||||
CHALLENGER: '챌린저',
|
||||
};
|
||||
|
||||
function sortPreferredPositions(preferredPositions: ApiPositionPreference[]) {
|
||||
return [...preferredPositions].sort((left, right) => left.priority - right.priority);
|
||||
}
|
||||
|
||||
function resolveMainAndSubPosition(preferredPositions: ApiPositionPreference[]) {
|
||||
const sorted = sortPreferredPositions(preferredPositions);
|
||||
return {
|
||||
mainPosition: sorted[0]?.position ?? 'MID',
|
||||
subPosition: sorted[1]?.position ?? sorted[0]?.position ?? 'MID',
|
||||
};
|
||||
}
|
||||
|
||||
function mapMatchParticipantToView(
|
||||
participant: ApiMatchParticipant,
|
||||
): ParticipantView {
|
||||
const { mainPosition, subPosition } = resolveMainAndSubPosition(
|
||||
participant.preferredPositions,
|
||||
);
|
||||
|
||||
return {
|
||||
id: participant.userId,
|
||||
userId: participant.userId,
|
||||
summonerName: participant.gameName ?? '알 수 없음',
|
||||
tag: participant.tagLine ?? '----',
|
||||
tier: participant.tier,
|
||||
mainPosition,
|
||||
subPosition,
|
||||
profileIconId: participant.profileIconId ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
function mapAuctionPlayerToView(
|
||||
player: ApiAuctionPlayerSnapshot,
|
||||
): AuctionPlayerView {
|
||||
const { mainPosition, subPosition } = resolveMainAndSubPosition(
|
||||
player.preferredPositions,
|
||||
);
|
||||
|
||||
return {
|
||||
id: player.userId,
|
||||
userId: player.userId,
|
||||
summonerName: player.gameName,
|
||||
tag: player.tagLine,
|
||||
tier: selectPrimaryTier(player.tiers),
|
||||
mainPosition,
|
||||
subPosition,
|
||||
profileIconId: player.profileIconId,
|
||||
masteries: player.masteries.slice(0, 3).map((mastery) => ({
|
||||
championName: mastery.championName ?? mastery.championId,
|
||||
championId: mastery.championId,
|
||||
level: mastery.level,
|
||||
points: mastery.points,
|
||||
})),
|
||||
recentStats: {
|
||||
games: player.recentStatsSummary?.games ?? 0,
|
||||
wins: player.recentStatsSummary?.wins ?? 0,
|
||||
losses: player.recentStatsSummary?.losses ?? 0,
|
||||
kda: {
|
||||
kills: player.recentStatsSummary?.avgKills ?? 0,
|
||||
deaths: player.recentStatsSummary?.avgDeaths ?? 0,
|
||||
assists: player.recentStatsSummary?.avgAssists ?? 0,
|
||||
},
|
||||
avgCs: Math.round(player.recentStatsSummary?.avgCs ?? 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createFallbackParticipant(userId: string): ParticipantView {
|
||||
return {
|
||||
id: userId,
|
||||
userId,
|
||||
summonerName: `User ${userId.slice(-4)}`,
|
||||
tag: '----',
|
||||
mainPosition: 'MID',
|
||||
subPosition: 'MID',
|
||||
profileIconId: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function mapAuctionTeamToView(
|
||||
team: ApiAuctionTeam,
|
||||
playerLookup: Map<string, AuctionPlayerView>,
|
||||
participantLookup: Map<string, ParticipantView>,
|
||||
): AuctionTeamView {
|
||||
return {
|
||||
side: team.side,
|
||||
captainUserId: team.captainUserId,
|
||||
captainName:
|
||||
participantLookup.get(team.captainUserId)?.summonerName ??
|
||||
`User ${team.captainUserId.slice(-4)}`,
|
||||
points: team.points,
|
||||
members: team.members.map((member) => {
|
||||
const participant = participantLookup.get(member.userId);
|
||||
const player =
|
||||
playerLookup.get(member.userId) ??
|
||||
(participant
|
||||
? {
|
||||
...participant,
|
||||
masteries: [],
|
||||
recentStats: {
|
||||
games: 0,
|
||||
wins: 0,
|
||||
losses: 0,
|
||||
kda: { kills: 0, deaths: 0, assists: 0 },
|
||||
avgCs: 0,
|
||||
},
|
||||
}
|
||||
: {
|
||||
...createFallbackParticipant(member.userId),
|
||||
masteries: [],
|
||||
recentStats: {
|
||||
games: 0,
|
||||
wins: 0,
|
||||
losses: 0,
|
||||
kda: { kills: 0, deaths: 0, assists: 0 },
|
||||
avgCs: 0,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
...player,
|
||||
assignedPosition: member.assignedPosition,
|
||||
cost: member.cost,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapIdToLabel(mapId: number) {
|
||||
return MAP_LABELS[mapId] ?? `맵 #${mapId}`;
|
||||
}
|
||||
|
||||
export function formatKoreanDate(dateLike: string | Date) {
|
||||
const date = new Date(dateLike);
|
||||
|
||||
return {
|
||||
date: new Intl.DateTimeFormat('ko-KR', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
weekday: 'short',
|
||||
}).format(date),
|
||||
time: new Intl.DateTimeFormat('ko-KR', {
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
}).format(date),
|
||||
};
|
||||
}
|
||||
|
||||
export function selectPrimaryTier(tiers: ApiTierInfo[]) {
|
||||
return tiers.find((tier) => tier.queueType === 'RANKED_SOLO_5x5') ?? tiers[0];
|
||||
}
|
||||
|
||||
export function formatTierLabel(tier?: ApiTierInfo) {
|
||||
if (!tier) return '미등록';
|
||||
|
||||
const tierName = TIER_NAMES[tier.tier] ?? tier.tier;
|
||||
const highTier = ['MASTER', 'GRANDMASTER', 'CHALLENGER'].includes(tier.tier);
|
||||
|
||||
if (highTier && tier.leaguePoints > 0) {
|
||||
return `${tierName} ${tier.leaguePoints}LP`;
|
||||
}
|
||||
|
||||
return tier.rank ? `${tierName} ${tier.rank}` : tierName;
|
||||
}
|
||||
|
||||
export function getTierColorToken(tier?: ApiTierInfo) {
|
||||
switch (tier?.tier) {
|
||||
case 'CHALLENGER':
|
||||
return 'text-amber-400';
|
||||
case 'GRANDMASTER':
|
||||
return 'text-red-400';
|
||||
case 'MASTER':
|
||||
return 'text-fuchsia-400';
|
||||
case 'DIAMOND':
|
||||
return 'text-cyan-400';
|
||||
case 'EMERALD':
|
||||
return 'text-emerald-400';
|
||||
case 'PLATINUM':
|
||||
return 'text-teal-300';
|
||||
case 'GOLD':
|
||||
return 'text-yellow-400';
|
||||
case 'SILVER':
|
||||
return 'text-gray-300';
|
||||
case 'BRONZE':
|
||||
return 'text-amber-700';
|
||||
case 'IRON':
|
||||
return 'text-stone-400';
|
||||
default:
|
||||
return 'text-base-content/50';
|
||||
}
|
||||
}
|
||||
|
||||
export function buildDefaultPreferredPositions() {
|
||||
return POSITION_ORDER.map((position, index) => ({
|
||||
position,
|
||||
priority: index + 1,
|
||||
}));
|
||||
}
|
||||
|
||||
export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
|
||||
const formattedDate = formatKoreanDate(match.scheduledAt);
|
||||
const participants = match.participants.map(mapMatchParticipantToView);
|
||||
const participantLookup = new Map(
|
||||
participants.map((participant) => [participant.userId, participant]),
|
||||
);
|
||||
|
||||
const teams = match.teams.map((team) => ({
|
||||
side: team.side,
|
||||
name: team.name || sideLabel(team.side),
|
||||
participants: team.members.map((member) => {
|
||||
const participant =
|
||||
participantLookup.get(member.userId) ?? createFallbackParticipant(member.userId);
|
||||
|
||||
return {
|
||||
...participant,
|
||||
assignedPosition: member.assignedPosition,
|
||||
cost: member.cost,
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
const winnerTeam = match.result
|
||||
? teams.find((team) => team.side === match.result?.winnerSide)
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
id: match._id,
|
||||
title: match.title,
|
||||
date: formattedDate.date,
|
||||
time: formattedDate.time,
|
||||
status: match.status,
|
||||
description: match.description,
|
||||
map: mapIdToLabel(match.mapId),
|
||||
maxParticipants: match.maxParticipants,
|
||||
joined: Boolean(match.joined),
|
||||
participants,
|
||||
teams,
|
||||
result: match.result
|
||||
? {
|
||||
winner: winnerTeam?.name ?? sideLabel(match.result.winnerSide),
|
||||
blueScore: match.result.blueScore,
|
||||
redScore: match.result.redScore,
|
||||
}
|
||||
: undefined,
|
||||
prizes: match.prizes,
|
||||
notices: match.notices,
|
||||
schedule: match.schedule,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapApiAuctionToAuctionState(
|
||||
auction: ApiAuction,
|
||||
match: ApiMatch,
|
||||
now = new Date(),
|
||||
): AuctionStateView {
|
||||
const participantLookup = new Map(
|
||||
match.participants
|
||||
.map(mapMatchParticipantToView)
|
||||
.map((participant) => [participant.userId, participant]),
|
||||
);
|
||||
const auctionOrder = auction.order.map(mapAuctionPlayerToView);
|
||||
const auctionPlayerLookup = new Map(
|
||||
auctionOrder.map((player) => [player.userId, player]),
|
||||
);
|
||||
const blueTeam =
|
||||
auction.teams.find((team) => team.side === 'blue') ??
|
||||
({
|
||||
side: 'blue',
|
||||
captainUserId: '',
|
||||
points: 0,
|
||||
members: [],
|
||||
} satisfies ApiAuctionTeam);
|
||||
const redTeam =
|
||||
auction.teams.find((team) => team.side === 'red') ??
|
||||
({
|
||||
side: 'red',
|
||||
captainUserId: '',
|
||||
points: 0,
|
||||
members: [],
|
||||
} satisfies ApiAuctionTeam);
|
||||
|
||||
const totalPlayers = auctionOrder.length;
|
||||
const currentPlayer =
|
||||
auction.phase === 'complete'
|
||||
? null
|
||||
: auctionPlayerLookup.get(auction.order[auction.currentIndex]?.userId ?? '') ?? null;
|
||||
const currentPlayerIndex =
|
||||
auction.phase === 'complete' ? totalPlayers : auction.currentIndex;
|
||||
const timer = auction.currentDeadline
|
||||
? Math.max(
|
||||
0,
|
||||
Math.ceil((new Date(auction.currentDeadline).getTime() - now.getTime()) / 1000),
|
||||
)
|
||||
: 0;
|
||||
|
||||
return {
|
||||
matchId: auction.matchId,
|
||||
phase: auction.phase,
|
||||
teams: [
|
||||
mapAuctionTeamToView(blueTeam, auctionPlayerLookup, participantLookup),
|
||||
mapAuctionTeamToView(redTeam, auctionPlayerLookup, participantLookup),
|
||||
],
|
||||
currentPlayer,
|
||||
currentPlayerIndex,
|
||||
totalPlayers,
|
||||
auctionOrder,
|
||||
bids: auction.bids.map((bid) => ({
|
||||
side: bid.side,
|
||||
amount: bid.amount,
|
||||
timestamp: bid.timestamp,
|
||||
})),
|
||||
currentBid: auction.currentBid,
|
||||
currentBidder: auction.currentBidder ?? null,
|
||||
timer,
|
||||
maxTimer: auction.maxTimerSeconds,
|
||||
deadline: auction.currentDeadline,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
export type Position = 'TOP' | 'JGL' | 'MID' | 'ADC' | 'SUP';
|
||||
export type TeamSide = 'blue' | 'red';
|
||||
export type MatchStatus =
|
||||
| 'recruiting'
|
||||
| 'team-built'
|
||||
| 'in-progress'
|
||||
| 'finished';
|
||||
export type AuctionPhase =
|
||||
| 'waiting'
|
||||
| 'presenting'
|
||||
| 'bidding'
|
||||
| 'sold'
|
||||
| 'complete';
|
||||
export type CommunityRole = 'owner' | 'admin' | 'member';
|
||||
|
||||
export interface ApiPositionPreference {
|
||||
position: Position;
|
||||
priority: number;
|
||||
}
|
||||
|
||||
export interface ApiTierInfo {
|
||||
queueType: string;
|
||||
tier: string;
|
||||
rank: string;
|
||||
leaguePoints: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
fetchedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiChampionMasteryEntry {
|
||||
championId: string;
|
||||
championName?: string;
|
||||
level: number;
|
||||
points: number;
|
||||
}
|
||||
|
||||
export interface ApiRiotRecentStatsSummary {
|
||||
games: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
avgKills: number;
|
||||
avgDeaths: number;
|
||||
avgAssists: number;
|
||||
avgCs: number;
|
||||
mostPlayedChampionIds: string[];
|
||||
extras?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ApiRiotAccount {
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
profileIconId: number;
|
||||
revisionDate: number;
|
||||
summonerLevel: number;
|
||||
isPrimary: boolean;
|
||||
tiers: ApiTierInfo[];
|
||||
tierHistory: unknown[];
|
||||
matchIds: string[];
|
||||
championMasteries: ApiChampionMasteryEntry[];
|
||||
championRecords: Record<string, Record<string, unknown>>;
|
||||
recentStatsSummary?: ApiRiotRecentStatsSummary;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiUser {
|
||||
_id: string;
|
||||
communityId: string;
|
||||
role: CommunityRole;
|
||||
kakaoTalkId?: string;
|
||||
kakaoTalkNickname?: string;
|
||||
discordId?: string;
|
||||
discordNickname?: string;
|
||||
riotAccounts: ApiRiotAccount[];
|
||||
preferredPositions: ApiPositionPreference[];
|
||||
isActivated: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiCommunity {
|
||||
_id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
ownerUserId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiMatchParticipant {
|
||||
userId: string;
|
||||
puuid?: string;
|
||||
gameName?: string;
|
||||
tagLine?: string;
|
||||
profileIconId?: number;
|
||||
tier?: ApiTierInfo;
|
||||
preferredPositions: ApiPositionPreference[];
|
||||
joinedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiMatchTeamMember {
|
||||
userId: string;
|
||||
assignedPosition: Position;
|
||||
cost?: number;
|
||||
}
|
||||
|
||||
export interface ApiMatchTeam {
|
||||
side: TeamSide;
|
||||
name: string;
|
||||
captainUserId?: string;
|
||||
members: ApiMatchTeamMember[];
|
||||
}
|
||||
|
||||
export interface ApiMatchResult {
|
||||
winnerSide: TeamSide;
|
||||
blueScore: number;
|
||||
redScore: number;
|
||||
mvpUserId?: string;
|
||||
riotMatchIds: string[];
|
||||
}
|
||||
|
||||
export interface ApiMatchScheduleItem {
|
||||
time: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface ApiMatch {
|
||||
_id: string;
|
||||
communityId: string;
|
||||
title: string;
|
||||
description: string;
|
||||
mapId: number;
|
||||
status: MatchStatus;
|
||||
scheduledAt: string;
|
||||
maxParticipants: number;
|
||||
hostUserId?: string;
|
||||
participants: ApiMatchParticipant[];
|
||||
teams: ApiMatchTeam[];
|
||||
result?: ApiMatchResult;
|
||||
prizes: string[];
|
||||
notices: string[];
|
||||
schedule: ApiMatchScheduleItem[];
|
||||
joined?: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ApiAuctionPlayerSnapshot {
|
||||
userId: string;
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
profileIconId: number;
|
||||
preferredPositions: ApiPositionPreference[];
|
||||
tiers: ApiTierInfo[];
|
||||
masteries: ApiChampionMasteryEntry[];
|
||||
recentStatsSummary?: ApiRiotRecentStatsSummary;
|
||||
}
|
||||
|
||||
export interface ApiAuctionTeamMember {
|
||||
userId: string;
|
||||
assignedPosition: Position;
|
||||
cost: number;
|
||||
}
|
||||
|
||||
export interface ApiAuctionTeam {
|
||||
side: TeamSide;
|
||||
captainUserId: string;
|
||||
points: number;
|
||||
members: ApiAuctionTeamMember[];
|
||||
}
|
||||
|
||||
export interface ApiAuctionBid {
|
||||
side: TeamSide;
|
||||
amount: number;
|
||||
bidderUserId: string;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface ApiAuction {
|
||||
_id: string;
|
||||
matchId: string;
|
||||
phase: AuctionPhase;
|
||||
teams: ApiAuctionTeam[];
|
||||
order: ApiAuctionPlayerSnapshot[];
|
||||
currentIndex: number;
|
||||
bids: ApiAuctionBid[];
|
||||
currentBid: number;
|
||||
currentBidder?: TeamSide;
|
||||
maxTimerSeconds: number;
|
||||
currentDeadline?: string;
|
||||
initialPoints: number;
|
||||
startedAt?: string;
|
||||
completedAt?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
user: ApiUser | null;
|
||||
}
|
||||
|
||||
export interface MatchesResponse {
|
||||
matches: ApiMatch[];
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { io, type Socket } from 'socket.io-client';
|
||||
import { API_BASE_URL, useAuthUserId } from '../config';
|
||||
import type { ApiAuction, Position, TeamSide } from './types';
|
||||
|
||||
type ConnectionStatus =
|
||||
| 'idle'
|
||||
| 'connecting'
|
||||
| 'connected'
|
||||
| 'disconnected'
|
||||
| 'error';
|
||||
|
||||
interface BidPayload {
|
||||
side: TeamSide;
|
||||
amount: number;
|
||||
bidderUserId?: string;
|
||||
}
|
||||
|
||||
export function useAuctionSocket(matchId: string | undefined) {
|
||||
const authUserId = useAuthUserId();
|
||||
const socketRef = useRef<Socket | null>(null);
|
||||
const [auction, setAuction] = useState<ApiAuction | null>(null);
|
||||
const [connectionStatus, setConnectionStatus] =
|
||||
useState<ConnectionStatus>('idle');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!matchId) {
|
||||
setAuction(null);
|
||||
setConnectionStatus('idle');
|
||||
return;
|
||||
}
|
||||
|
||||
const socket = io(`${API_BASE_URL}/auction`, {
|
||||
transports: ['websocket'],
|
||||
auth: authUserId ? { 'x-auth-user-id': authUserId } : {},
|
||||
});
|
||||
|
||||
socketRef.current = socket;
|
||||
setConnectionStatus('connecting');
|
||||
setError(null);
|
||||
|
||||
socket.on('connect', () => {
|
||||
setConnectionStatus('connected');
|
||||
socket.emit('join', { matchId });
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
setConnectionStatus('disconnected');
|
||||
});
|
||||
|
||||
socket.on('state', (nextAuction: ApiAuction) => {
|
||||
setAuction(nextAuction);
|
||||
setError(null);
|
||||
});
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
});
|
||||
|
||||
return () => {
|
||||
socket.removeAllListeners();
|
||||
socket.disconnect();
|
||||
socketRef.current = null;
|
||||
setConnectionStatus('idle');
|
||||
};
|
||||
}, [authUserId, matchId]);
|
||||
|
||||
function emit(eventName: string, payload?: unknown) {
|
||||
const socket = socketRef.current;
|
||||
if (!socket || !socket.connected) {
|
||||
setError('소켓이 아직 연결되지 않았습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setError(null);
|
||||
|
||||
if (payload === undefined) {
|
||||
socket.emit(eventName);
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit(eventName, payload);
|
||||
}
|
||||
|
||||
return {
|
||||
auction,
|
||||
connectionStatus,
|
||||
error,
|
||||
placeBid(payload: BidPayload) {
|
||||
emit('bid', payload);
|
||||
},
|
||||
openBidding() {
|
||||
emit('open-bidding', {});
|
||||
},
|
||||
markSold(assignedPosition?: Position) {
|
||||
emit('sold', assignedPosition ? { assignedPosition } : {});
|
||||
},
|
||||
next() {
|
||||
emit('next', {});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,427 +0,0 @@
|
||||
import type { AuctionPlayer, AuctionState, AuctionTeam } from "./auction-types";
|
||||
|
||||
const auctionPlayers: AuctionPlayer[] = [
|
||||
{
|
||||
id: 3,
|
||||
summonerName: "프리리",
|
||||
tag: "0000",
|
||||
tier: {
|
||||
previousSeason: "플래티넘 I",
|
||||
current: "에메랄드 I",
|
||||
peak: "에메랄드 I",
|
||||
},
|
||||
mainPosition: "TOP",
|
||||
subPosition: "MID",
|
||||
profileIconId: 588,
|
||||
masteries: [
|
||||
{
|
||||
championName: "신드라",
|
||||
championId: "Syndra",
|
||||
level: 7,
|
||||
points: 124300,
|
||||
},
|
||||
{
|
||||
championName: "아리",
|
||||
championId: "Ahri",
|
||||
level: 7,
|
||||
points: 98200,
|
||||
},
|
||||
{
|
||||
championName: "르블랑",
|
||||
championId: "Leblanc",
|
||||
level: 6,
|
||||
points: 45100,
|
||||
},
|
||||
],
|
||||
recentStats: {
|
||||
games: 20,
|
||||
wins: 13,
|
||||
losses: 7,
|
||||
kda: { kills: 8.2, deaths: 7.0, assists: 7.8 },
|
||||
avgCs: 178,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
summonerName: "면정학",
|
||||
tag: "1234",
|
||||
tier: {
|
||||
previousSeason: "플래티넘 III",
|
||||
current: "에메랄드 III",
|
||||
peak: "에메랄드 III",
|
||||
},
|
||||
mainPosition: "MID",
|
||||
subPosition: "ADC",
|
||||
profileIconId: 6207,
|
||||
masteries: [
|
||||
{
|
||||
championName: "오리아나",
|
||||
championId: "Orianna",
|
||||
level: 7,
|
||||
points: 312500,
|
||||
},
|
||||
{
|
||||
championName: "신드라",
|
||||
championId: "Syndra",
|
||||
level: 7,
|
||||
points: 156800,
|
||||
},
|
||||
{ championName: "빅토르", championId: "Viktor", level: 6, points: 67200 },
|
||||
],
|
||||
recentStats: {
|
||||
games: 20,
|
||||
wins: 9,
|
||||
losses: 11,
|
||||
kda: { kills: 5.4, deaths: 7.3, assists: 7.9 },
|
||||
avgCs: 195,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
summonerName: "던던",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "마스터 47LP",
|
||||
current: "다이아몬드 II",
|
||||
peak: "마스터 6LP",
|
||||
},
|
||||
mainPosition: "MID",
|
||||
subPosition: "SUP",
|
||||
profileIconId: 7036,
|
||||
masteries: [
|
||||
{ championName: "조이", championId: "Zoe", level: 7, points: 189400 },
|
||||
{
|
||||
championName: "제라스",
|
||||
championId: "Xerath",
|
||||
level: 7,
|
||||
points: 134200,
|
||||
},
|
||||
{
|
||||
championName: "흐웨이",
|
||||
championId: "Hwei",
|
||||
level: 6,
|
||||
points: 78900,
|
||||
},
|
||||
],
|
||||
recentStats: {
|
||||
games: 15,
|
||||
wins: 5,
|
||||
losses: 10,
|
||||
kda: { kills: 6.1, deaths: 5.1, assists: 6.0 },
|
||||
avgCs: 212,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
summonerName: "정글러123",
|
||||
tag: "KR3",
|
||||
tier: {
|
||||
previousSeason: "골드 I",
|
||||
current: "플래티넘 III",
|
||||
peak: "플래티넘 III",
|
||||
},
|
||||
mainPosition: "JGL",
|
||||
subPosition: "SUP",
|
||||
profileIconId: 4789,
|
||||
masteries: [
|
||||
{ championName: "리신", championId: "LeeSin", level: 7, points: 201300 },
|
||||
{ championName: "비에고", championId: "Viego", level: 6, points: 87600 },
|
||||
{ championName: "렝가", championId: "Rengar", level: 6, points: 65400 },
|
||||
],
|
||||
recentStats: {
|
||||
games: 38,
|
||||
wins: 18,
|
||||
losses: 20,
|
||||
kda: { kills: 5.4, deaths: 5.8, assists: 8.1 },
|
||||
avgCs: 142,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
summonerName: "탑솔장인",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "에메랄드 IV",
|
||||
current: "에메랄드 II",
|
||||
peak: "에메랄드 I",
|
||||
},
|
||||
mainPosition: "TOP",
|
||||
subPosition: "JGL",
|
||||
profileIconId: 5450,
|
||||
masteries: [
|
||||
{ championName: "잭스", championId: "Jax", level: 7, points: 145600 },
|
||||
{ championName: "요릭", championId: "Yorick", level: 7, points: 112400 },
|
||||
{ championName: "나서스", championId: "Nasus", level: 6, points: 89300 },
|
||||
],
|
||||
recentStats: {
|
||||
games: 47,
|
||||
wins: 27,
|
||||
losses: 20,
|
||||
kda: { kills: 5.6, deaths: 3.9, assists: 4.1 },
|
||||
avgCs: 201,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
summonerName: "요들마스터",
|
||||
tag: "KR2",
|
||||
tier: {
|
||||
previousSeason: "다이아 II",
|
||||
current: "다이아 III",
|
||||
peak: "다이아 I",
|
||||
},
|
||||
mainPosition: "SUP",
|
||||
subPosition: "MID",
|
||||
profileIconId: 4951,
|
||||
masteries: [
|
||||
{
|
||||
championName: "쓰레쉬",
|
||||
championId: "Thresh",
|
||||
level: 7,
|
||||
points: 267800,
|
||||
},
|
||||
{
|
||||
championName: "노틸러스",
|
||||
championId: "Nautilus",
|
||||
level: 7,
|
||||
points: 134500,
|
||||
},
|
||||
{ championName: "룰루", championId: "Lulu", level: 6, points: 78900 },
|
||||
],
|
||||
recentStats: {
|
||||
games: 61,
|
||||
wins: 36,
|
||||
losses: 25,
|
||||
kda: { kills: 2.1, deaths: 3.8, assists: 14.2 },
|
||||
avgCs: 32,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
summonerName: "서폿장인",
|
||||
tag: "0001",
|
||||
tier: {
|
||||
previousSeason: "다이아 III",
|
||||
current: "다이아 IV",
|
||||
peak: "다이아 II",
|
||||
},
|
||||
mainPosition: "SUP",
|
||||
subPosition: "ADC",
|
||||
profileIconId: 4900,
|
||||
masteries: [
|
||||
{ championName: "유미", championId: "Yuumi", level: 7, points: 198700 },
|
||||
{ championName: "소나", championId: "Sona", level: 7, points: 145200 },
|
||||
{ championName: "나미", championId: "Nami", level: 6, points: 92100 },
|
||||
],
|
||||
recentStats: {
|
||||
games: 52,
|
||||
wins: 30,
|
||||
losses: 22,
|
||||
kda: { kills: 1.8, deaths: 4.2, assists: 16.3 },
|
||||
avgCs: 25,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
summonerName: "Shadow Wolf",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "다이아 IV",
|
||||
current: "플래티넘 II",
|
||||
peak: "다이아 II",
|
||||
},
|
||||
mainPosition: "JGL",
|
||||
subPosition: "TOP",
|
||||
profileIconId: 4834,
|
||||
masteries: [
|
||||
{
|
||||
championName: "니달리",
|
||||
championId: "Nidalee",
|
||||
level: 7,
|
||||
points: 178900,
|
||||
},
|
||||
{ championName: "엘리스", championId: "Elise", level: 7, points: 134500 },
|
||||
{
|
||||
championName: "그레이브즈",
|
||||
championId: "Graves",
|
||||
level: 6,
|
||||
points: 67800,
|
||||
},
|
||||
],
|
||||
recentStats: {
|
||||
games: 44,
|
||||
wins: 22,
|
||||
losses: 22,
|
||||
kda: { kills: 6.5, deaths: 4.7, assists: 7.8 },
|
||||
avgCs: 156,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
function createInitialState(): AuctionState {
|
||||
const blueTeam: AuctionTeam = {
|
||||
side: "blue",
|
||||
captainName: "프리리",
|
||||
points: 1000,
|
||||
members: [],
|
||||
};
|
||||
const redTeam: AuctionTeam = {
|
||||
side: "red",
|
||||
captainName: "IceQueen",
|
||||
points: 1000,
|
||||
members: [],
|
||||
};
|
||||
|
||||
return {
|
||||
matchId: 1,
|
||||
phase: "waiting",
|
||||
teams: [blueTeam, redTeam],
|
||||
currentPlayer: null,
|
||||
currentPlayerIndex: -1,
|
||||
totalPlayers: auctionPlayers.length,
|
||||
auctionOrder: auctionPlayers,
|
||||
bids: [],
|
||||
currentBid: 0,
|
||||
currentBidder: null,
|
||||
timer: 0,
|
||||
maxTimer: 15,
|
||||
};
|
||||
}
|
||||
|
||||
// Mock WebSocket - 경매 시뮬레이션
|
||||
export function createMockAuction(onUpdate: (state: AuctionState) => void) {
|
||||
let state = createInitialState();
|
||||
let timerInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let isRunning = false;
|
||||
|
||||
function emit() {
|
||||
onUpdate({
|
||||
...state,
|
||||
teams: [{ ...state.teams[0] }, { ...state.teams[1] }],
|
||||
});
|
||||
}
|
||||
|
||||
function clearTimer() {
|
||||
if (timerInterval) {
|
||||
clearInterval(timerInterval);
|
||||
timerInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
function startBidTimer() {
|
||||
clearTimer();
|
||||
state.timer = state.maxTimer;
|
||||
emit();
|
||||
|
||||
timerInterval = setInterval(() => {
|
||||
state.timer--;
|
||||
emit();
|
||||
if (state.timer <= 0) {
|
||||
clearTimer();
|
||||
handleTimerEnd();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function handleTimerEnd() {
|
||||
if (state.currentBidder && state.currentPlayer) {
|
||||
// 낙찰
|
||||
const teamIdx = state.currentBidder === "blue" ? 0 : 1;
|
||||
state.teams[teamIdx].points -= state.currentBid;
|
||||
state.teams[teamIdx].members.push({
|
||||
...state.currentPlayer,
|
||||
cost: state.currentBid,
|
||||
assignedPosition: state.currentPlayer.mainPosition,
|
||||
});
|
||||
state.phase = "sold";
|
||||
emit();
|
||||
|
||||
// 다음 선수로
|
||||
setTimeout(() => {
|
||||
if (!isRunning) return;
|
||||
nextPlayer();
|
||||
}, 2000);
|
||||
} else {
|
||||
// 유찰 → 최소 가격으로 랜덤 팀에 배정
|
||||
if (state.currentPlayer) {
|
||||
const randomSide = Math.random() > 0.5 ? 0 : 1;
|
||||
const minCost = 50;
|
||||
state.teams[randomSide].points -= minCost;
|
||||
state.teams[randomSide].members.push({
|
||||
...state.currentPlayer,
|
||||
cost: minCost,
|
||||
assignedPosition: state.currentPlayer.mainPosition,
|
||||
});
|
||||
state.phase = "sold";
|
||||
state.currentBid = minCost;
|
||||
state.currentBidder = randomSide === 0 ? "blue" : "red";
|
||||
emit();
|
||||
|
||||
setTimeout(() => {
|
||||
if (!isRunning) return;
|
||||
nextPlayer();
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nextPlayer() {
|
||||
const nextIdx = state.currentPlayerIndex + 1;
|
||||
if (nextIdx >= state.auctionOrder.length) {
|
||||
state.phase = "complete";
|
||||
state.currentPlayer = null;
|
||||
emit();
|
||||
return;
|
||||
}
|
||||
|
||||
state.currentPlayerIndex = nextIdx;
|
||||
state.currentPlayer = state.auctionOrder[nextIdx];
|
||||
state.bids = [];
|
||||
state.currentBid = 0;
|
||||
state.currentBidder = null;
|
||||
state.phase = "presenting";
|
||||
emit();
|
||||
|
||||
// 2초 뒤 입찰 시작
|
||||
setTimeout(() => {
|
||||
if (!isRunning) return;
|
||||
state.phase = "bidding";
|
||||
startBidTimer();
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
return {
|
||||
start() {
|
||||
isRunning = true;
|
||||
state.phase = "waiting";
|
||||
emit();
|
||||
setTimeout(() => {
|
||||
if (!isRunning) return;
|
||||
nextPlayer();
|
||||
}, 1500);
|
||||
},
|
||||
|
||||
bid(side: "blue" | "red", amount: number) {
|
||||
if (state.phase !== "bidding") return;
|
||||
const teamIdx = side === "blue" ? 0 : 1;
|
||||
if (amount <= state.currentBid) return;
|
||||
if (amount > state.teams[teamIdx].points) return;
|
||||
|
||||
state.currentBid = amount;
|
||||
state.currentBidder = side;
|
||||
state.bids.push({ side, amount, timestamp: Date.now() });
|
||||
// 입찰 시 타이머 리셋 (최소 5초)
|
||||
if (state.timer < 5) {
|
||||
state.timer = 5;
|
||||
}
|
||||
emit();
|
||||
},
|
||||
|
||||
destroy() {
|
||||
isRunning = false;
|
||||
clearTimer();
|
||||
},
|
||||
|
||||
getState: () => state,
|
||||
};
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import type { Participant, Position } from "./mock";
|
||||
|
||||
export interface ChampionMastery {
|
||||
championName: string;
|
||||
championId: string;
|
||||
level: number;
|
||||
points: number;
|
||||
}
|
||||
|
||||
export interface RecentStats {
|
||||
games: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
kda: { kills: number; deaths: number; assists: number };
|
||||
avgCs: number;
|
||||
}
|
||||
|
||||
export interface AuctionPlayer extends Participant {
|
||||
masteries: ChampionMastery[];
|
||||
recentStats: RecentStats;
|
||||
}
|
||||
|
||||
export interface AuctionTeam {
|
||||
side: "blue" | "red";
|
||||
captainName: string;
|
||||
points: number;
|
||||
members: (AuctionPlayer & { cost: number; assignedPosition: Position })[];
|
||||
}
|
||||
|
||||
export type AuctionPhase =
|
||||
| "waiting"
|
||||
| "presenting"
|
||||
| "bidding"
|
||||
| "sold"
|
||||
| "complete";
|
||||
|
||||
export interface BidEntry {
|
||||
side: "blue" | "red";
|
||||
amount: number;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface AuctionState {
|
||||
matchId: number;
|
||||
phase: AuctionPhase;
|
||||
teams: [AuctionTeam, AuctionTeam];
|
||||
currentPlayer: AuctionPlayer | null;
|
||||
currentPlayerIndex: number;
|
||||
totalPlayers: number;
|
||||
auctionOrder: AuctionPlayer[];
|
||||
bids: BidEntry[];
|
||||
currentBid: number;
|
||||
currentBidder: "blue" | "red" | null;
|
||||
timer: number;
|
||||
maxTimer: number;
|
||||
}
|
||||
|
||||
// WebSocket message types (서버 → 클라이언트)
|
||||
export type ServerMessage =
|
||||
| { type: "auction:init"; state: AuctionState }
|
||||
| { type: "auction:present"; player: AuctionPlayer; index: number }
|
||||
| { type: "auction:bid"; side: "blue" | "red"; amount: number }
|
||||
| { type: "auction:timer"; remaining: number }
|
||||
| { type: "auction:sold"; side: "blue" | "red"; player: AuctionPlayer; cost: number }
|
||||
| { type: "auction:complete"; teams: [AuctionTeam, AuctionTeam] };
|
||||
|
||||
// WebSocket message types (클라이언트 → 서버)
|
||||
export type ClientMessage =
|
||||
| { type: "bid"; amount: number };
|
||||
@@ -0,0 +1,58 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { setAuthUserId, useAuthUserId } from '../config';
|
||||
|
||||
export default function DevAuthSwitcher() {
|
||||
const authUserId = useAuthUserId();
|
||||
const queryClient = useQueryClient();
|
||||
const [inputValue, setInputValue] = useState(authUserId ?? '');
|
||||
|
||||
useEffect(() => {
|
||||
setInputValue(authUserId ?? '');
|
||||
}, [authUserId]);
|
||||
|
||||
if (!import.meta.env.DEV) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function updateAuthUserId(nextValue: string | null) {
|
||||
setAuthUserId(nextValue);
|
||||
void queryClient.invalidateQueries();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed right-4 bottom-4 z-50 w-72 border border-base-content/10 bg-base-100/95 backdrop-blur px-3 py-3 shadow-xl">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
Dev Auth
|
||||
</div>
|
||||
<div className="mt-2 text-[11px] text-base-content/45">
|
||||
X-Auth-User-Id
|
||||
</div>
|
||||
<input
|
||||
value={inputValue}
|
||||
onChange={(event) => setInputValue(event.target.value)}
|
||||
placeholder="Mongo User ID"
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-2 py-2 text-xs text-base-content focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
<div className="mt-2 flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-xs px-3"
|
||||
onClick={() => updateAuthUserId(inputValue)}
|
||||
>
|
||||
Set
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs px-3"
|
||||
onClick={() => updateAuthUserId(null)}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-2 text-[10px] text-base-content/35 break-all">
|
||||
현재값: {authUserId ?? '없음'}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
export type DevCaptainSide = 'spectator' | 'blue' | 'red';
|
||||
|
||||
const AUTH_USER_ID_STORAGE_KEY = 'lolympus.authUserId';
|
||||
const DEV_CAPTAIN_SIDE_STORAGE_KEY = 'lolympus.devCaptainSide';
|
||||
const AUTH_USER_CHANGED_EVENT = 'lolympus:auth-user-changed';
|
||||
const CAPTAIN_SIDE_CHANGED_EVENT = 'lolympus:captain-side-changed';
|
||||
|
||||
export const API_BASE_URL = (
|
||||
import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:3000'
|
||||
).replace(/\/$/, '');
|
||||
|
||||
export const DEFAULT_COMMUNITY_ID = (
|
||||
import.meta.env.VITE_DEFAULT_COMMUNITY_ID ?? ''
|
||||
).trim();
|
||||
|
||||
function dispatchWindowEvent(eventName: string) {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.dispatchEvent(new Event(eventName));
|
||||
}
|
||||
|
||||
function subscribeToWindowChanges(eventName: string, callback: () => void) {
|
||||
if (typeof window === 'undefined') {
|
||||
return () => undefined;
|
||||
}
|
||||
|
||||
const handleChange = () => callback();
|
||||
window.addEventListener(eventName, handleChange);
|
||||
window.addEventListener('storage', handleChange);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener(eventName, handleChange);
|
||||
window.removeEventListener('storage', handleChange);
|
||||
};
|
||||
}
|
||||
|
||||
export function getAuthUserId(): string | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
const value = window.localStorage.getItem(AUTH_USER_ID_STORAGE_KEY)?.trim();
|
||||
return value ? value : null;
|
||||
}
|
||||
|
||||
export function setAuthUserId(userId: string | null) {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
if (!userId?.trim()) {
|
||||
window.localStorage.removeItem(AUTH_USER_ID_STORAGE_KEY);
|
||||
} else {
|
||||
window.localStorage.setItem(AUTH_USER_ID_STORAGE_KEY, userId.trim());
|
||||
}
|
||||
|
||||
dispatchWindowEvent(AUTH_USER_CHANGED_EVENT);
|
||||
}
|
||||
|
||||
export function getDevCaptainSide(): DevCaptainSide {
|
||||
if (typeof window === 'undefined') return 'spectator';
|
||||
|
||||
const value = window.localStorage.getItem(
|
||||
DEV_CAPTAIN_SIDE_STORAGE_KEY,
|
||||
) as DevCaptainSide | null;
|
||||
|
||||
if (value === 'blue' || value === 'red' || value === 'spectator') {
|
||||
return value;
|
||||
}
|
||||
|
||||
return 'spectator';
|
||||
}
|
||||
|
||||
export function setDevCaptainSide(side: DevCaptainSide) {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.localStorage.setItem(DEV_CAPTAIN_SIDE_STORAGE_KEY, side);
|
||||
dispatchWindowEvent(CAPTAIN_SIDE_CHANGED_EVENT);
|
||||
}
|
||||
|
||||
export function useAuthUserId(): string | null {
|
||||
return useSyncExternalStore<string | null>(
|
||||
(callback) => subscribeToWindowChanges(AUTH_USER_CHANGED_EVENT, callback),
|
||||
getAuthUserId,
|
||||
() => null,
|
||||
);
|
||||
}
|
||||
|
||||
export function useDevCaptainSide(): DevCaptainSide {
|
||||
return useSyncExternalStore<DevCaptainSide>(
|
||||
(callback) => subscribeToWindowChanges(CAPTAIN_SIDE_CHANGED_EVENT, callback),
|
||||
getDevCaptainSide,
|
||||
() => 'spectator',
|
||||
);
|
||||
}
|
||||
+19
-6
@@ -1,10 +1,23 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import './index.css';
|
||||
import App from './App.tsx';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 10 * 1000,
|
||||
gcTime: 5 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
);
|
||||
@@ -1,404 +0,0 @@
|
||||
// LoL 포지션
|
||||
export type Position = "TOP" | "JGL" | "MID" | "ADC" | "SUP";
|
||||
|
||||
export type MatchStatus = "recruiting" | "team-built" | "finished";
|
||||
|
||||
export interface TierInfo {
|
||||
previousSeason: string;
|
||||
current: string;
|
||||
peak: string;
|
||||
}
|
||||
|
||||
export interface Participant {
|
||||
id: number;
|
||||
summonerName: string;
|
||||
tag: string;
|
||||
tier: TierInfo;
|
||||
mainPosition: Position;
|
||||
subPosition: Position;
|
||||
profileIconId: number;
|
||||
}
|
||||
|
||||
export interface Team {
|
||||
name: string;
|
||||
participants: (Participant & { assignedPosition: Position })[];
|
||||
}
|
||||
|
||||
export interface MatchDetail {
|
||||
id: number;
|
||||
title: string;
|
||||
date: string;
|
||||
time: string;
|
||||
status: MatchStatus;
|
||||
description: string;
|
||||
map: string;
|
||||
maxParticipants: number;
|
||||
participants: Participant[];
|
||||
teams?: [Team, Team];
|
||||
result?: { winner: string; blueScore: number; redScore: number };
|
||||
prizes?: string[];
|
||||
notices?: string[];
|
||||
schedule?: { time: string; label: string }[];
|
||||
}
|
||||
|
||||
export const positionLabel: Record<Position, string> = {
|
||||
TOP: "탑",
|
||||
JGL: "정글",
|
||||
MID: "미드",
|
||||
ADC: "원딜",
|
||||
SUP: "서폿",
|
||||
};
|
||||
|
||||
import posTop from "./assets/position/Top_icon.png";
|
||||
import posJgl from "./assets/position/Jungle_icon.png";
|
||||
import posMid from "./assets/position/Middle_icon.png";
|
||||
import posAdc from "./assets/position/Bottom_icon.png";
|
||||
import posSup from "./assets/position/Support_icon.png";
|
||||
|
||||
export const positionIcon: Record<Position, string> = {
|
||||
TOP: posTop,
|
||||
JGL: posJgl,
|
||||
MID: posMid,
|
||||
ADC: posAdc,
|
||||
SUP: posSup,
|
||||
};
|
||||
|
||||
const participants: Participant[] = [
|
||||
{
|
||||
id: 1,
|
||||
summonerName: "프리리",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "플래티넘 I",
|
||||
current: "다이아 IV",
|
||||
peak: "다이아 IV",
|
||||
},
|
||||
mainPosition: "MID",
|
||||
subPosition: "ADC",
|
||||
profileIconId: 588,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
summonerName: "호호불어먹어요",
|
||||
tag: "0000",
|
||||
tier: {
|
||||
previousSeason: "다이아 IV",
|
||||
current: "플래티넘 II",
|
||||
peak: "다이아 IV",
|
||||
},
|
||||
mainPosition: "JGL",
|
||||
subPosition: "TOP",
|
||||
profileIconId: 7015,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
summonerName: "소다",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "플래티넘 I",
|
||||
current: "에메랄드 I",
|
||||
peak: "에메랄드 I",
|
||||
},
|
||||
mainPosition: "TOP",
|
||||
subPosition: "MID",
|
||||
profileIconId: 5186,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
summonerName: "잉호바",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "다이아 II",
|
||||
current: "다이아 III",
|
||||
peak: "마스터 200LP",
|
||||
},
|
||||
mainPosition: "SUP",
|
||||
subPosition: "MID",
|
||||
profileIconId: 7050,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
summonerName: "잉호바탭키도둑",
|
||||
tag: "Tab",
|
||||
tier: {
|
||||
previousSeason: "에메랄드 II",
|
||||
current: "플래티넘 I",
|
||||
peak: "에메랄드 I",
|
||||
},
|
||||
mainPosition: "ADC",
|
||||
subPosition: "SUP",
|
||||
profileIconId: 5231,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
summonerName: "osu",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "플래티넘 III",
|
||||
current: "에메랄드 III",
|
||||
peak: "마스터 200LP",
|
||||
},
|
||||
mainPosition: "MID",
|
||||
subPosition: "JGL",
|
||||
profileIconId: 7091,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
summonerName: "IceQueen",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "다이아 I",
|
||||
current: "다이아 II",
|
||||
peak: "마스터 50LP",
|
||||
},
|
||||
mainPosition: "ADC",
|
||||
subPosition: "MID",
|
||||
profileIconId: 5102,
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
summonerName: "정글러123",
|
||||
tag: "KR3",
|
||||
tier: {
|
||||
previousSeason: "골드 I",
|
||||
current: "플래티넘 III",
|
||||
peak: "플래티넘 III",
|
||||
},
|
||||
mainPosition: "JGL",
|
||||
subPosition: "SUP",
|
||||
profileIconId: 4789,
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
summonerName: "탑솔장인",
|
||||
tag: "KR1",
|
||||
tier: {
|
||||
previousSeason: "에메랄드 IV",
|
||||
current: "에메랄드 II",
|
||||
peak: "에메랄드 I",
|
||||
},
|
||||
mainPosition: "TOP",
|
||||
subPosition: "JGL",
|
||||
profileIconId: 5450,
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
summonerName: "서폿장인",
|
||||
tag: "0001",
|
||||
tier: {
|
||||
previousSeason: "다이아 III",
|
||||
current: "다이아 IV",
|
||||
peak: "다이아 II",
|
||||
},
|
||||
mainPosition: "SUP",
|
||||
subPosition: "ADC",
|
||||
profileIconId: 4900,
|
||||
},
|
||||
];
|
||||
|
||||
// 내전 1: 팀빌딩 전 (모집 중)
|
||||
export const match_recruiting: MatchDetail = {
|
||||
id: 2,
|
||||
title: "쌀먹 내전",
|
||||
date: "2026년 4월 19일 (일)",
|
||||
time: "오후 3시",
|
||||
status: "recruiting",
|
||||
description: "JEIFF님의 후원으로 개최되는 쌀먹 내전. 많관부~",
|
||||
map: "소환사의 협곡",
|
||||
maxParticipants: 10,
|
||||
participants: participants.slice(0, 6),
|
||||
prizes: ["5명 추첨 커피", "MVP: 스킨 선물"],
|
||||
notices: [
|
||||
"시작 10분 전까지 커스텀 방에 입장해주세요.",
|
||||
"무단 불참 시 다음 내전 참여가 제한될 수 있습니다.",
|
||||
"게임 중 과도한 욕설은 자제해주세요.",
|
||||
],
|
||||
schedule: [
|
||||
{ time: "21:45", label: "로비 오픈" },
|
||||
{ time: "21:50", label: "경매 시작" },
|
||||
{ time: "22:00", label: "게임 시작" },
|
||||
{ time: "~24:00", label: "예상 종료" },
|
||||
],
|
||||
};
|
||||
|
||||
// 내전 2: 팀빌딩 완료, 게임 시작 전
|
||||
export const match_teamBuilt: MatchDetail = {
|
||||
id: 1,
|
||||
title: "롤림푸스 멸망전 시즌 4 결승전",
|
||||
date: "2026년 4월 18일 (토)",
|
||||
time: "오후 8시",
|
||||
status: "team-built",
|
||||
description: "시즌 4 최종 결승전입니다. ABC팀 VS DEF팀으로 진행됩니다.",
|
||||
map: "소환사의 협곡",
|
||||
maxParticipants: 10,
|
||||
participants,
|
||||
teams: [
|
||||
{
|
||||
name: "블루팀",
|
||||
participants: [
|
||||
{ ...participants[0], assignedPosition: "MID" },
|
||||
{ ...participants[1], assignedPosition: "JGL" },
|
||||
{ ...participants[2], assignedPosition: "TOP" },
|
||||
{ ...participants[4], assignedPosition: "ADC" },
|
||||
{ ...participants[9], assignedPosition: "SUP" },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "레드팀",
|
||||
participants: [
|
||||
{ ...participants[6], assignedPosition: "ADC" },
|
||||
{ ...participants[5], assignedPosition: "MID" },
|
||||
{ ...participants[8], assignedPosition: "TOP" },
|
||||
{ ...participants[7], assignedPosition: "JGL" },
|
||||
{ ...participants[3], assignedPosition: "SUP" },
|
||||
],
|
||||
},
|
||||
],
|
||||
prizes: ["승리 팀: 햄버거 세트", "패배 팀: 컴포즈커피 아메리카노"],
|
||||
notices: [
|
||||
"결승전은 3판 2선으로 진행됩니다.",
|
||||
"시작 15분 전까지 디스코드 음성채널에 입장해주세요.",
|
||||
"경기 중 감정 표현과 도발 모션은 금지입니다.",
|
||||
],
|
||||
schedule: [
|
||||
{ time: "19:30", label: "디스코드 집합" },
|
||||
{ time: "19:45", label: "팀빌딩 확인" },
|
||||
{ time: "20:00", label: "1세트 시작" },
|
||||
{ time: "20:40", label: "2세트 시작 (예상)" },
|
||||
{ time: "21:20", label: "3세트 시작 (필요시)" },
|
||||
],
|
||||
};
|
||||
|
||||
// 내전 3: 게임 종료
|
||||
export const match_finished: MatchDetail = {
|
||||
id: 101,
|
||||
title: "시즌 4 준결승",
|
||||
date: "2026년 4월 11일 (금)",
|
||||
time: "오후 8시",
|
||||
status: "finished",
|
||||
description: "시즌 4 준결승전입니다.",
|
||||
map: "소환사의 협곡",
|
||||
maxParticipants: 10,
|
||||
participants,
|
||||
teams: [
|
||||
{
|
||||
name: "블루팀",
|
||||
participants: [
|
||||
{ ...participants[0], assignedPosition: "MID" },
|
||||
{ ...participants[1], assignedPosition: "JGL" },
|
||||
{ ...participants[2], assignedPosition: "TOP" },
|
||||
{ ...participants[4], assignedPosition: "ADC" },
|
||||
{ ...participants[9], assignedPosition: "SUP" },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "레드팀",
|
||||
participants: [
|
||||
{ ...participants[6], assignedPosition: "ADC" },
|
||||
{ ...participants[5], assignedPosition: "MID" },
|
||||
{ ...participants[8], assignedPosition: "TOP" },
|
||||
{ ...participants[7], assignedPosition: "JGL" },
|
||||
{ ...participants[3], assignedPosition: "SUP" },
|
||||
],
|
||||
},
|
||||
],
|
||||
result: { winner: "블루팀", blueScore: 2, redScore: 1 },
|
||||
prizes: ["1등 팀: RP 10,000 지급", "MVP: 프리리 (MID)"],
|
||||
notices: [],
|
||||
schedule: [],
|
||||
};
|
||||
|
||||
// 메인 페이지용
|
||||
export const nextMatchSummary = {
|
||||
id: match_teamBuilt.id,
|
||||
title: match_teamBuilt.title,
|
||||
date: match_teamBuilt.date,
|
||||
time: match_teamBuilt.time,
|
||||
participants: match_teamBuilt.participants.length,
|
||||
maxParticipants: match_teamBuilt.maxParticipants,
|
||||
status: "모집 완료",
|
||||
description: match_teamBuilt.description,
|
||||
map: match_teamBuilt.map,
|
||||
};
|
||||
|
||||
export const upcomingMatches = [
|
||||
{
|
||||
id: match_recruiting.id,
|
||||
title: match_recruiting.title,
|
||||
date: match_recruiting.date,
|
||||
time: match_recruiting.time,
|
||||
participants: match_recruiting.participants.length,
|
||||
maxParticipants: match_recruiting.maxParticipants,
|
||||
status: "모집 중",
|
||||
map: match_recruiting.map,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: "칼바람 나락 내전",
|
||||
date: "2026년 4월 25일 (토)",
|
||||
time: "오후 7시",
|
||||
participants: 2,
|
||||
maxParticipants: 10,
|
||||
status: "모집 중",
|
||||
map: "칼바람 나락",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: "롤림푸스 시즌 5 개막전",
|
||||
date: "2026년 5월 2일 (토)",
|
||||
time: "오후 8시",
|
||||
participants: 0,
|
||||
maxParticipants: 10,
|
||||
status: "예정",
|
||||
map: "소환사의 협곡",
|
||||
},
|
||||
];
|
||||
|
||||
export const pastMatches = [
|
||||
{
|
||||
id: 101,
|
||||
title: "시즌 4 준결승",
|
||||
date: "2026년 4월 11일",
|
||||
participants: 10,
|
||||
result: "블루팀 승리",
|
||||
map: "소환사의 협곡",
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
title: "평일 내전",
|
||||
date: "2026년 4월 9일",
|
||||
participants: 10,
|
||||
result: "레드팀 승리",
|
||||
map: "소환사의 협곡",
|
||||
},
|
||||
{
|
||||
id: 103,
|
||||
title: "칼바람 나락 내전",
|
||||
date: "2026년 4월 5일",
|
||||
participants: 10,
|
||||
result: "-",
|
||||
map: "칼바람 나락",
|
||||
},
|
||||
{
|
||||
id: 104,
|
||||
title: "시즌 4 8강",
|
||||
date: "2026년 4월 4일",
|
||||
participants: 10,
|
||||
result: "블루팀 승리",
|
||||
map: "소환사의 협곡",
|
||||
},
|
||||
{
|
||||
id: 105,
|
||||
title: "주말 내전",
|
||||
date: "2026년 3월 29일",
|
||||
participants: 10,
|
||||
result: "레드팀 승리",
|
||||
map: "소환사의 협곡",
|
||||
},
|
||||
];
|
||||
|
||||
export function getMatchById(id: number): MatchDetail | undefined {
|
||||
return [match_recruiting, match_teamBuilt, match_finished].find(
|
||||
(m) => m.id === id,
|
||||
);
|
||||
}
|
||||
+313
-249
@@ -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
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user