1497 lines
52 KiB
TypeScript
1497 lines
52 KiB
TypeScript
import {
|
|
lazy,
|
|
Suspense,
|
|
useEffect,
|
|
useMemo,
|
|
useRef,
|
|
useState,
|
|
type FormEvent,
|
|
type KeyboardEvent,
|
|
} from 'react';
|
|
import { useQueryClient } from '@tanstack/react-query';
|
|
import { AlertTriangle, SendHorizontal } from 'lucide-react';
|
|
import { Link, useLocation, useNavigate, useParams } from 'react-router';
|
|
import {
|
|
useAuction,
|
|
useAuctionHistory,
|
|
useDdragonManifest,
|
|
useMatch,
|
|
useMe,
|
|
useResetAuction,
|
|
useUndoAuction,
|
|
useUserHistoryProfile,
|
|
} from '../api/hooks';
|
|
import {
|
|
mapApiAuctionToAuctionState,
|
|
type AuctionPlayerView,
|
|
type AuctionStateView,
|
|
} from '../api/mappers';
|
|
import { useAuctionSocket } from '../api/useAuctionSocket';
|
|
import {
|
|
DEFAULT_COMMUNITY_ID,
|
|
setDevCaptainTeamIndex,
|
|
useDevCaptainTeamIndex,
|
|
} from '../config';
|
|
import { ApiError } from '../lib/api';
|
|
import {
|
|
championDisplayName,
|
|
championIconUrl,
|
|
profileIconUrl,
|
|
} from '../lib/ddragon';
|
|
import {
|
|
positionIcon,
|
|
positionLabel,
|
|
teamIndexColorClasses,
|
|
teamIndexLabel,
|
|
} from '../lib/league';
|
|
import { RankBadge, ResponsiveTierLabel } from '../components/RankBadge';
|
|
import type {
|
|
ApiAuction,
|
|
ApiAuctionChatMessage,
|
|
ApiRiotLaneStats,
|
|
ApiUser,
|
|
Position,
|
|
} from '../api/types';
|
|
|
|
const TierHistoryChart = lazy(() => import('../components/TierHistoryChart'));
|
|
|
|
type CaptainRole = {
|
|
teamIndex: number;
|
|
};
|
|
|
|
function formatPoints(value: number) {
|
|
return value.toLocaleString();
|
|
}
|
|
|
|
function relativeTime(dateLike: string) {
|
|
const seconds = Math.max(
|
|
0,
|
|
Math.floor((Date.now() - new Date(dateLike).getTime()) / 1000),
|
|
);
|
|
if (seconds < 60) return `${seconds}초 전`;
|
|
const minutes = Math.floor(seconds / 60);
|
|
if (minutes < 60) return `${minutes}분 전`;
|
|
const hours = Math.floor(minutes / 60);
|
|
if (hours < 24) return `${hours}시간 전`;
|
|
return `${Math.floor(hours / 24)}일 전`;
|
|
}
|
|
|
|
function formatChatTime(dateLike: string) {
|
|
return new Intl.DateTimeFormat('ko-KR', {
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
}).format(new Date(dateLike));
|
|
}
|
|
|
|
function resolveChatSenderLabel(
|
|
currentUser: ApiUser | null,
|
|
captainRole: CaptainRole | null,
|
|
) {
|
|
const primaryRiotAccount =
|
|
currentUser?.riotAccounts.find((entry) => entry.isPrimary) ??
|
|
currentUser?.riotAccounts[0];
|
|
if (primaryRiotAccount?.gameName) {
|
|
return primaryRiotAccount.tagLine
|
|
? `${primaryRiotAccount.gameName}#${primaryRiotAccount.tagLine}`
|
|
: primaryRiotAccount.gameName;
|
|
}
|
|
if (currentUser?.kakaoTalkNickname) return currentUser.kakaoTalkNickname;
|
|
if (currentUser?.discordNickname) return currentUser.discordNickname;
|
|
if (captainRole) return `${teamIndexLabel(captainRole.teamIndex)} 팀장`;
|
|
return '관전자';
|
|
}
|
|
|
|
function isCurrentBidder(
|
|
currentBidder: AuctionStateView['currentBidder'],
|
|
team: Pick<AuctionStateView['teams'][number], 'teamIndex'>,
|
|
) {
|
|
return currentBidder?.teamIndex === team.teamIndex;
|
|
}
|
|
|
|
function getAuctionUpdatedAt(auction: ApiAuction | null | undefined) {
|
|
if (!auction) return 0;
|
|
return Date.parse(auction.updatedAt ?? auction.createdAt ?? '') || 0;
|
|
}
|
|
|
|
function pickLatestAuction(
|
|
socketAuction: ApiAuction | null,
|
|
queryAuction: ApiAuction | undefined,
|
|
) {
|
|
if (!socketAuction) return queryAuction ?? null;
|
|
if (!queryAuction) return socketAuction;
|
|
return getAuctionUpdatedAt(queryAuction) > getAuctionUpdatedAt(socketAuction)
|
|
? queryAuction
|
|
: socketAuction;
|
|
}
|
|
|
|
const AUCTION_MAX_TEAM_SIZE = 5;
|
|
const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
|
const POSITION_TO_RIOT_LANE = {
|
|
TOP: 'TOP',
|
|
JGL: 'JUNGLE',
|
|
MID: 'MIDDLE',
|
|
ADC: 'BOTTOM',
|
|
SUP: 'UTILITY',
|
|
} as const;
|
|
|
|
function PosBadge({ pos }: { pos: Position }) {
|
|
return (
|
|
<span className="inline-flex items-center gap-1.5 text-xs font-medium px-1.5 py-0.5 border border-primary/20 text-primary bg-primary/5">
|
|
<img src={positionIcon[pos]} alt="" className="w-3.5 h-3.5 object-contain" />
|
|
<span>{positionLabel[pos]}</span>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
|
|
const pct = 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'}`}
|
|
style={{ width: `${pct}%` }}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function getWinRate(stats: ApiRiotLaneStats) {
|
|
return stats.games > 0 ? Math.round((stats.wins / stats.games) * 100) : 0;
|
|
}
|
|
|
|
function getWinRateClass(winRate: number) {
|
|
if (winRate >= 55) return 'text-blue-400';
|
|
if (winRate >= 50) return 'text-base-content';
|
|
return 'text-red-400';
|
|
}
|
|
|
|
function formatKdaRatio(stats: ApiRiotLaneStats) {
|
|
if (stats.avgDeaths === 0) return 'Perfect';
|
|
return ((stats.avgKills + stats.avgAssists) / stats.avgDeaths).toFixed(2);
|
|
}
|
|
|
|
function RecentSoloStats({
|
|
player,
|
|
}: {
|
|
player: NonNullable<AuctionStateView['currentPlayer']>;
|
|
}) {
|
|
const primaryStats = player.recentStats.primary;
|
|
|
|
if (!primaryStats) {
|
|
return (
|
|
<div className="p-4">
|
|
<h4 className="text-xs font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
|
최근 솔로랭크
|
|
</h4>
|
|
<div className="rounded border border-dashed border-base-content/10 px-3 py-6 text-center text-xs text-base-content/25">
|
|
최근 솔로랭크 기록이 없습니다
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const primaryWinRate = getWinRate(primaryStats);
|
|
const primaryKdaRatio = formatKdaRatio(primaryStats);
|
|
|
|
return (
|
|
<div className="p-4">
|
|
<div className="flex items-start justify-between gap-3 mb-3">
|
|
<div>
|
|
<h4 className="text-xs font-bold uppercase tracking-wider text-base-content/30">
|
|
최근 솔로랭크
|
|
</h4>
|
|
<div className="mt-1 flex items-center gap-2">
|
|
<span className="text-xs font-semibold text-base-content">
|
|
{positionLabel[player.mainPosition]}
|
|
</span>
|
|
{player.recentStats.primarySource === 'overall' ? (
|
|
<span className="text-xs text-base-content/35">
|
|
전체 기준
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
<div
|
|
className={`text-sm font-bold tabular-nums ${getWinRateClass(primaryWinRate)}`}
|
|
>
|
|
{primaryWinRate}%
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<div className="flex items-baseline justify-between">
|
|
<span className="text-xs text-base-content/40">전적</span>
|
|
<span className="text-xs text-base-content/60 tabular-nums">
|
|
<span className="text-blue-400">{primaryStats.wins}W</span>{' '}
|
|
<span className="text-red-400">{primaryStats.losses}L</span>
|
|
</span>
|
|
</div>
|
|
<div className="flex items-baseline justify-between">
|
|
<span className="text-xs text-base-content/40">KDA</span>
|
|
<span className="text-xs text-base-content/60 tabular-nums">
|
|
{primaryStats.avgKills}/{primaryStats.avgDeaths}/{primaryStats.avgAssists}
|
|
<span
|
|
className={`ml-1 font-bold ${Number(primaryKdaRatio) >= 3 ? 'text-emerald-400' : 'text-base-content/50'}`}
|
|
>
|
|
({primaryKdaRatio})
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div className="flex items-baseline justify-between">
|
|
<span className="text-xs text-base-content/40">분당 CS</span>
|
|
<span className="text-xs text-base-content/60 tabular-nums">
|
|
{primaryStats.avgCsPerMin}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-4 border-t border-base-content/8 pt-3 space-y-1.5">
|
|
{LANE_ROWS.map((position) => {
|
|
const laneStats =
|
|
player.recentStats.byLane[POSITION_TO_RIOT_LANE[position]];
|
|
const isMainLane = position === player.mainPosition;
|
|
|
|
return (
|
|
<div
|
|
key={position}
|
|
className={`flex items-center justify-between gap-3 text-xs ${isMainLane ? 'font-semibold text-base-content' : 'text-base-content/65'}`}
|
|
>
|
|
<span className={isMainLane ? 'text-base-content' : 'text-base-content/35'}>
|
|
{positionLabel[position]}
|
|
</span>
|
|
{laneStats && laneStats.games > 0 ? (
|
|
<span className="tabular-nums text-right">
|
|
{laneStats.wins}W {laneStats.losses}L · {laneStats.avgKills}/
|
|
{laneStats.avgDeaths}/{laneStats.avgAssists} ·{' '}
|
|
{laneStats.avgCsPerMin} CS/min
|
|
</span>
|
|
) : (
|
|
<span className="text-base-content/20">—</span>
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function TeamPanel({
|
|
team,
|
|
isActive,
|
|
isLeft,
|
|
historyBackTo,
|
|
}: {
|
|
team: AuctionStateView['teams'][number];
|
|
isActive: boolean;
|
|
isLeft: boolean;
|
|
historyBackTo: string;
|
|
}) {
|
|
const { data: ddragon } = useDdragonManifest();
|
|
const tone = teamIndexColorClasses(team.teamIndex);
|
|
const teamSize = team.members.length + 1;
|
|
const isFull = teamSize >= AUCTION_MAX_TEAM_SIZE;
|
|
|
|
return (
|
|
<div
|
|
className={`border ${tone.border} 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 ${tone.bar}`}
|
|
/>
|
|
<div className={`${tone.bg} px-3 py-2 border-b ${tone.border}`}>
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-2">
|
|
<span className={`text-xs font-bold uppercase tracking-wide ${tone.text}`}>
|
|
{teamIndexLabel(team.teamIndex, team.name)}
|
|
</span>
|
|
<span className="text-xs text-base-content/30">
|
|
팀장: {team.captainName}
|
|
</span>
|
|
</div>
|
|
<span className="text-xs font-bold text-amber-400 tabular-nums">
|
|
{formatPoints(team.points)}P
|
|
</span>
|
|
</div>
|
|
<div className="mt-1 flex items-center justify-between text-xs">
|
|
<span className="text-base-content/25">
|
|
팀장 포함 {teamSize}/{AUCTION_MAX_TEAM_SIZE}
|
|
</span>
|
|
{isFull && <span className="font-bold text-amber-400">정원 완료</span>}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="divide-y divide-base-content/5">
|
|
{team.members.length === 0 ? (
|
|
<div className="px-3 py-6 text-center text-xs text-base-content/20">
|
|
아직 멤버가 없습니다
|
|
</div>
|
|
) : (
|
|
team.members.map((member) => (
|
|
<div
|
|
key={`${member.userId}-${member.assignedPosition}`}
|
|
className="px-3 py-1.5 flex items-center gap-2"
|
|
>
|
|
<Link
|
|
to={`/users/${member.userId}/history`}
|
|
state={{ backTo: historyBackTo }}
|
|
className="flex flex-1 min-w-0 items-center gap-1.5 group"
|
|
>
|
|
<div className="w-6 h-6 bg-base-content/10 overflow-hidden shrink-0">
|
|
<img
|
|
src={profileIconUrl(ddragon, member.profileIconId)}
|
|
alt=""
|
|
className="w-full h-full object-cover"
|
|
loading="lazy"
|
|
/>
|
|
</div>
|
|
<RankBadge tier={member.tier} />
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-xs font-medium text-base-content truncate block leading-tight group-hover:text-primary transition-colors">
|
|
{member.summonerName}
|
|
</span>
|
|
</div>
|
|
</Link>
|
|
<span className="shrink-0 text-xs font-semibold text-base-content/45">
|
|
{positionLabel[member.assignedPosition]}
|
|
</span>
|
|
<span className="text-xs text-amber-400/60 tabular-nums w-8 text-right">
|
|
{member.cost}
|
|
</span>
|
|
</div>
|
|
))
|
|
)}
|
|
|
|
{Array.from({
|
|
length: Math.max(0, AUCTION_MAX_TEAM_SIZE - 1 - team.members.length),
|
|
}).map((_, index) => (
|
|
<div
|
|
key={`empty-${team.teamIndex}-${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" />
|
|
<span className="ml-2 text-xs text-base-content/10">—</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PlayerSpotlight({
|
|
state,
|
|
historyBackTo,
|
|
}: {
|
|
state: AuctionStateView;
|
|
historyBackTo: string;
|
|
}) {
|
|
const { data: ddragon } = useDdragonManifest();
|
|
const player = state.currentPlayer;
|
|
const historyProfileQuery = useUserHistoryProfile(
|
|
player?.userId,
|
|
DEFAULT_COMMUNITY_ID,
|
|
Boolean(player && player.tierHistory.length === 0),
|
|
);
|
|
if (!player) return null;
|
|
const tierHistory =
|
|
player.tierHistory.length > 0
|
|
? player.tierHistory
|
|
: (historyProfileQuery.data?.tierHistory ?? []);
|
|
|
|
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">
|
|
<Link
|
|
to={`/users/${player.userId}/history`}
|
|
state={{ backTo: historyBackTo }}
|
|
className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0"
|
|
>
|
|
<img
|
|
src={profileIconUrl(ddragon, player.profileIconId)}
|
|
alt=""
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
</Link>
|
|
<div className="flex-1">
|
|
<div className="flex items-center gap-2 mb-1">
|
|
<Link
|
|
to={`/users/${player.userId}/history`}
|
|
state={{ backTo: historyBackTo }}
|
|
className="text-lg font-bold text-base-content leading-tight hover:text-primary transition-colors"
|
|
>
|
|
{player.summonerName}
|
|
</Link>
|
|
<span className="text-xs text-base-content/25">
|
|
#{player.tag}
|
|
</span>
|
|
</div>
|
|
<div className="mb-2 text-xs">
|
|
<ResponsiveTierLabel tier={player.tier} />
|
|
</div>
|
|
<div className="flex items-center gap-1.5">
|
|
<PosBadge pos={player.mainPosition} />
|
|
<span className="inline-flex items-center gap-0.5 text-xs px-1.5 py-0.5 border border-base-content/8 text-base-content/35">
|
|
<img
|
|
src={positionIcon[player.subPosition]}
|
|
alt=""
|
|
className="w-3.5 h-3.5 object-contain inline"
|
|
/>{' '}
|
|
{positionLabel[player.subPosition]}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{tierHistory.length > 0 && (
|
|
<Suspense
|
|
fallback={
|
|
<div className="h-[180px] border-b border-base-content/8 bg-base-100" />
|
|
}
|
|
>
|
|
<TierHistoryChart
|
|
entries={tierHistory}
|
|
className="border-b border-base-content/8 bg-base-100 overflow-hidden"
|
|
summaryVariant="inline"
|
|
height={180}
|
|
showHeader={false}
|
|
/>
|
|
</Suspense>
|
|
)}
|
|
|
|
<div className="grid grid-cols-2 divide-x divide-base-content/5">
|
|
<div className="p-4">
|
|
<h4 className="text-xs font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
|
숙련도 높은 챔피언
|
|
</h4>
|
|
<div className="space-y-2">
|
|
{player.masteries.length > 0 ? (
|
|
player.masteries.map((mastery) => {
|
|
const iconUrl = championIconUrl(ddragon, mastery.championId);
|
|
const displayName =
|
|
championDisplayName(ddragon, mastery.championId) ??
|
|
String(mastery.championId);
|
|
return (
|
|
<div key={mastery.championId} className="flex items-center gap-2">
|
|
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
|
{iconUrl ? (
|
|
<img
|
|
src={iconUrl}
|
|
alt={displayName}
|
|
className="w-full h-full object-cover"
|
|
loading="lazy"
|
|
/>
|
|
) : null}
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<div className="text-xs font-medium text-base-content truncate">
|
|
{displayName}
|
|
</div>
|
|
<div className="text-xs text-base-content/25">
|
|
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
})
|
|
) : (
|
|
<div className="text-xs text-base-content/25">
|
|
숙련도 데이터가 없습니다.
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<RecentSoloStats player={player} />
|
|
</div>
|
|
|
|
{(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-xs text-base-content/30 uppercase tracking-wider font-semibold">
|
|
{state.phase === 'sold' ? '낙찰가' : '현재 입찰가'}
|
|
</span>
|
|
<div className="flex items-center gap-2">
|
|
{state.currentBidder && (
|
|
<span
|
|
className={`text-xs font-bold uppercase ${teamIndexColorClasses(state.currentBidder.teamIndex).text}`}
|
|
>
|
|
{teamIndexLabel(state.currentBidder.teamIndex)}
|
|
</span>
|
|
)}
|
|
<span className="text-lg font-black text-amber-400 tabular-nums">
|
|
{state.currentBid > 0 ? formatPoints(state.currentBid) : '—'}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{state.phase === 'passed' && (
|
|
<div className="border-t border-base-content/8 bg-amber-500/[0.04] px-4 py-3 text-center">
|
|
<span className="text-sm font-bold text-amber-400">
|
|
유찰{' '}
|
|
{state.auctionRound === 1
|
|
? '— 마지막에 다시 등장합니다'
|
|
: '— 강제 배정 대상'}
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function BidControls({
|
|
state,
|
|
captainRole,
|
|
onBid,
|
|
}: {
|
|
state: AuctionStateView;
|
|
captainRole: CaptainRole | null;
|
|
onBid: (teamIndex: number, amount: number) => void;
|
|
}) {
|
|
const [bidAmount, setBidAmount] = useState(100);
|
|
const minBid = state.currentBid + 10;
|
|
const activeTeam = captainRole
|
|
? state.teams.find((team) => team.teamIndex === captainRole.teamIndex)
|
|
: null;
|
|
const activeTeamSize = activeTeam ? activeTeam.members.length + 1 : 0;
|
|
const isActiveTeamFull = activeTeamSize >= AUCTION_MAX_TEAM_SIZE;
|
|
|
|
useEffect(() => {
|
|
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
|
|
}, [state.currentBid, minBid]);
|
|
|
|
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((preset) => (
|
|
<button
|
|
key={preset}
|
|
onClick={() => setBidAmount(Math.max(minBid, preset))}
|
|
disabled={isActiveTeamFull}
|
|
className={`text-xs px-2.5 py-1 border transition-colors ${
|
|
bidAmount === preset
|
|
? 'border-primary/40 bg-primary/10 text-primary'
|
|
: 'border-base-content/10 text-base-content/40 hover:border-base-content/20'
|
|
}`}
|
|
>
|
|
{preset}P
|
|
</button>
|
|
))}
|
|
<input
|
|
type="number"
|
|
value={bidAmount}
|
|
onChange={(event) =>
|
|
setBidAmount(Math.max(minBid, Number(event.target.value)))
|
|
}
|
|
min={minBid}
|
|
disabled={isActiveTeamFull}
|
|
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>
|
|
<button
|
|
onClick={() => onBid(activeTeam.teamIndex, bidAmount)}
|
|
disabled={
|
|
isActiveTeamFull ||
|
|
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 ${
|
|
`${teamIndexColorClasses(activeTeam.teamIndex).border} ${teamIndexColorClasses(activeTeam.teamIndex).bg} ${teamIndexColorClasses(activeTeam.teamIndex).text} hover:bg-base-content/5`
|
|
}`}
|
|
>
|
|
{isActiveTeamFull
|
|
? `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
|
: `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 입찰 (${formatPoints(bidAmount)}P)`}
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
|
const endRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
}, [bids.length]);
|
|
|
|
if (bids.length === 0) return null;
|
|
|
|
return (
|
|
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
|
|
<div className="px-3 py-1.5 border-b border-base-content/8 bg-base-200/40">
|
|
<span className="text-xs font-bold uppercase tracking-wider text-base-content/30">
|
|
입찰 기록
|
|
</span>
|
|
</div>
|
|
<div className="max-h-28 overflow-y-auto p-2 space-y-0.5">
|
|
{bids.map((bid, index) => (
|
|
<div key={`${bid.teamIndex}-${bid.timestamp}-${index}`} className="flex items-center gap-2 text-xs">
|
|
<span
|
|
className={`font-bold uppercase ${teamIndexColorClasses(bid.teamIndex).text}`}
|
|
>
|
|
{teamIndexLabel(bid.teamIndex)}
|
|
</span>
|
|
<span className="text-base-content/30">→</span>
|
|
<span className="text-amber-400 tabular-nums font-semibold">
|
|
{formatPoints(bid.amount)}P
|
|
</span>
|
|
</div>
|
|
))}
|
|
<div ref={endRef} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function AuctionPage() {
|
|
const { id } = useParams();
|
|
const location = useLocation();
|
|
const navigate = useNavigate();
|
|
const queryClient = useQueryClient();
|
|
const meQuery = useMe();
|
|
const currentUser =
|
|
meQuery.data?.memberships.find(
|
|
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
|
)?.user ?? null;
|
|
const canManageAuction =
|
|
import.meta.env.DEV ||
|
|
currentUser?.role === 'owner' ||
|
|
currentUser?.role === 'admin';
|
|
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
|
|
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID, {
|
|
refetchInterval: 5000,
|
|
});
|
|
const historyQuery = useAuctionHistory(id, DEFAULT_COMMUNITY_ID, {
|
|
enabled: canManageAuction,
|
|
refetchInterval: 3000,
|
|
});
|
|
const undoMutation = useUndoAuction(DEFAULT_COMMUNITY_ID);
|
|
const resetAuctionMutation = useResetAuction(DEFAULT_COMMUNITY_ID);
|
|
const socket = useAuctionSocket(id);
|
|
const captainTeamIndex = useDevCaptainTeamIndex();
|
|
const [now, setNow] = useState(() => Date.now());
|
|
const [assignedPosition, setAssignedPosition] = useState<Position>('MID');
|
|
const [showCancelModal, setShowCancelModal] = useState(false);
|
|
const [cancelConfirmText, setCancelConfirmText] = useState('');
|
|
const cancelConfirmInputRef = useRef<HTMLInputElement>(null);
|
|
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
|
const canConfirmAuctionCancel = cancelConfirmText.trim() === '예';
|
|
|
|
async function invalidateAuctionData() {
|
|
if (!id) return;
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['auction', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['auction-history', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['match', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
]);
|
|
}
|
|
|
|
useEffect(() => {
|
|
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
|
return () => window.clearInterval(timer);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!showCancelModal) return;
|
|
cancelConfirmInputRef.current?.focus();
|
|
}, [showCancelModal]);
|
|
|
|
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
|
const auctionState =
|
|
liveAuction && matchQuery.data
|
|
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data, new Date(now))
|
|
: null;
|
|
const availableTeamIndexes = useMemo(() => {
|
|
const indexes = new Set((auctionState?.teams ?? []).map((team) => team.teamIndex));
|
|
return [...indexes].sort((left, right) => left - right);
|
|
}, [auctionState?.teams]);
|
|
const captainRole: CaptainRole | null =
|
|
captainTeamIndex === null
|
|
? null
|
|
: {
|
|
teamIndex: captainTeamIndex,
|
|
};
|
|
const chatSenderLabel = resolveChatSenderLabel(currentUser, captainRole);
|
|
|
|
useEffect(() => {
|
|
if (auctionState?.currentPlayer) {
|
|
setAssignedPosition(auctionState.currentPlayer.mainPosition);
|
|
}
|
|
}, [auctionState?.currentPlayer?.id]);
|
|
|
|
useEffect(() => {
|
|
if (availableTeamIndexes.length === 0) return;
|
|
if (captainTeamIndex !== null && !availableTeamIndexes.includes(captainTeamIndex)) {
|
|
setDevCaptainTeamIndex(availableTeamIndexes[0]);
|
|
}
|
|
}, [availableTeamIndexes, captainTeamIndex]);
|
|
|
|
useEffect(() => {
|
|
if (!socket.resetAt || !id) return;
|
|
void invalidateAuctionData().finally(() => {
|
|
navigate(`/match/${id}`, { replace: true });
|
|
});
|
|
}, [id, navigate, socket.resetAt]);
|
|
|
|
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 || (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>
|
|
);
|
|
}
|
|
|
|
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 phaseLabel: Record<AuctionStateView['phase'], string> = {
|
|
waiting: '경매 준비 중...',
|
|
presenting: '다음 선수 등장',
|
|
bidding: '입찰 진행 중',
|
|
sold: '낙찰!',
|
|
passed: '유찰 — 다음 선수로',
|
|
complete: '경매 완료',
|
|
};
|
|
const errorMessage =
|
|
socket.error ??
|
|
(auctionQuery.error instanceof Error ? auctionQuery.error.message : null);
|
|
|
|
function handleUndo(sequence: number) {
|
|
if (!id) return;
|
|
if (!window.confirm(`${sequence}번 액션 직전으로 되돌릴까요?`)) return;
|
|
undoMutation.mutate(
|
|
{ matchId: id, sequence },
|
|
{
|
|
onSuccess: async () => {
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['auction', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['auction-history', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['match', DEFAULT_COMMUNITY_ID, id],
|
|
}),
|
|
]);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
function handleResetAuction() {
|
|
if (!id || !canConfirmAuctionCancel) return;
|
|
resetAuctionMutation.mutate(
|
|
{ matchId: id },
|
|
{
|
|
onSuccess: async () => {
|
|
setShowCancelModal(false);
|
|
setCancelConfirmText('');
|
|
await invalidateAuctionData();
|
|
navigate(`/match/${id}`, { replace: true });
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
const undoPanel = canManageAuction ? (
|
|
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
|
<div className="text-xs font-bold uppercase tracking-wider text-base-content/35">
|
|
되돌리기 (Undo)
|
|
</div>
|
|
<div className="max-h-48 overflow-y-auto space-y-1 text-xs">
|
|
{historyQuery.data?.length ? (
|
|
historyQuery.data.map((entry) => (
|
|
<button
|
|
key={entry.sequence}
|
|
type="button"
|
|
onClick={() => handleUndo(entry.sequence)}
|
|
disabled={undoMutation.isPending}
|
|
className="flex w-full items-center justify-between gap-2 border border-base-content/8 px-2 py-1.5 text-left transition-colors hover:border-primary/30 hover:bg-primary/5 disabled:cursor-not-allowed disabled:opacity-40"
|
|
>
|
|
<span className="text-base-content/65 tabular-nums">
|
|
#{entry.sequence}
|
|
</span>
|
|
<span className="text-base-content/45">{entry.actionLabel}</span>
|
|
<span className="text-xs text-base-content/25">
|
|
{relativeTime(entry.takenAt)}
|
|
</span>
|
|
</button>
|
|
))
|
|
) : (
|
|
<div className="border border-dashed border-base-content/10 px-2 py-4 text-center text-base-content/25">
|
|
기록이 없습니다
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
) : null;
|
|
|
|
return (
|
|
<main className="max-w-[1600px] mx-auto px-4 sm:px-6 py-6">
|
|
<Link
|
|
to={`/match/${id}`}
|
|
className="inline-flex items-center gap-1 text-xs text-base-content/40 hover:text-base-content transition-colors mb-4"
|
|
>
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
className="h-3.5 w-3.5"
|
|
fill="none"
|
|
viewBox="0 0 24 24"
|
|
stroke="currentColor"
|
|
>
|
|
<path
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
strokeWidth={2}
|
|
d="M15 19l-7-7 7-7"
|
|
/>
|
|
</svg>
|
|
내전 상세로
|
|
</Link>
|
|
|
|
{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>
|
|
)}
|
|
|
|
{undoMutation.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">
|
|
{undoMutation.error.message}
|
|
</div>
|
|
)}
|
|
|
|
{resetAuctionMutation.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">
|
|
{resetAuctionMutation.error.message}
|
|
</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-xs text-base-content/30 mt-0.5">
|
|
{Math.min(auctionState.currentPlayerIndex + 1, Math.max(auctionState.totalPlayers, 1))} /{' '}
|
|
{auctionState.totalPlayers} 선수
|
|
</p>
|
|
</div>
|
|
<div className="flex flex-col items-end gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<span
|
|
className={`inline-flex items-center text-xs 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'
|
|
: auctionState.phase === 'passed'
|
|
? 'border-amber-500/20 bg-amber-500/10 text-amber-400/70'
|
|
: 'border-base-content/10 bg-base-content/5 text-base-content/40'
|
|
}`}
|
|
>
|
|
{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>
|
|
{/* 임시 운영용: 로그인/권한 확인 없이 조작자 역할을 선택할 수 있게 열어둔다. */}
|
|
<select
|
|
value={captainTeamIndex ?? 'spectator'}
|
|
onChange={(event) =>
|
|
setDevCaptainTeamIndex(
|
|
event.target.value === 'spectator'
|
|
? null
|
|
: Number(event.target.value),
|
|
)
|
|
}
|
|
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
|
|
>
|
|
<option value="spectator">관전자</option>
|
|
{availableTeamIndexes.map((teamIndex) => (
|
|
<option key={teamIndex} value={teamIndex}>
|
|
{teamIndexLabel(teamIndex)} 팀장
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{auctionState.phase === 'bidding' && (
|
|
<TimerBar timer={auctionState.timer} maxTimer={auctionState.maxTimer} />
|
|
)}
|
|
|
|
<div className="grid grid-cols-1 xl:grid-cols-[260px_minmax(0,1fr)_minmax(340px,440px)_320px] gap-4 mt-4">
|
|
<aside className="hidden xl:block">
|
|
<PoolPanel state={auctionState} />
|
|
</aside>
|
|
|
|
<div className="grid sm:grid-cols-2 gap-4 content-start">
|
|
{auctionState.teams.map((team) => (
|
|
<TeamPanel
|
|
key={team.teamIndex}
|
|
team={team}
|
|
isActive={isCurrentBidder(auctionState.currentBidder, team)}
|
|
isLeft={team.teamIndex % 2 === 1}
|
|
historyBackTo={historyBackTo}
|
|
/>
|
|
))}
|
|
</div>
|
|
|
|
<div className="flex-1 min-w-0 space-y-4">
|
|
{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">
|
|
경매 완료
|
|
</div>
|
|
<div className="text-xs text-base-content/40">
|
|
모든 선수가 팀에 배정되었습니다.
|
|
</div>
|
|
<Link
|
|
to={`/match/${id}`}
|
|
className="btn btn-primary btn-sm mt-4 px-6 text-xs"
|
|
>
|
|
결과 확인
|
|
</Link>
|
|
</div>
|
|
{undoPanel}
|
|
</>
|
|
) : (
|
|
<>
|
|
<PlayerSpotlight
|
|
state={auctionState}
|
|
historyBackTo={historyBackTo}
|
|
/>
|
|
|
|
{auctionState.phase === 'sold' && auctionState.currentBidder && (
|
|
<div
|
|
className={`text-center py-3 border text-sm font-bold ${
|
|
`${teamIndexColorClasses(auctionState.currentBidder.teamIndex).border} ${teamIndexColorClasses(auctionState.currentBidder.teamIndex).bg} ${teamIndexColorClasses(auctionState.currentBidder.teamIndex).text}`
|
|
}`}
|
|
>
|
|
{teamIndexLabel(auctionState.currentBidder.teamIndex)} 낙찰
|
|
{' '}— {formatPoints(auctionState.currentBid)}P
|
|
</div>
|
|
)}
|
|
|
|
<BidControls
|
|
state={auctionState}
|
|
captainRole={captainRole}
|
|
onBid={(teamIndex, amount) =>
|
|
socket.placeBid({ teamIndex, amount })
|
|
}
|
|
/>
|
|
<BidLog bids={auctionState.bids} />
|
|
|
|
{canManageAuction && (
|
|
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
|
<div className="text-xs font-bold uppercase tracking-wider text-base-content/35">
|
|
Auction Controls
|
|
</div>
|
|
{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' ||
|
|
auctionState.phase === 'passed') && (
|
|
<button
|
|
type="button"
|
|
className="btn btn-primary btn-sm px-5 text-xs"
|
|
onClick={() => socket.next()}
|
|
>
|
|
다음 선수
|
|
</button>
|
|
)}
|
|
<div className="border-t border-base-content/10 pt-3">
|
|
<button
|
|
type="button"
|
|
className="btn btn-outline btn-error btn-sm inline-flex items-center gap-1.5 px-4 text-xs"
|
|
onClick={() => {
|
|
setCancelConfirmText('');
|
|
setShowCancelModal(true);
|
|
}}
|
|
disabled={resetAuctionMutation.isPending}
|
|
>
|
|
<AlertTriangle className="h-3.5 w-3.5" />
|
|
경매 진행 취소
|
|
</button>
|
|
<p className="mt-2 text-xs leading-relaxed text-base-content/35">
|
|
경매 데이터와 진행 기록을 삭제하고 내전을 모집 상태로 되돌립니다.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{undoPanel}
|
|
</>
|
|
)}
|
|
</div>
|
|
|
|
<aside className="hidden xl:block">
|
|
<ChatPanel
|
|
messages={socket.chatMessages}
|
|
connectionStatus={socket.connectionStatus}
|
|
senderLabel={chatSenderLabel}
|
|
onSend={(message) =>
|
|
socket.sendChatMessage({
|
|
displayName: chatSenderLabel,
|
|
message,
|
|
})
|
|
}
|
|
className="sticky top-4 h-[520px] max-h-[calc(100vh-2rem)]"
|
|
/>
|
|
</aside>
|
|
</div>
|
|
|
|
<div className="mt-4 xl:hidden">
|
|
<ChatPanel
|
|
messages={socket.chatMessages}
|
|
connectionStatus={socket.connectionStatus}
|
|
senderLabel={chatSenderLabel}
|
|
onSend={(message) =>
|
|
socket.sendChatMessage({
|
|
displayName: chatSenderLabel,
|
|
message,
|
|
})
|
|
}
|
|
className="h-[420px]"
|
|
/>
|
|
</div>
|
|
|
|
{showCancelModal && (
|
|
<div
|
|
className="fixed inset-0 z-50 flex items-center justify-center bg-black/55 px-4"
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-labelledby="auction-cancel-title"
|
|
>
|
|
<div className="w-full max-w-md border border-red-500/25 bg-base-100 p-5 shadow-2xl">
|
|
<div className="flex items-start gap-3">
|
|
<span className="inline-flex h-9 w-9 shrink-0 items-center justify-center border border-red-500/25 bg-red-500/10 text-red-400">
|
|
<AlertTriangle className="h-4 w-4" />
|
|
</span>
|
|
<div className="min-w-0">
|
|
<h2
|
|
id="auction-cancel-title"
|
|
className="text-base font-bold text-base-content"
|
|
>
|
|
경매 진행 취소
|
|
</h2>
|
|
<p className="mt-2 text-sm leading-6 text-base-content/60">
|
|
정말 경매를 취소하고 모집 상태로 되돌리시겠습니까?
|
|
경매 데이터, 입찰 기록, 팀 배정 정보가 삭제됩니다.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<label
|
|
htmlFor="auction-cancel-confirm"
|
|
className="mt-5 block text-xs font-bold uppercase tracking-wider text-base-content/40"
|
|
>
|
|
계속하려면 예 입력
|
|
</label>
|
|
<input
|
|
id="auction-cancel-confirm"
|
|
ref={cancelConfirmInputRef}
|
|
value={cancelConfirmText}
|
|
onChange={(event) => setCancelConfirmText(event.target.value)}
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Escape') {
|
|
setShowCancelModal(false);
|
|
setCancelConfirmText('');
|
|
}
|
|
if (event.key === 'Enter' && canConfirmAuctionCancel) {
|
|
handleResetAuction();
|
|
}
|
|
}}
|
|
className="mt-2 h-10 w-full border border-base-content/15 bg-base-100 px-3 text-sm text-base-content outline-none transition-colors focus:border-red-400/60"
|
|
placeholder="예"
|
|
/>
|
|
|
|
<div className="mt-5 flex flex-wrap justify-end gap-2">
|
|
<button
|
|
type="button"
|
|
className="btn btn-ghost btn-sm px-4 text-xs"
|
|
onClick={() => {
|
|
setShowCancelModal(false);
|
|
setCancelConfirmText('');
|
|
}}
|
|
disabled={resetAuctionMutation.isPending}
|
|
>
|
|
닫기
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className="btn btn-error btn-sm px-4 text-xs"
|
|
onClick={handleResetAuction}
|
|
disabled={
|
|
!canConfirmAuctionCancel || resetAuctionMutation.isPending
|
|
}
|
|
>
|
|
{resetAuctionMutation.isPending
|
|
? '취소 처리 중...'
|
|
: '경매 취소 진행'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|
|
|
|
type PoolTab = 'waiting' | 'passed';
|
|
|
|
// 풀 리스트는 경매 등장 순서를 노출하면 안 되므로 게임명 알파벳 순으로 독립 정렬한다.
|
|
const POOL_COLLATOR = new Intl.Collator(['ko', 'en'], { sensitivity: 'base' });
|
|
|
|
function comparePoolPlayers(a: AuctionPlayerView, b: AuctionPlayerView) {
|
|
return POOL_COLLATOR.compare(a.summonerName, b.summonerName);
|
|
}
|
|
|
|
function PoolPanel({ state }: { state: AuctionStateView }) {
|
|
const { data: ddragon } = useDdragonManifest();
|
|
const [tab, setTab] = useState<PoolTab>('waiting');
|
|
|
|
const { waitingPool, passedPool } = useMemo(() => {
|
|
const captainIds = new Set(state.teams.map((team) => team.captainUserId));
|
|
const memberIds = new Set(
|
|
state.teams.flatMap((team) =>
|
|
team.members.map((member) => member.userId),
|
|
),
|
|
);
|
|
const passedIds = new Set(
|
|
state.passedQueue.map((player) => player.userId),
|
|
);
|
|
const currentId = state.currentPlayer?.userId;
|
|
|
|
const startIndex =
|
|
state.phase === 'complete' ? state.totalPlayers : state.currentPlayerIndex + 1;
|
|
|
|
const waiting = state.auctionOrder
|
|
.slice(startIndex)
|
|
.filter(
|
|
(player) =>
|
|
!captainIds.has(player.userId) &&
|
|
!memberIds.has(player.userId) &&
|
|
!passedIds.has(player.userId) &&
|
|
player.userId !== currentId,
|
|
)
|
|
.sort(comparePoolPlayers);
|
|
|
|
const passed = [...state.passedQueue].sort(comparePoolPlayers);
|
|
|
|
return { waitingPool: waiting, passedPool: passed };
|
|
}, [state]);
|
|
|
|
const activePool = tab === 'waiting' ? waitingPool : passedPool;
|
|
|
|
return (
|
|
<div className="border border-base-content/10 bg-base-100 sticky top-4 max-h-[calc(100vh-2rem)] flex flex-col">
|
|
<div role="tablist" className="flex border-b border-base-content/10 px-3">
|
|
<PoolTabButton
|
|
label="대기"
|
|
count={waitingPool.length}
|
|
active={tab === 'waiting'}
|
|
onClick={() => setTab('waiting')}
|
|
/>
|
|
<PoolTabButton
|
|
label="유찰"
|
|
count={passedPool.length}
|
|
active={tab === 'passed'}
|
|
onClick={() => setTab('passed')}
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex-1 overflow-y-auto">
|
|
{activePool.length === 0 ? (
|
|
<div className="px-3 py-8 text-center text-xs text-base-content/30">
|
|
{tab === 'waiting'
|
|
? '대기 중인 유저가 없습니다'
|
|
: '유찰된 유저가 없습니다'}
|
|
</div>
|
|
) : (
|
|
<ul className="divide-y divide-base-content/5">
|
|
{activePool.map((player) => (
|
|
<PoolListItem
|
|
key={player.userId}
|
|
player={player}
|
|
ddragon={ddragon}
|
|
showPassCount={tab === 'passed'}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PoolTabButton({
|
|
label,
|
|
count,
|
|
active,
|
|
onClick,
|
|
}: {
|
|
label: string;
|
|
count: number;
|
|
active: boolean;
|
|
onClick: () => void;
|
|
}) {
|
|
return (
|
|
<button
|
|
role="tab"
|
|
type="button"
|
|
onClick={onClick}
|
|
className={`relative px-1 pt-3 pb-2.5 mr-5 text-xs font-semibold transition-colors ${
|
|
active
|
|
? 'text-base-content'
|
|
: 'text-base-content/40 hover:text-base-content/70'
|
|
}`}
|
|
>
|
|
{label}
|
|
<span className="ml-1 text-xs tabular-nums text-base-content/30">
|
|
{count}
|
|
</span>
|
|
{active ? (
|
|
<span className="absolute -bottom-px left-0 right-0 h-px bg-primary" />
|
|
) : null}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
function PoolListItem({
|
|
player,
|
|
ddragon,
|
|
showPassCount,
|
|
}: {
|
|
player: AuctionPlayerView;
|
|
ddragon: ReturnType<typeof useDdragonManifest>['data'];
|
|
showPassCount: boolean;
|
|
}) {
|
|
return (
|
|
<li className="flex items-center gap-2 px-3 py-2">
|
|
<img
|
|
src={profileIconUrl(ddragon, player.profileIconId)}
|
|
alt=""
|
|
className="w-7 h-7 shrink-0 rounded-sm border border-base-content/10 object-cover"
|
|
/>
|
|
<div className="min-w-0 flex-1 flex items-center gap-1.5">
|
|
<span className="truncate text-xs font-semibold text-base-content">
|
|
{player.summonerName}
|
|
</span>
|
|
<RankBadge tier={player.tier} />
|
|
{showPassCount && player.passCount > 0 ? (
|
|
<span className="inline-flex items-center text-xs font-medium px-1.5 py-0.5 border border-amber-500/30 text-amber-500 bg-amber-500/5">
|
|
{player.passCount}회 유찰
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
function ChatPanel({
|
|
messages,
|
|
connectionStatus,
|
|
senderLabel,
|
|
onSend,
|
|
className = '',
|
|
}: {
|
|
messages: ApiAuctionChatMessage[];
|
|
connectionStatus: ReturnType<typeof useAuctionSocket>['connectionStatus'];
|
|
senderLabel: string;
|
|
onSend: (message: string) => void;
|
|
className?: string;
|
|
}) {
|
|
const [draft, setDraft] = useState('');
|
|
const messagesEndRef = useRef<HTMLDivElement | null>(null);
|
|
const trimmedDraft = draft.trim();
|
|
const isConnected = connectionStatus === 'connected';
|
|
const canSend = isConnected && trimmedDraft.length > 0;
|
|
|
|
useEffect(() => {
|
|
messagesEndRef.current?.scrollIntoView({ block: 'end' });
|
|
}, [messages.length]);
|
|
|
|
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
if (!canSend) return;
|
|
onSend(trimmedDraft);
|
|
setDraft('');
|
|
}
|
|
|
|
function handleKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
if (event.key !== 'Enter' || event.shiftKey) return;
|
|
event.preventDefault();
|
|
if (!canSend) return;
|
|
onSend(trimmedDraft);
|
|
setDraft('');
|
|
}
|
|
|
|
const statusLabel =
|
|
connectionStatus === 'connected'
|
|
? '실시간'
|
|
: connectionStatus === 'connecting'
|
|
? '연결 중'
|
|
: '오프라인';
|
|
|
|
return (
|
|
<div
|
|
className={`border border-base-content/10 bg-base-100 flex min-h-0 flex-col ${className}`}
|
|
>
|
|
<div className="border-b border-base-content/10 px-3 py-2.5 flex items-center justify-between">
|
|
<div className="text-xs font-bold uppercase tracking-wider text-base-content/35">
|
|
채팅
|
|
</div>
|
|
<span
|
|
className={`text-xs ${
|
|
isConnected ? 'text-green-500' : 'text-base-content/30'
|
|
}`}
|
|
>
|
|
{statusLabel}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="flex-1 min-h-0 overflow-y-auto px-3 py-3">
|
|
{messages.length === 0 ? (
|
|
<div className="flex h-full items-center justify-center text-center text-xs text-base-content/25">
|
|
아직 메시지가 없습니다
|
|
</div>
|
|
) : (
|
|
<ol className="space-y-3">
|
|
{messages.map((message) => (
|
|
<li key={message.id} className="space-y-1">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="min-w-0 truncate text-xs font-bold text-base-content/70">
|
|
{message.displayName}
|
|
</span>
|
|
<time className="shrink-0 text-xs tabular-nums text-base-content/25">
|
|
{formatChatTime(message.sentAt)}
|
|
</time>
|
|
</div>
|
|
<p className="whitespace-pre-wrap break-words border border-base-content/8 bg-base-content/[0.03] px-2.5 py-2 text-xs leading-relaxed text-base-content/75">
|
|
{message.message}
|
|
</p>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
)}
|
|
<div ref={messagesEndRef} />
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit} className="border-t border-base-content/10 p-2 space-y-2">
|
|
<div className="flex items-center justify-between gap-2 px-0.5 text-xs text-base-content/30">
|
|
<span className="truncate">{senderLabel}</span>
|
|
<span className="tabular-nums">{draft.length}/300</span>
|
|
</div>
|
|
<textarea
|
|
value={draft}
|
|
onChange={(event) => setDraft(event.target.value)}
|
|
onKeyDown={handleKeyDown}
|
|
disabled={!isConnected}
|
|
maxLength={300}
|
|
placeholder="메시지를 입력하세요"
|
|
className="w-full resize-none border border-base-content/10 bg-base-content/5 px-2 py-1.5 text-xs text-base-content/80 placeholder:text-base-content/25 focus:border-primary/40 focus:outline-none disabled:cursor-not-allowed disabled:text-base-content/30"
|
|
rows={2}
|
|
aria-label="경매 채팅 메시지"
|
|
/>
|
|
<button
|
|
type="submit"
|
|
disabled={!canSend}
|
|
className="btn btn-primary btn-sm w-full text-xs"
|
|
>
|
|
<SendHorizontal className="h-3.5 w-3.5" aria-hidden="true" />
|
|
전송
|
|
</button>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|