Skip to content

Commit

Permalink
chore: fix exception on useEffect to avoid wrong unread count (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuhho committed Apr 20, 2024
1 parent 369eff3 commit 26c7188
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/pages/Buyer/BuyerChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const BuyerChat = () => {
}
};

const sentExitResponse = () => {
const sendExitResponse = () => {
if (stompClient.current && stompClient.current.connected) {
stompClient.current.send('app/api/v1/chat/customers/exit/' + chatId, {});
}
Expand Down Expand Up @@ -352,10 +352,13 @@ export const BuyerChat = () => {
});

useEffect(() => {
// 컴포넌트가 마운트되었을 때 실행
if (stompClient.current?.connected) {
connectChat();
if (!stompClient.current?.connected) {
return;
}
// 컴포넌트가 마운트되었을 때 실행

connectChat();

//채팅 불러오기
getChatMessages(0);
//
Expand All @@ -374,7 +377,7 @@ export const BuyerChat = () => {
stompClient.current.unsubscribe(
'/queue/chatMessages/customers/' + chatId,
);
sentExitResponse();
sendExitResponse();
}
};
}, [stompClient.current?.connected]);
Expand Down
8 changes: 5 additions & 3 deletions src/pages/Seller/SellerChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,12 @@ const SellerChat = () => {
});

useEffect(() => {
// 컴포넌트가 마운트되었을 때 실행
if (stompClient.current?.connected) {
connectChat();
if (!stompClient.current?.connected) {
return;
}

connectChat();

//채팅 불러오기
getChatMessages(0);
//채팅 status, 상대이름 가져오기
Expand Down

0 comments on commit 26c7188

Please sign in to comment.