Skip to content

Commit aed0b2a

Browse files
committed
Fix: api 응답 수정에 따라 opponentInfo -> otherUser로 수정
1 parent 32f6884 commit aed0b2a

6 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/pages/Chats/ChatRoom/ChatBox/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChatBoxContainer, Textarea, SendButton } from './styles';
22
import { useEffect, useRef, useState } from 'react';
33
import { useRecoilValue } from 'recoil';
44
import { useParams } from 'react-router-dom';
5-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
5+
import { OtherUserAtom } from '@recoil/util/OtherUser';
66
import { useSocket } from '@context/SocketProvider';
77
import { getCurrentUserId } from '@utils/getCurrentUserId';
88

@@ -13,8 +13,8 @@ const ChatBox: React.FC = () => {
1313

1414
const { chatRoomId } = useParams();
1515
const currentUserId = getCurrentUserId();
16-
const opponentInfo = useRecoilValue(OpponentInfoAtom);
17-
const isOpponentValid = !!(opponentInfo && opponentInfo.id);
16+
const otherUser = useRecoilValue(OtherUserAtom);
17+
const isOpponentValid = !!(otherUser && otherUser.id);
1818

1919
useEffect(() => {
2020
if (textareaRef.current && !isOpponentValid) {
@@ -51,7 +51,7 @@ const ChatBox: React.FC = () => {
5151
if (socket) {
5252
const sendMessageRequest = {
5353
chatRoomId: Number(chatRoomId),
54-
toUserId: opponentInfo?.id,
54+
toUserId: otherUser?.id,
5555
content: newMessage,
5656
fromUserId: currentUserId,
5757
createdAt: new Date().toISOString(),

src/pages/Chats/ChatRoom/createExtendedMessages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { chatRoomMessagesData } from '@apis/chatting/dto';
88
export const createExtendedMessages = (
99
allMessages: chatRoomMessagesData[],
1010
userId: number,
11-
opponentInfo: OtherUserDto | null,
11+
otherUser: OtherUserDto | null,
1212
) => {
1313
// DateBar 표시 여부를 결정하는 함수
1414
const isNewDay = (curDate: string, lastDate: string) => {
@@ -57,8 +57,8 @@ export const createExtendedMessages = (
5757
} else {
5858
// 받은 메시지일 경우 rcvdMessage 속성 추가
5959
const rcvdMessage: RcvdMessageProps = {
60-
fromUserNickname: opponentInfo?.nickname || '알수없음',
61-
profilePictureUrl: opponentInfo?.profilePictureUrl || defaultProfile,
60+
fromUserNickname: otherUser?.nickname || '알수없음',
61+
profilePictureUrl: otherUser?.profilePictureUrl || defaultProfile,
6262
content: message.content,
6363
isProfileImageVisible,
6464
isSenderChanged,

src/pages/Chats/ChatRoom/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type { BottomSheetMenuProps } from '@components/BottomSheetMenu/dto';
1818
import type { ModalProps } from '@components/Modal/dto';
1919
import { createExtendedMessages } from './createExtendedMessages';
2020
import { AllMesagesAtom } from '@recoil/Chats/AllMessages';
21-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
21+
import { OtherUserAtom } from '@recoil/util/OtherUser';
2222
import { useSocket } from '@context/SocketProvider';
2323
import Back from '@assets/arrow/left.svg';
2424
import KebabMenu from '@assets/default/more.svg';
@@ -52,7 +52,7 @@ const ChatRoom: React.FC = () => {
5252

5353
const { chatRoomId } = useParams();
5454
const currentUserId = getCurrentUserId();
55-
const opponentInfo = useRecoilValue(OpponentInfoAtom);
55+
const otherUser = useRecoilValue(OtherUserAtom);
5656

5757
// 메시지 수신 시 아래로 스크롤 (스크롤 아래 고정)
5858
const scrollToBottom = (ref: React.RefObject<HTMLDivElement>) => {
@@ -61,21 +61,21 @@ const ChatRoom: React.FC = () => {
6161

6262
// 프로필 사진 클릭 시 프로필 페이지로 이동
6363
const handleUserClick = useCallback(() => {
64-
const opponentId = opponentInfo?.id ? opponentInfo.id : -1;
64+
const opponentId = otherUser?.id ? otherUser.id : -1;
6565
if (opponentId === -1) {
6666
setModalContent('유저 정보를 찾을 수 없습니다.');
6767
setIsStatusModalOpen(true);
6868
} else {
6969
nav(`/users/${opponentId}`);
7070
}
71-
}, [opponentInfo, nav]);
71+
}, [otherUser, nav]);
7272

7373
// 유저 차단 api
7474
const postUserBlock = async () => {
7575
try {
7676
const data: PostUserBlockRequest = {
7777
requesterId: currentUserId,
78-
targetId: opponentInfo?.id || -1,
78+
targetId: otherUser?.id || -1,
7979
action: 'block',
8080
};
8181
const response = await postUserBlockApi(data);
@@ -133,7 +133,7 @@ const ChatRoom: React.FC = () => {
133133
// 메시지 수신 시
134134
useEffect(() => {
135135
// 렌더링에 필요한 정보 추가
136-
const temp = createExtendedMessages(allMessages, currentUserId, opponentInfo);
136+
const temp = createExtendedMessages(allMessages, currentUserId, otherUser);
137137
setExtendedMessages(temp);
138138

139139
// 스크롤 아래로 이동
@@ -230,7 +230,7 @@ const ChatRoom: React.FC = () => {
230230
return (
231231
<OODDFrame>
232232
<TopBar
233-
text={opponentInfo?.nickname || '알수없음'}
233+
text={otherUser?.nickname || '알수없음'}
234234
LeftButtonSrc={Back}
235235
RightButtonSrc={KebabMenu}
236236
onClickLeftButton={() => {

src/pages/Chats/ChatRoomItem/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StyledText } from '@components/Text/StyledText';
22
import { UserImage, ChatRoomItemLayout, LeftBox, RightBox, LatestMessage } from './styles';
33
import { useNavigate } from 'react-router-dom';
44
import { useRecoilState } from 'recoil';
5-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
5+
import { OtherUserAtom } from '@recoil/util/OtherUser';
66
import dayjs from 'dayjs';
77
import relativeTime from 'dayjs/plugin/relativeTime';
88
import 'dayjs/locale/ko';
@@ -13,11 +13,11 @@ dayjs.extend(relativeTime);
1313

1414
const ChatRoomItem: React.FC<ChatRoomData> = ({ id, otherUser, latestMessage }) => {
1515
const [timeAgo, setTimeAgo] = useState<string | null>(null);
16-
const [, setOpponentInfo] = useRecoilState(OpponentInfoAtom);
16+
const [, setOtherUser] = useRecoilState(OtherUserAtom);
1717
const nav = useNavigate();
1818

1919
const handleChatRoomClick = () => {
20-
setOpponentInfo(otherUser);
20+
setOtherUser(otherUser);
2121
nav(`/chats/${id}`);
2222
};
2323

src/pages/Chats/Matching/Cards/Card/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import { handleError } from '@apis/util/handleError';
2626
import type { ModalProps } from '@components/Modal/dto';
2727
import Modal from '@components/Modal';
2828
import { useRecoilState } from 'recoil';
29-
import { OpponentInfoAtom } from '@recoil/util/OpponentInfo';
29+
import { OtherUserAtom } from '@recoil/util/OtherUser';
3030
import type { CardProps } from './dto';
3131

3232
const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
3333
const [isStatusModalOpen, setIsStatusModalOpen] = useState(false);
3434
const [modalContent, setModalContent] = useState('알 수 없는 오류가 발생했습니다.\n관리자에게 문의해 주세요.');
35-
const [, setOpponentInfo] = useRecoilState(OpponentInfoAtom);
35+
const [, setOtherUser] = useRecoilState(OtherUserAtom);
3636
const nav = useNavigate();
3737
const requester = matching.requester;
3838

@@ -58,7 +58,7 @@ const Card: React.FC<CardProps> = ({ removeRejectedMatching, matching }) => {
5858
removeRejectedMatching(); // 매칭 리스트에서 해당 매칭을 제거
5959

6060
if (status === 'accept') {
61-
setOpponentInfo({
61+
setOtherUser({
6262
id: requester.id,
6363
nickname: requester.nickname,
6464
profilePictureUrl: requester.profilePictureUrl,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { OtherUserDto } from '@apis/chatting/dto';
44

55
const { persistAtom } = recoilPersist();
66

7-
export const OpponentInfoAtom = atom<OtherUserDto | null>({
8-
key: 'OpponentInfoAtom',
7+
export const OtherUserAtom = atom<OtherUserDto | null>({
8+
key: 'OtherUserAtom',
99
default: null,
1010
effects_UNSTABLE: [persistAtom],
1111
});

0 commit comments

Comments
 (0)