Refactor: 홈에서 선택한 워크스페이스로 이동 추가

This commit is contained in:
정현조 2024-09-09 17:38:08 +09:00
parent 020c2f6739
commit cb33e44d9a

View File

@ -1,4 +1,5 @@
import { useState } from 'react'; import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue, SelectGroup } from '../ui/select'; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue, SelectGroup } from '../ui/select';
import GoogleLogo from '@/assets/icons/web_neutral_rd_ctn@1x.png'; import GoogleLogo from '@/assets/icons/web_neutral_rd_ctn@1x.png';
@ -8,9 +9,9 @@ interface HomeProps {
} }
export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) { export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars const [, setSelectedWorkspace] = useState('');
const [selectedWorkspace, setSelectedWorkspace] = useState('');
const [loggedIn, setLoggedIn] = useState(isLoggedIn); const [loggedIn, setLoggedIn] = useState(isLoggedIn);
const navigate = useNavigate();
const workspaces = [ const workspaces = [
{ id: 1, name: 'Workspace 1' }, { id: 1, name: 'Workspace 1' },
@ -20,12 +21,20 @@ export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) {
const handleGoogleSignIn = () => { const handleGoogleSignIn = () => {
console.log('구글로 계속하기'); console.log('구글로 계속하기');
setLoggedIn(true); // 임시 코드 setLoggedIn(true);
if (setIsLoggedIn) { if (setIsLoggedIn) {
setIsLoggedIn(true); setIsLoggedIn(true);
} }
}; };
const handleWorkspaceSelect = (value: string) => {
const selected = workspaces.find((workspace) => workspace.name === value);
if (selected) {
navigate(`/browse/${selected.id}`);
}
setSelectedWorkspace(value);
};
return ( return (
<div className="flex h-full flex-col items-center justify-center bg-gray-50 p-8"> <div className="flex h-full flex-col items-center justify-center bg-gray-50 p-8">
<div className="mb-6 max-w-xl rounded-lg bg-white p-6 shadow-lg"> <div className="mb-6 max-w-xl rounded-lg bg-white p-6 shadow-lg">
@ -59,7 +68,7 @@ export default function Home({ isLoggedIn = false, setIsLoggedIn }: HomeProps) {
/> />
</button> </button>
) : ( ) : (
<Select onValueChange={(value) => setSelectedWorkspace(value)}> <Select onValueChange={handleWorkspaceSelect}>
<SelectTrigger className="mb-4 w-72"> <SelectTrigger className="mb-4 w-72">
<SelectValue placeholder="워크스페이스를 선택하세요" /> <SelectValue placeholder="워크스페이스를 선택하세요" />
</SelectTrigger> </SelectTrigger>