@@ -3,6 +3,8 @@ import { connectSocket, subChatListSocket } from '@/common/utils/wsClient';
33import { useQueryClient } from '@tanstack/react-query' ;
44import { QUERY_KEYS } from '@/libs/queryKeys' ;
55import { useUnreadChatStore } from '@/common/store/UnreadChatStore' ;
6+ import { useInAppNotificaiton } from '@/common/hooks/useInAppNotification' ;
7+ import { useLocation } from 'react-router' ;
68
79interface Props {
810 children : React . ReactNode ;
@@ -11,6 +13,9 @@ interface Props {
1113const SocketProvider = ( { children } : Props ) => {
1214 const queryClient = useQueryClient ( ) ;
1315 const setUnreadChatCount = useUnreadChatStore ( state => state . setUnreadChatCount ) ;
16+ const { openNotification } = useInAppNotificaiton ( ) ;
17+ const location = useLocation ( ) ;
18+ console . log ( location . pathname ) ;
1419
1520 useEffect ( ( ) => {
1621 let unsubscribe : ( ( ) => void ) | undefined ;
@@ -21,6 +26,18 @@ const SocketProvider = ({ children }: Props) => {
2126 unsubscribe = subChatListSocket ( data => {
2227 queryClient . invalidateQueries ( { queryKey : [ QUERY_KEYS . CHAT_LIST ] } ) ;
2328 if ( data . type === 'UNREAD_CHAT_COUNT' ) setUnreadChatCount ( data . message . unreadChatCount ) ;
29+ if ( data . type === 'CHAT' ) {
30+ if ( location . pathname . startsWith ( '/chat' ) ) {
31+ return ;
32+ }
33+
34+ const content = data . message . mostRecentChatContent ;
35+ const nickname = data . message . mostRecentChatNickname ;
36+ const profileImage = data . message . opponentProfileImageUrl ;
37+ const chatRoomId = data . message . chatRoomId ;
38+
39+ openNotification ( { content, nickname, profileImage, chatRoomId } ) ;
40+ }
2441 } ) ;
2542 } )
2643 . catch ( err => {
@@ -30,7 +47,7 @@ const SocketProvider = ({ children }: Props) => {
3047 return ( ) => {
3148 unsubscribe ?.( ) ;
3249 } ;
33- } , [ queryClient , setUnreadChatCount ] ) ;
50+ } , [ queryClient , setUnreadChatCount , location . pathname ] ) ;
3451
3552 return < > { children } </ > ;
3653} ;
0 commit comments