From aae5f9ab93a4a00e674827e343b7658d3cda4cf1 Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 13 Feb 2024 14:49:31 +0900 Subject: [PATCH] =?UTF-8?q?feature-060:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=8F=99=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/category/Card.tsx | 5 +- .../layout/header/profile/ProfileDetail.tsx | 1 + src/components/layout/sideBar/UserMode.tsx | 15 +++-- src/hooks/useMoveCategory.ts | 63 +++---------------- 4 files changed, 21 insertions(+), 63 deletions(-) diff --git a/src/components/category/Card.tsx b/src/components/category/Card.tsx index f07f41c..4e97d49 100644 --- a/src/components/category/Card.tsx +++ b/src/components/category/Card.tsx @@ -1,5 +1,6 @@ import React, { useEffect } from 'react'; import * as CardStyles from '@/styles/category/Card.style'; +import VideoTag from '../common/videoTag'; export interface IVideoProps { video_id: number; @@ -60,14 +61,14 @@ const Card: React.FC = ({ {video.description} - {/* {video.tag.map((tag) => ( + {video.tag.map((tag) => ( - ))} */} + ))} diff --git a/src/components/layout/header/profile/ProfileDetail.tsx b/src/components/layout/header/profile/ProfileDetail.tsx index 13b5c6f..44a54cd 100644 --- a/src/components/layout/header/profile/ProfileDetail.tsx +++ b/src/components/layout/header/profile/ProfileDetail.tsx @@ -27,6 +27,7 @@ const ProfileDetail = ({ onClose }: Props) => { const handleClickLogoutButton = () => { setUserToken(null); + navigate('/'); onClose(); }; diff --git a/src/components/layout/sideBar/UserMode.tsx b/src/components/layout/sideBar/UserMode.tsx index 9b5fe42..b2ed517 100644 --- a/src/components/layout/sideBar/UserMode.tsx +++ b/src/components/layout/sideBar/UserMode.tsx @@ -47,16 +47,21 @@ const UserMode = () => { }; const putCategoryFolder = async () => { + let response; if (grabedCategory.current?.topCategoryId === -1) { - subToTop(topId, grabedCategory, dropedCategory); + response = await subToTop(grabedCategory); } else if (grabedCategory.current?.topCategoryId === null) { - topToOtherTop(grabedCategory, dropedCategory); + response = await topToOtherTop(grabedCategory, dropedCategory); } else { - subToOtherTop(topId, grabedCategory); + response = await subToOtherTop(topId, grabedCategory); } // 잡은 카테고리, 놓은 카테고리 초기화 - grabedCategory.current = undefined; - dropedCategory.current = undefined; + if (response) { + grabedCategory.current = undefined; + dropedCategory.current = undefined; + } else { + alert('카테고리를 옮기는데 오류가 발생했습니다.'); + } }; return ( <> diff --git a/src/hooks/useMoveCategory.ts b/src/hooks/useMoveCategory.ts index 0b19138..3be900b 100644 --- a/src/hooks/useMoveCategory.ts +++ b/src/hooks/useMoveCategory.ts @@ -3,23 +3,13 @@ import { putSubToTop, putTopToOtherTop, } from '@/apis/category'; -import { categoryState } from '@/stores/category'; -import handleCategory from '@/utils/handleCategory'; import { useNavigate } from 'react-router-dom'; -import { useRecoilState } from 'recoil'; import { ISubFolderProps } from 'types/category'; import useUpdateCategories from './useUpdateCategories'; const useMoveCategory = () => { - const [categories, setCategories] = useRecoilState(categoryState); const navigate = useNavigate(); const { updateCategories } = useUpdateCategories(); - const { - deleteSubCategory, - deleteTopCategory, - insertCategory, - insertSubToTopCategory, - } = handleCategory(); const subToOtherTop = async ( topId: number, @@ -31,33 +21,20 @@ const useMoveCategory = () => { } // 하위에 있는 폴더를 다른 상위 폴더로 이동하는 기능 // 카테고리 이동1 - const deleteResponse = deleteSubCategory( - categories, - topId, - grabedCategory.current?.categoryId, - ); - const insertResponse = insertCategory( - deleteResponse, - grabedCategory.current?.topCategoryId, - grabedCategory.current!, - ); const res = await putSubToOtherTop( grabedCategory.current!.categoryId, topId, ); + console.log(res); if (res.isSuccess) { - updateCategories(); - setCategories([...insertResponse]); + await updateCategories(); navigate(`/category/${grabedCategory.current?.topCategoryId}`); - } else { - alert('카테고리를 옮기는데 오류가 발생했습니다.'); } + return res.isSuccess; }; const subToTop = async ( - topId: number, grabedCategory: React.MutableRefObject, - dropedCategory: React.MutableRefObject, ) => { if (grabedCategory.current?.name === '기타') { alert(`'기타' 폴더는 이동할 수 없습니다.`); @@ -65,23 +42,11 @@ const useMoveCategory = () => { } // 하위에 있는 폴더를 상위로 올리는 기능 // 카테고리 이동2 - const deleteResponse = deleteSubCategory( - categories, - topId, - grabedCategory.current?.categoryId, - ); - const insertResponse = insertSubToTopCategory( - deleteResponse, - dropedCategory.current, - grabedCategory.current!, - ); const res = await putSubToTop(grabedCategory.current!.categoryId); if (res.isSuccess) { - updateCategories(); - setCategories([...insertResponse]); - } else { - alert('카테고리를 옮기는데 오류가 발생했습니다.'); + await updateCategories(); } + return res.isSuccess; }; const topToOtherTop = async ( @@ -90,29 +55,15 @@ const useMoveCategory = () => { ) => { // 상위에 있는 폴더를 다른 상위 폴더로 넣는 기능 // 카테고리 이동3 - const deleteResponse = deleteTopCategory( - categories, - grabedCategory.current!.categoryId, - ); - const insertResponse = insertCategory( - deleteResponse, - dropedCategory.current!, - { - categoryId: grabedCategory.current!.categoryId, - name: grabedCategory.current!.name, - topCategoryId: dropedCategory.current!, - }, - ); const res = await putTopToOtherTop( grabedCategory.current!.categoryId, dropedCategory.current!, ); if (res.isSuccess) { - setCategories(insertResponse); + await updateCategories(); navigate(`/category/${dropedCategory.current}`); - } else { - alert('카테고리를 옮기는데 오류가 발생했습니다.'); } + return res.isSuccess; }; return { subToOtherTop, subToTop, topToOtherTop };