From c864634ffe7c57c1a3f2f8050cc005a027caa155 Mon Sep 17 00:00:00 2001 From: godhyzzang <109357302+godhyzzang@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:47:23 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20api=ED=98=B8=EC=B6=9C=EB=AC=B8?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(fullscreen)/login/add/page.tsx | 81 +++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/app/(fullscreen)/login/add/page.tsx b/src/app/(fullscreen)/login/add/page.tsx index fab3af98..2dac5eef 100644 --- a/src/app/(fullscreen)/login/add/page.tsx +++ b/src/app/(fullscreen)/login/add/page.tsx @@ -4,8 +4,8 @@ import React, { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; +import { useFetchAllCategories } from '@/api/hooks/useCategories'; import { useUpdateUserInfo } from '@/api/hooks/useUserInfo'; -import { fetchAllCategories } from '@/api/queries/fetchAllCategories'; import LoadingSpinner from '@/components/common/LoadingSpinner'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; @@ -13,7 +13,7 @@ import { useToast } from '@/hooks/use-toast'; import { CategoryList } from '@/types/Category'; export default function LoginAddPage() { - const [isLoading, setIsLoading] = useState(true); + const { data, isLoading } = useFetchAllCategories(); const [categories, setCategories] = useState([]); @@ -23,21 +23,11 @@ export default function LoginAddPage() { const toast = useToast(); - const getAllCategories = async () => { - try { - const initialCategories = await fetchAllCategories(); - - setCategories(initialCategories.data.categoryList); - } catch (error) { - console.error('Error fetching categories:', error); - } finally { - setIsLoading(false); - } - }; - useEffect(() => { - getAllCategories(); - }, []); + if (data) { + setCategories(data.data.categoryList); + } + }, [data]); const handlePreferedCategories = () => { if (selectedCategories.length !== 0 && selectedCategories.length <= 5) { @@ -75,32 +65,43 @@ export default function LoginAddPage() { }); }; - return ( + return isLoading ? ( +
+ +
+ ) : (
-

- 읽고싶은 글이나 영상의 카테고리를 골라주세요! -

- {isLoading ? ( - - ) : ( -
- {categories.map((category) => ( - - ))} -
- )} +

+
+ 첫 방문이시군요! 환영합니다!👋 +
+
+ + {' '} + 읽고싶은 아티클🖋️이나 영상 🖥️의 카테고리를 골라주세요! +
+ 선택한 카테고리 위주로 컨텐츠 추천이 제공됩니다. +
+

+ +
+ {categories.map((category) => ( + + ))} +
+