@@ -10,10 +10,10 @@ import 'swiper/css/pagination';
1010
1111import theme from '@styles/theme' ;
1212
13- import { createMatchingApi } from '@apis/matching' ;
1413import { togglePostLikeStatusApi } from '@apis/post-like' ;
1514import { postUserBlockApi } from '@apis/user-block' ;
1615import { handleError } from '@apis/util/handleError' ;
16+ import { useSocket } from '@context/SocketProvider' ;
1717import { getCurrentUserId } from '@utils/getCurrentUserId' ;
1818
1919import defaultProfile from '@assets/default/defaultProfile.svg' ;
@@ -29,7 +29,6 @@ import OptionsBottomSheet from '@components/BottomSheet/OptionsBottomSheet';
2929import Modal from '@components/Modal' ;
3030import { StyledText } from '@components/Text/StyledText' ;
3131
32- import type { CreateMatchingRequest } from '@apis/matching/dto' ;
3332import type { PostUserBlockRequest } from '@apis/user-block/dto' ;
3433import type { CommentBottomSheetProps } from '@components/BottomSheet/CommentBottomSheet/dto' ;
3534import { OptionsBottomSheetProps } from '@components/BottomSheet/OptionsBottomSheet/dto' ;
@@ -65,6 +64,8 @@ const Feed: React.FC<FeedProps> = ({ feed }) => {
6564 const currentUserId = getCurrentUserId ( ) ;
6665 const timeAgo = dayjs ( feed . createdAt ) . locale ( 'ko' ) . fromNow ( ) ;
6766
67+ const socket = useSocket ( 'matching' ) ;
68+
6869 const handleMoreButtonClick = ( e : React . MouseEvent ) => {
6970 e . stopPropagation ( ) ;
7071 setIsOptionsBottomSheetOpen ( true ) ;
@@ -141,26 +142,22 @@ const Feed: React.FC<FeedProps> = ({ feed }) => {
141142 }
142143 } ;
143144
144- // 매칭 생성 api
145- const createMatching = async ( comment : string ) => {
146- try {
147- const matchingRequest : CreateMatchingRequest = {
148- requesterId : currentUserId || - 1 ,
149- targetId : feed . user . id || - 1 ,
150- message : comment ,
151- } ;
152- const response = await createMatchingApi ( matchingRequest ) ;
145+ // 매칭 신청 socket api
146+ const createMatching = ( comment : string ) => {
147+ socket . emit ( 'requestMatching' , {
148+ requesterId : currentUserId ,
149+ targetId : feed . user . id ,
150+ message : comment ,
151+ } ) ;
153152
154- if ( response . isSuccess ) {
155- setModalContent ( `${ feed . user . nickname } 님에게 대표 OOTD와\n한 줄 메세지를 보냈어요!` ) ;
156- }
157- } catch ( error ) {
158- const errorMessage = handleError ( error , 'user' ) ;
159- setModalContent ( errorMessage ) ;
160- } finally {
153+ socket . on ( 'error' , ( data ) => {
154+ setModalContent ( data ) ;
161155 setIsMatchingCommentBottomSheetOpen ( false ) ;
162156 setIsStatusModalOpen ( true ) ;
163- }
157+
158+ // 리스너가 중복 등록되지 않도록 바로 정리
159+ socket . off ( 'error' ) ;
160+ } ) ;
164161 } ;
165162
166163 // 게시글 옵션(더보기) 바텀시트
0 commit comments