From fdeba796f81073cb9dc0fe55b3243e802c0f0693 Mon Sep 17 00:00:00 2001 From: Jihoo Kim Date: Tue, 22 Aug 2023 14:00:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8C=93=EA=B8=80=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=AC=20=EB=95=8C=20api=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=88=98=20=EC=A4=84=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comments/components/CommentItem/CommentItem.tsx | 7 +------ .../comments/components/CommentList/CommentList.tsx | 2 +- src/features/comments/queries/useGetComments.tsx | 7 +++++++ src/features/comments/types.ts | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/features/comments/components/CommentItem/CommentItem.tsx b/src/features/comments/components/CommentItem/CommentItem.tsx index 338fa3b9..4837eff5 100644 --- a/src/features/comments/components/CommentItem/CommentItem.tsx +++ b/src/features/comments/components/CommentItem/CommentItem.tsx @@ -3,7 +3,6 @@ import { useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { commentStateAtom } from '@/features/comments/states/comment'; import { useUser } from '@/features/user/queries/useUser'; -import { useGetMyChoice } from '@/features/vote/queries'; import CommentContent from './CommentContent'; import CommentFooter from './CommentFooter'; import CommentHeader from './CommentHeader'; @@ -37,10 +36,6 @@ export function CommentItem({ scrollEnabled, }: CommentItemProps) { const [commentState, setCommentState] = useAtom(commentStateAtom); - const { data: choice } = useGetMyChoice({ - userId: user.id, - postId: user.choiceLabel ? undefined : commentState.postId || undefined, - }); const navigate = useNavigate(); const { user: currentUser } = useUser(); const ref = useRef(null); @@ -111,7 +106,7 @@ export function CommentItem({ email={user.email} nickname={user.nickname} age={user.age} - choice={user.choiceLabel || choice?.label || null} + choice={user.choiceLabel} isWriter={isWriter} isMyComment={user.id === currentUser?.id} commentId={commentId} diff --git a/src/features/comments/components/CommentList/CommentList.tsx b/src/features/comments/components/CommentList/CommentList.tsx index 247a5775..39128822 100644 --- a/src/features/comments/components/CommentList/CommentList.tsx +++ b/src/features/comments/components/CommentList/CommentList.tsx @@ -45,7 +45,7 @@ export function CommentList({ writerId, comments }: CommentListProps) { email: reply.user.email, nickname: reply.user.nickname, age: calculateAgeFromBirthDate(reply.user.birthDate), - choiceLabel: null, // TODO: api 응답 변경 + choiceLabel: reply.user.choice?.label || null, }} isWriter={writerId === reply.user.id} content={reply.content} diff --git a/src/features/comments/queries/useGetComments.tsx b/src/features/comments/queries/useGetComments.tsx index 15f32602..c369189e 100644 --- a/src/features/comments/queries/useGetComments.tsx +++ b/src/features/comments/queries/useGetComments.tsx @@ -50,6 +50,13 @@ export function useGetComments(postId: number) { profileImage: user.profileImageUrl, nickname: user.nickname, birthDate: user.birthDate, + worryChoice: user.worryChoice + ? { + id: user.worryChoice.id, + label: user.worryChoice.label, + isAbstained: user.worryChoice.isAbstained === 'yes', + } + : null, }, }), ) || [], diff --git a/src/features/comments/types.ts b/src/features/comments/types.ts index aa9775da..0cd9f714 100644 --- a/src/features/comments/types.ts +++ b/src/features/comments/types.ts @@ -28,6 +28,11 @@ export interface Comment { profileImage: string | null; nickname: string; birthDate: string; + choice: { + id: number; + label: string; + isAbstained: boolean; + } | null; }; }[]; }