Skip to content

Commit

Permalink
FE-89 ♻️ 필요없는 count 상태 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
JeonYumin94 committed Aug 9, 2024
1 parent 296874d commit 4f8311a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
22 changes: 12 additions & 10 deletions src/hooks/useMyContentState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ export default function useMyContentState(user: UserInfo) {
const limit = 3;
const [isLoadingMore, setIsLoadingMore] = useState(false);
const [selectedTab, setSelectedTab] = useState<'epigrams' | 'comments'>('epigrams');
const [epigramCount, setEpigramCount] = useState(0);
const [commentCount, setCommentCount] = useState(0);

const [epigramCursor, setEpigramCursor] = useState<number>(0);
const [commentCursor, setCommentCursor] = useState<number>(0);
const [epigrams, setEpigrams] = useState<EpigramsResponse>({ totalCount: 0, nextCursor: null, list: [] });
const [comments, setComments] = useState<CommentResponseType>({ totalCount: 0, nextCursor: null, list: [] });

const { data: count } = useGetMyContentHook({ id: user.id });
const { data: countData } = useGetMyContentHook({ id: user.id });
const epigramsRequest = { limit, cursor: epigramCursor, writerId: user.id };
const commentsRequest = { limit, cursor: commentCursor, id: user.id };

const { data: epigramsData, isLoading: isEpigramsLoading, error: epigramsError } = useGetEpigrams(epigramsRequest);
const { data: commentData, isLoading: isCommentsLoading, error: commentsError, refetch: refetchComments } = useCommentsHook(commentsRequest);

useEffect(() => {
if (count) {
setEpigramCount(count.epigramCount);
setCommentCount(count.commentCount);
if (countData) {
setEpigrams((prev) => ({
...prev,
totalCount: countData.epigramCount,
}));
setComments((prev) => ({
...prev,
totalCount: countData.commentCount,
}));
}
}, [count]);
}, [countData]);

useEffect(() => {
if (selectedTab === 'epigrams' && epigramsData) {
Expand Down Expand Up @@ -85,8 +90,6 @@ export default function useMyContentState(user: UserInfo) {
return {
isLoadingMore,
selectedTab,
epigramCount,
commentCount,
epigrams,
comments,
isEpigramsLoading,
Expand All @@ -95,7 +98,6 @@ export default function useMyContentState(user: UserInfo) {
commentsError,
handleMoreLoad,
handleTabClick,
setCommentCount,
setComments,
refetchComments,
};
Expand Down
24 changes: 4 additions & 20 deletions src/pageLayout/MypageLayout/MyContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,8 @@ interface MyContentProps {

export default function MyContent({ user }: MyContentProps) {
const { toast } = useToast();
const {
isLoadingMore,
selectedTab,
epigramCount,
commentCount,
epigrams,
comments,
isEpigramsLoading,
isCommentsLoading,
epigramsError,
commentsError,
handleMoreLoad,
handleTabClick,
setComments,
setCommentCount,
refetchComments,
} = useMyContentState(user);
const { isLoadingMore, selectedTab, epigrams, comments, isEpigramsLoading, isCommentsLoading, epigramsError, commentsError, handleMoreLoad, handleTabClick, setComments, refetchComments } =
useMyContentState(user);

const deleteCommentMutation = useDeleteCommentMutation({
onSuccess: ({ commentId }) => {
Expand All @@ -39,7 +24,6 @@ export default function MyContent({ user }: MyContentProps) {
nextCursor: prev.nextCursor,
list: prev.list.filter((comment) => comment.id !== commentId),
}));
setCommentCount((prev) => prev - 1);
},
});

Expand Down Expand Up @@ -75,14 +59,14 @@ export default function MyContent({ user }: MyContentProps) {
onClick={() => selectedTab !== 'epigrams' && handleTabClick('epigrams')}
disabled={selectedTab === 'epigrams'}
>
내 에피그램({epigramCount})
내 에피그램({epigrams.totalCount})
</Button>
<Button
className={`font-semibold text-2xl ${selectedTab === 'comments' ? 'cursor-default text-black-600 disabled:opacity-1 ' : 'cursor-pointer text-neutral-400'}`}
onClick={() => selectedTab !== 'comments' && handleTabClick('comments')}
disabled={selectedTab === 'comments'}
>
내 댓글({commentCount})
내 댓글({comments.totalCount})
</Button>
</div>
<div className='w-full py-[36px]'>
Expand Down

0 comments on commit 4f8311a

Please sign in to comment.