From 5f982a70bf9f3dae5fc5701c1967ecb8fa2cee49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=98=84=EC=A1=B0?= Date: Wed, 11 Sep 2024 13:41:35 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20Home=20=ED=8E=98=EC=9D=B4=EC=A7=80(?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=95=98=EB=8A=94=EA=B3=B3)=20?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Home/index.stories.tsx | 35 -------- frontend/src/components/Home/index.tsx | 85 +++++++++---------- 2 files changed, 41 insertions(+), 79 deletions(-) delete mode 100644 frontend/src/components/Home/index.stories.tsx diff --git a/frontend/src/components/Home/index.stories.tsx b/frontend/src/components/Home/index.stories.tsx deleted file mode 100644 index ace0d61..0000000 --- a/frontend/src/components/Home/index.stories.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import '@/index.css'; -import { Meta, StoryObj } from '@storybook/react'; -import Home from '.'; -import { useState } from 'react'; - -const HomeWrapper = ({ initialLoggedIn }: { initialLoggedIn: boolean }) => { - const [isLoggedIn, setIsLoggedIn] = useState(initialLoggedIn); - - return ( - - ); -}; - -const meta: Meta = { - title: 'Components/Home', - component: Home, - parameters: { - layout: 'fullscreen', - }, -}; - -export default meta; - -type Story = StoryObj; - -export const GoogleLogin: Story = { - render: () => , -}; - -export const SelectWorkspace: Story = { - render: () => , -}; diff --git a/frontend/src/components/Home/index.tsx b/frontend/src/components/Home/index.tsx index 73267d5..f275bf0 100644 --- a/frontend/src/components/Home/index.tsx +++ b/frontend/src/components/Home/index.tsx @@ -1,38 +1,45 @@ -import { useState } from 'react'; +import { useRef } from 'react'; import { useNavigate } from 'react-router-dom'; -import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue, SelectGroup } from '../ui/select'; import GoogleLogo from '@/assets/icons/web_neutral_rd_ctn@1x.png'; +import useAuthStore from '@/stores/useAuthStore'; +import { Button } from '@/components/ui/button'; +import { fetchProfileApi } from '@/api/authApi'; -interface HomeProps { - isLoggedIn?: boolean; - setIsLoggedIn?: (loggedIn: boolean) => void; -} +const DOMAIN = 'https://j11s002.p.ssafy.io'; -export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) { - const [, setSelectedWorkspace] = useState(''); - const [loggedIn, setLoggedIn] = useState(isLoggedIn); +export default function Home() { const navigate = useNavigate(); + const { isLoggedIn, setLoggedIn, profile, setProfile } = useAuthStore(); + const hasFetchedProfile = useRef(false); - const workspaces = [ - { id: 1, name: 'Workspace 1' }, - { id: 2, name: 'Workspace 2' }, - { id: 3, name: 'Workspace 3' }, - ]; + if (!isLoggedIn && !profile.id && !hasFetchedProfile.current) { + const accessToken = localStorage.getItem('accessToken'); + if (accessToken) { + setLoggedIn(true, accessToken); + fetchProfileApi() + .then((data) => { + if (data?.isSuccess && data.data) { + setProfile({ + id: data.data.id, + nickname: data.data.nickname, + profileImage: data.data.profileImage, + }); + hasFetchedProfile.current = true; + } + }) + .catch((error) => { + alert('프로필을 가져오는 중 오류가 발생했습니다. 다시 시도해주세요.'); + console.error('프로필 가져오기 실패:', error); + }); + } + } const handleGoogleSignIn = () => { - console.log('구글로 계속하기'); - setLoggedIn(true); - if (setIsLoggedIn) { - setIsLoggedIn(true); - } + window.location.href = `${DOMAIN}/api/login/oauth2/authorization/google`; }; - const handleWorkspaceSelect = (value: string) => { - const selected = workspaces.find((workspace) => workspace.name === value); - if (selected) { - navigate(`/browse/${selected.id}`); - } - setSelectedWorkspace(value); + const handleStart = () => { + navigate('/browse'); }; return ( @@ -41,7 +48,7 @@ export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) {

서비스 설명

본 서비스는 인공 지능(AI) 모델의 학습을 지원하기 위해 웹 기반의 자동 라벨링 도구를 개발하는 것을 목표로 - 합니다. 이 도구는 이미지나 텍스트와 같은 비정형 데이터에 레이블을 자동으로 부여하는 기능을 제공합니다. + 합니다.

기존의 수동적인 방법으로는 대량의 학습 데이터를 처리하는데 시간과 비용이 많이 소모되었습니다. 그러나 본 @@ -56,7 +63,7 @@ export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) {

- {!loggedIn ? ( + {!isLoggedIn ? ( ) : ( - + )} );