feat(auction): cancel active auction

This commit is contained in:
dahyeon committed 2026-06-07 07:44:59 -07:00
1 parent 8a9dd37755
commit ef693fcf4a
5 files changed
+182 -2

No files matched your search

+14
View File
@@ -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) {