Skip to content

Conversation

@chysis
Copy link
Collaborator

@chysis chysis commented Mar 3, 2025

이슈번호

요약(개요)

  • 로그인 한 사용자의 정보 조회 api를 연동했습니다.

    • UserProfile에서 사용자 정보를 요청하고, userId를 전역 상태로 관리합니다.
    • 사용자 정보 api의 staleTime은 현재 access_token의 유효 기간인 2주와 동일하게 설정했습니다.
  • 친구 목록, 보낸/받은 친구 요청 목록, 받은 요청에 대한 수락/거절 api를 연동했습니다.

    • 친구 목록은 자주 바뀌는 데이터가 아니므로 staleTime을 10분으로 설정했습니다.
    • 보낸/받은 친구 요청 목록은 실시간성이 중요하므로 매번 fetch합니다.
    • 받은 요청을 수락/거절하면 친구 요청 목록과 친구 목록 query를 무효화합니다.
    • 받은 요청을 수락하는 경우 해당 친구와의 DM 채팅방을 자동으로 생성합니다.
    • 친구 요청하기 전에 먼저 친구로 등록된 사용자인지, 이미 요청을 보냈거나 받았는지를 확인한 뒤에 친구 검색하고, 성공 시에 요청을 보냅니다.
  • DM 목록 조회 및 DM 생성 api를 연동했습니다.

    • DM 생성 모달에서는 최대 9명의 친구를 선택해서 방을 만들 수 있습니다. 생성하면 모달은 닫힙니다.
  • 친구 삭제 api를 연동했습니다.

  • 계정 탈퇴 api를 연동했습니다.

  • 기타 코드 컨벤션 관련 또는 디자인 수정이 있습니다.

작업 내용

image
▲ 길드 리스트에서 DM을 선택한 경우

image
image
▲ 대기 중(받은, 보낸 친구 요청 목록)인 목록

image
▲ DM 생성 모달

집중해서 리뷰해야 하는 부분

기타 전달 사항 및 참고 자료(선택)

  • 외장 ssd로 파일 옮기다가 작업한 게 전부 날아갈 뻔했네요... 무서워서 일단 PR 먼저 올렸습니다😞
  • 친구 검색 시 응답으로 userId를 함께 내려줘야 하는데, api가 수정되는 대로 반영할 예정입니다. -> 반영 완료했습니다

