Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MOVIEJOJO7/cat-talk into fe…
Browse files Browse the repository at this point in the history
…ature/#63
  • Loading branch information
LikeFireAndSky committed Nov 15, 2023
2 parents cb6546d + 6a3e04f commit 4cc76a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
6 changes: 0 additions & 6 deletions Components/Chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { getCookie } from '@/Components/Login/Cookie';
import { useRouter } from 'next/navigation';
import { Socket } from 'socket.io-client';
import { DefaultEventsMap } from 'socket.io/dist/typed-events';

const ChatHeader = ({
socket,
chatId,
chatName,
chatUsers,
}: {
socket: Socket<DefaultEventsMap, DefaultEventsMap>;
chatId: string;
chatName: string;
chatUsers: number;
Expand All @@ -19,7 +15,6 @@ const ChatHeader = ({
const accessToken = getCookie('accessToken');

const handleBackChat = () => {
socket.disconnect();
router.back();
};

Expand All @@ -34,7 +29,6 @@ const ChatHeader = ({
body: JSON.stringify({ chatId }),
});

socket.disconnect();
router.back();
};

Expand Down
11 changes: 0 additions & 11 deletions Components/Chat/ChatRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ const ChatRoom = ({
});

socket.on('join', (responseData) => {
// console.log('join 이벤트 리슨');
// console.log('responseData: ', responseData);
// console.log('responseData.users: ', responseData.users);
// console.log('responseData.joiner: ', responseData.joiners);

setChatUsers([...chatUsers, ...responseData.users]);
socket.emit(
'message-to-server',
Expand All @@ -70,11 +65,6 @@ const ChatRoom = ({
});

socket.on('leave', (responseData) => {
// console.log('leave 이벤트 리슨');
// console.log('responseData: ', responseData);
// console.log('responseData.users: ', responseData.users);
// console.log('responseData.leaver: ', responseData.leaver);

setChatUsers([...chatUsers, ...responseData.users]);
socket.emit(
'message-to-server',
Expand Down Expand Up @@ -115,7 +105,6 @@ const ChatRoom = ({
return (
<>
<ChatHeader
socket={socket}
chatId={chatId}
chatName={chatName}
chatUsers={chatUsers.length}
Expand Down
8 changes: 8 additions & 0 deletions app/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSearchParams } from 'next/navigation';
import { getCookie } from '@/Components/Login/Cookie';
import { io } from 'socket.io-client';
import ChatRoom from '@/Components/Chat/ChatRoom';
import { useEffect } from 'react';

const Chat = ({ params }: { params: { id: string } }) => {
const chatId = params.id;
Expand All @@ -18,6 +19,13 @@ const Chat = ({ params }: { params: { id: string } }) => {
},
});

useEffect(() => {
return () => {
socket.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<ChatRoom
socket={socket}
Expand Down

0 comments on commit 4cc76a8

Please sign in to comment.