Skip to content

Commit 5117b6f

Browse files
authored
Merge pull request #99 from Leets-Official/98-fix/채팅-연결-오류-수정
[Fix] 채팅 연결 오류 수정
2 parents 9e114f2 + 36f2f4e commit 5117b6f

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/pages/chat/model/useChatState.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const useChatState = () => {
4040
// rooms에서 선택된 방 정보 가져오기
4141
const selectedRoom = rooms.find((r) => r.roomId === selectedRoomId);
4242
const postId = selectedRoom?.postId ?? null;
43-
const { data: currentRoom, isLoading: isRoomLoading } = useChatRoomQuery(postId);
43+
const partnerId = selectedRoom?.partnerId ?? null;
44+
const { data: currentRoom, isLoading: isRoomLoading } = useChatRoomQuery(postId, partnerId);
4445

4546
const isLoading = isMessagesLoading || isRoomLoading;
4647

src/shared/apis/chat/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export const createOrGetRoom = async (postId: number): Promise<ChatRoomData> =>
1515
return response.data.data;
1616
};
1717

18+
export const getRoomByPostId = async (postId: number, partnerId: number): Promise<ChatRoomData> => {
19+
const response = await axiosInstance.get<CreateRoomResponseBody>(CHAT_ENDPOINTS.ROOM(postId), {
20+
params: { partnerId },
21+
});
22+
return response.data.data;
23+
};
24+
1825
export const getChatRooms = async (): Promise<ChatRoomListItem[]> => {
1926
const response = await axiosInstance.get<ChatRoomListResponseBody>(CHAT_ENDPOINTS.ROOMS);
2027
return response.data.data;

src/shared/apis/chat/queries.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useAuthStore } from '@shared/stores';
22
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3-
import { checkUnreadMessages, createOrGetRoom, getChatMessages, getChatRooms } from './api';
3+
import { checkUnreadMessages, createOrGetRoom, getChatMessages, getChatRooms, getRoomByPostId } from './api';
44
import { chatKeys } from './keys';
55

66
export const useChatRoomsQuery = () => {
@@ -30,11 +30,11 @@ export const useCreateRoomMutation = () => {
3030
});
3131
};
3232

33-
export const useChatRoomQuery = (postId: number | null) => {
33+
export const useChatRoomQuery = (postId: number | null, partnerId: number | null) => {
3434
return useQuery({
3535
queryKey: chatKeys.roomByPost(postId!),
36-
queryFn: () => createOrGetRoom(postId!),
37-
enabled: postId !== null,
36+
queryFn: () => getRoomByPostId(postId!, partnerId!),
37+
enabled: postId !== null && partnerId !== null,
3838
staleTime: 5 * 60 * 1000,
3939
});
4040
};

0 commit comments

Comments
 (0)