11'use client' ;
2- import { RefObject , useEffect } from 'react' ;
3- import { ChatRoomId } from '../../types' ;
2+ import { useEffect } from 'react' ;
43import useChatWebSocketStore , { useChatWebSocketActions } from '../../model/useChatWebSocketStore' ;
5- import { Client } from '@stomp/stompjs ' ;
4+ import { useConnectWebSocket } from '../.. ' ;
65
7- export default function useLeaveChatRoom (
8- chatStompRef : RefObject < Client | null > ,
9- chatroomId : ChatRoomId
10- ) {
11- const { isLeaveRoom } = useChatWebSocketStore ( ) ;
6+ export default function useLeaveChatRoom ( ) {
7+ // chatStompRef: RefObject<Client | null>,
8+ const { chatStompRef } = useConnectWebSocket ( ) ;
9+
10+ const { leavedRoom } = useChatWebSocketStore ( ) ;
1211 const { clearMessages } = useChatWebSocketActions ( ) ;
1312
1413 useEffect ( ( ) => {
15- if ( chatroomId === 0 || ! chatStompRef ?. current || ! isLeaveRoom ) return ;
16- console . log ( '퇴장 훅 실행' ) ;
14+ if ( leavedRoom === 0 || ! chatStompRef ?. current ) return ;
1715 if ( chatStompRef . current ?. connected ) {
1816 try {
1917 chatStompRef . current . publish ( {
20- destination : `/chat/rooms/${ chatroomId } /leave ` ,
21- body : String ( chatroomId ) ,
18+ destination : `/chat/rooms/${ leavedRoom } /left ` ,
19+ body : String ( leavedRoom ) ,
2220 } ) ;
2321 } catch ( err ) {
2422 console . error ( '퇴장 메시지 전송 오류' , err ) ;
@@ -28,5 +26,5 @@ export default function useLeaveChatRoom(
2826 }
2927
3028 // eslint-disable-next-line react-hooks/exhaustive-deps
31- } , [ chatStompRef , chatroomId , isLeaveRoom ] ) ;
29+ } , [ chatStompRef , leavedRoom ] ) ;
3230}
0 commit comments