@chysis chysis self-assigned this Mar 3, 2025
@chysis chysis linked an issue Mar 3, 2025 that may be closed by this pull request
4 tasks
Comment on lines +29 to +31
const [friends, sentRequests, receivedRequests] = await Promise.all([
getFriendsList(),
getSentRequest(),
getReceivedRequest(),
]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

친구 검색 버튼을 누르기 전에 불필요한 요청이 가지 않도록 Promise.all을 사용했어요.

Comment on lines 29 to 32
try {
createDirectMessageMutation.mutate({ bodyRequest: { memberIds: selectedFriends } });
} catch (error) {
console.log('DM 생성 실패', error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usePostDirect 훅에서 onError 콜백으로도 처리가 가능할 것 같아요!

Copy link
Collaborator Author

@chysis chysis Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러 처리도 mutation에서 하도록 수정했습니다!

f7ec3ef


const handleCreateDirectMessage = async () => {
try {
createDirectMessageMutation.mutate({ bodyRequest: { memberIds: selectedFriends } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usePostDirect 훅에서는 createDirectMessage를 제공하는데, 해당 모달 컴포넌트에서는 이 훅을 사용할 때 createDirectMessageMutation.mutate()를 쓰시는 이유가 궁금해요!

const handleCreateDirectMessage = () => {
  createDirectMessage(selectedFriends);
};

이런 방식은 비효율적일까요?-?

Copy link
Collaborator Author

@chysis chysis Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutate 기능만 수행하는 함수를 뒤늦게 만들고, 이 부분을 다시 수정하질 않았네요😅
mutate 기능은 함수로 분리하고, mutation의 필요한 속성들은 따로 반환하도록 수정했어요!

f7ec3ef

{friends.map((friend) => (
<S.FriendItem key={friend.userId} onClick={() => handleCheckboxClick(friend.userId)}>
<S.FriendProfileImage $imageUrl={friend.profileImageUrl}>
<S.FriendStatusMark $isOnline={true} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$isOnline은 테스트를 위해 임시로 true로 고정해두신거죵??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞아요! 상태 관리가 도입되면 수정할 예정이에요

Comment on lines 18 to 25
const handleDeleteFriend = async () => {
try {
await deleteFriend({ friendId });
queryClient.invalidateQueries({ queryKey: ['friendsList'] });
} catch (error) {
console.error('친구 삭제 실패', error);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

갑자기 든 생각인데 나중에 해당 부분은 useMutation을 사용해보는건 어떨까요? 사실 뭐가 더 나은지 저도 잘 몰라서 같이 고민해보고 싶었어요 헤헿

const deleteFriendMutation = useMutation({
    mutationFn: () => deleteFriend({friendId});
    onSuccess: () => {
        queryClient.invalidateQueries({ queryKey: ['friendsList']});
    },
    onError: (error) => {
        console.error('친구 삭제 실패', error);
    }
})

당장은 이런 생각이긴 했던 것 같아요!

Copy link
Collaborator Author

@chysis chysis Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteFriend도 useMutation을 사용하여 분리했어요 :)

95ed854

Comment on lines 33 to 36
const directMessageName = members.responses
.filter((member) => member.userId !== userInfo?.userId)
.map((member) => member.nickname)
.join(', ');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userImageUrl 에서도 filter((member) => member.userId !== userInfo?.userId) 가 반복되는 부분은 otherMembers = ~ 와같이 빼볼 수도 있을 것 같다는 생각이 들었어요 😃 물론 지금도 반복되는 부분이 많이 없어서 크게 상관없는 부분이긴한 것 같아요 ㅎㅎ

Copy link
Collaborator Author

@chysis chysis Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반복되는 코드도 줄일 수 있고, 무엇보다도 '나를 제외한 다른 멤버 리스트'에서 무언가를 한다는 것이 더 명확히 보이는 것 같아서 변수로 분리했어요! 꼼꼼하게 봐주셔서 감사해요👍👍

a24e54d


import usePostDirect from '../../CreateDirectMessageModal/hooks/usePostDirect';

const useHandleFriendRequest = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넘 깔꼼,, 👍🏻

Comment on lines 16 to 25
useEffect(() => {
if (queryResult.data) setUserInfo({ userId: queryResult.data.result.userId });
}, [queryResult.data, setUserInfo]);

useEffect(() => {
if (queryResult.isError) clearUserInfo();
}, [queryResult.isError, clearUserInfo]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffect를 사용해서 값이 변할 때마다 store를 업데이트하면 불필요한 렌더링이 생길 수 있지 않을까 하는 고민이 들었던 것 같아요,,! onSuccesssetUserInfo를 하고, onErrorcloseUserInfo를 해보는건 별로일까요? 🤔(쿼리 알못)

Copy link
Collaborator Author

@chysis chysis Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TanStack Query가 v5로 업데이트 되면서 useQuery의 onSuccess, onError가 없어졌어요. 관련 글
그래서 필요한 경우에 onError의 경우에는 queryClient에서 일괄 적용이 가능한데, useGetUserInfo에 특화된 에러 처리를 해야 하기 때문에 useEffect를 사용했어요.

onSuccess의 경우에도 useEffect를 사용했어요.

staleTime을 14일로 설정했기 때문에 그 동안은 새로 요청하지 않고, useEffect도 실행되지 않아요. 하지만 로그아웃/재로그인 등의 이유로 이 쿼리가 무효화 또는 삭제될 수 있기 때문에, 성공했을 때 매번 setUserInfo를 수행하지 않고 기존의 데이터와 비교해서 다를 때만 set 하는 것으로 수정했어요 :) 안전 장치라고 생각해주시면 될 것 같아요!

d532252

Copy link
Member

@zelkovaria zelkovaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

철민님 ,, 넘 늦었죠,, ( ˃̣̣̥ω˂̣̣̥ ) 작업량도 많았는데 전반적으로 너무 잘 해주신 것 같아요! 고생 많으셨어요 👍🏻 디테일하게 확인을 더 많이 못해서 죄송하네요 ㅠ.ㅠ 제가 남긴 코멘트들은 반영을 하지 않아도 되는 부분이고 같이 고민하고 싶었던 부분이 더 큰 것 같으니 편히 읽어주세요 ㅎㅎ 큰 이슈 없어서 approve 해둘게요! 든든한 FE(not철민) 팀원 갓철민! (코멘트 알림 여러번 날려서 죗옹합니다 ,,,)

chysis added 28 commits March 6, 2025 19:03
@chysis chysis force-pushed the fe/feat/89-friends-dm branch from cd03dda to d532252 Compare March 6, 2025 10:03
@chysis chysis merged commit 6847d55 into main Mar 6, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FE] feat: 친구 관련 api 연동 및 DM 채팅 연동

3 participants