Compare commits
2
Commits
5ad0f8a1c2
...
ef693fcf4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef693fcf4a | ||
|
|
8a9dd37755 |
No files matched your search
+1
-1
@@ -1 +1 @@
|
||||
66
|
||||
68
|
||||
@@ -164,6 +164,7 @@ export class AuctionController {
|
||||
) {
|
||||
this.assertSameCommunity(currentUser, communityId);
|
||||
await this.auctionService.reset({ matchId, communityId });
|
||||
this.auctionGateway.broadcastReset(matchId.toString());
|
||||
}
|
||||
|
||||
private resolveBidder(
|
||||
|
||||
@@ -364,6 +364,11 @@ export class AuctionGateway
|
||||
this.syncRoomTimer(matchId, auction);
|
||||
}
|
||||
|
||||
public broadcastReset(matchId: string) {
|
||||
this.clearRoomTimer(matchId);
|
||||
this.server.to(matchId).emit('reset', { matchId });
|
||||
}
|
||||
|
||||
private emitChatHistory(socket: Socket, auction: AuctionDocument) {
|
||||
socket.emit('chat-history', {
|
||||
messages: (auction.chatMessages ?? []).map((message) =>
|
||||
|
||||
@@ -171,6 +171,15 @@ export function useUndoAuction(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useResetAuction(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: ({ matchId }: { matchId: string }) =>
|
||||
apiFetch<void>(`/communities/${communityId}/matches/${matchId}/auction`, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (body: MatchMutationRequest) =>
|
||||
|
||||
@@ -26,6 +26,10 @@ interface ChatHistoryPayload {
|
||||
messages?: ApiAuctionChatMessage[];
|
||||
}
|
||||
|
||||
interface ResetPayload {
|
||||
matchId?: string;
|
||||
}
|
||||
|
||||
const MAX_CHAT_MESSAGES = 200;
|
||||
|
||||
function mergeChatMessages(
|
||||
@@ -47,6 +51,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
const socketRef = useRef<Socket | null>(null);
|
||||
const [auction, setAuction] = useState<ApiAuction | null>(null);
|
||||
const [chatMessages, setChatMessages] = useState<ApiAuctionChatMessage[]>([]);
|
||||
const [resetAt, setResetAt] = useState<number | null>(null);
|
||||
const [connectionStatus, setConnectionStatus] =
|
||||
useState<ConnectionStatus>('idle');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -103,6 +108,14 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
setChatMessages((current) => mergeChatMessages(current, [message]));
|
||||
});
|
||||
|
||||
socket.on('reset', (payload: ResetPayload) => {
|
||||
if (payload.matchId && payload.matchId !== matchId) return;
|
||||
setAuction(null);
|
||||
setChatMessages([]);
|
||||
setResetAt(Date.now());
|
||||
setError('경매가 취소되었습니다.');
|
||||
});
|
||||
|
||||
socket.on('error', (payload: { message?: string }) => {
|
||||
setConnectionStatus('error');
|
||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||
@@ -144,6 +157,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
||||
return {
|
||||
auction: visibleAuction,
|
||||
chatMessages: visibleAuction ? chatMessages : [],
|
||||
resetAt,
|
||||
connectionStatus: visibleConnectionStatus,
|
||||
error,
|
||||
placeBid(payload: BidPayload) {
|
||||
|
||||
@@ -7,14 +7,15 @@ import {
|
||||
type KeyboardEvent,
|
||||
} from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { SendHorizontal } from 'lucide-react';
|
||||
import { Link, useLocation, useParams } from 'react-router';
|
||||
import { AlertTriangle, SendHorizontal } from 'lucide-react';
|
||||
import { Link, useLocation, useNavigate, useParams } from 'react-router';
|
||||
import {
|
||||
useAuction,
|
||||
useAuctionHistory,
|
||||
useDdragonManifest,
|
||||
useMatch,
|
||||
useMe,
|
||||
useResetAuction,
|
||||
useUndoAuction,
|
||||
} from '../api/hooks';
|
||||
import {
|
||||
@@ -728,6 +729,7 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
||||
export default function AuctionPage() {
|
||||
const { id } = useParams();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const currentUser =
|
||||
@@ -747,17 +749,42 @@ export default function AuctionPage() {
|
||||
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
|
||||
@@ -788,6 +815,13 @@ export default function AuctionPage() {
|
||||
}
|
||||
}, [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">
|
||||
@@ -862,6 +896,21 @@ export default function AuctionPage() {
|
||||
);
|
||||
}
|
||||
|
||||
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-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
@@ -930,6 +979,12 @@ export default function AuctionPage() {
|
||||
</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">
|
||||
@@ -1101,6 +1156,23 @@ export default function AuctionPage() {
|
||||
다음 선수
|
||||
</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-[11px] leading-relaxed text-base-content/35">
|
||||
경매 데이터와 진행 기록을 삭제하고 내전을 모집 상태로 되돌립니다.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{undoPanel}
|
||||
@@ -1138,6 +1210,85 @@ export default function AuctionPage() {
|
||||
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-[11px] 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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user