Skip to content

Commit

Permalink
Merge pull request #107 from MOVIEJOJO7/Feature/#105
Browse files Browse the repository at this point in the history
Fix: 채팅 들어가과 나가기 에러 해결
  • Loading branch information
JitHoon authored Nov 16, 2023
2 parents 796bc49 + fd28a7c commit 85d93b4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Components/Chat/ChatRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ChatHeader from '@/Components/Chat/ChatHeader';
import RenderChats from '@/Components/Chat/RenderChats';
import Image from 'next/image';
import Swal from 'sweetalert2';
import { getCookie } from '../Login/Cookie';

const ChatRoom = ({
socket,
Expand All @@ -24,6 +25,7 @@ const ChatRoom = ({
const [newMessage, setNewMessage] = useState('');
const [chatUsers, setChatUsers] = useState<User[]>([]);
const [chatName, setChatName] = useState('');
const userId = getCookie('userId');

// 채팅 참여 유저 블러오기
useEffect(() => {
Expand Down Expand Up @@ -85,7 +87,10 @@ const ChatRoom = ({
if (socket?.connected) {
socket.on('join', (responseData) => {
setChatUsers([...chatUsers, ...responseData.users]);
Swal.fire(`${responseData.users[0]} 님이 입장하셨습니다.`);

if (responseData.users[0] !== userId) {
Swal.fire(`${responseData.leaver} 님이 퇴장하셨습니다.`);
}
});
}

Expand All @@ -100,7 +105,10 @@ const ChatRoom = ({
if (socket?.connected) {
socket.on('leave', (responseData) => {
setChatUsers([...chatUsers, ...responseData.users]);
Swal.fire(`${responseData.leaver} 님이 퇴장하셨습니다.`);

if (responseData.leaver !== userId) {
Swal.fire(`${responseData.leaver} 님이 퇴장하셨습니다.`);
}
});
}

Expand Down

0 comments on commit 85d93b4

Please sign in to comment.