Skip to content

Commit bf1116e

Browse files
committed
refactor: 매칭 신청을 소켓 api로 변경
1 parent a192cbe commit bf1116e

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

src/pages/Home/OOTD/Feed/index.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import 'swiper/css/pagination';
1010

1111
import theme from '@styles/theme';
1212

13-
import { createMatchingApi } from '@apis/matching';
1413
import { togglePostLikeStatusApi } from '@apis/post-like';
1514
import { postUserBlockApi } from '@apis/user-block';
1615
import { handleError } from '@apis/util/handleError';
16+
import { useSocket } from '@context/SocketProvider';
1717
import { getCurrentUserId } from '@utils/getCurrentUserId';
1818

1919
import defaultProfile from '@assets/default/defaultProfile.svg';
@@ -29,7 +29,6 @@ import OptionsBottomSheet from '@components/BottomSheet/OptionsBottomSheet';
2929
import Modal from '@components/Modal';
3030
import { StyledText } from '@components/Text/StyledText';
3131

32-
import type { CreateMatchingRequest } from '@apis/matching/dto';
3332
import type { PostUserBlockRequest } from '@apis/user-block/dto';
3433
import type { CommentBottomSheetProps } from '@components/BottomSheet/CommentBottomSheet/dto';
3534
import { 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

Comments
 (0)