-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLIENT] 공통 레이아웃 적용을 위한 라우팅 구조 수정 (#48)
* feat: 공통 레이아웃 적용을 위해 라우팅 구조 변경 #47 - 기존: DM 페이지와 커뮤니티 페이지는 별개의 페이지로 Gnb를 공유하지 않았음 - 변경 후: DM 페이지와 커뮤니티 페이지를 `/` 경로 아래에 두어 Gnb를 공유하게 됨 * chore: eslint global에 JSX 명시 * feat: 팔로잉, 팔로워, 사용자 검색을 query params에 따라 조건부 렌더링 - 기존: `/followings`, `/followers`, `/user-search`에 각각 라우터가 등록되어있었음. 따라서 재렌더링하지 않아도 되는 부분까지 재렌더링해야했음 - 변경 후: `/dms?tab=`처럼 `tab` query params에 따라 조건부 렌더링 * feat: `Home` 페이지 - gnb, sidebar 위치 놓음
- Loading branch information
1 parent
c65435b
commit 829a90e
Showing
5 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import React from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
const DM = () => { | ||
return <div>DM</div>; | ||
return ( | ||
<> | ||
<Outlet /> | ||
</> | ||
); | ||
}; | ||
|
||
export default DM; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Followers from '@pages/Followers'; | ||
import Followings from '@pages/Followings'; | ||
import UserSearch from '@pages/UserSearch'; | ||
import React, { useEffect } from 'react'; | ||
import { | ||
createSearchParams, | ||
useNavigate, | ||
useSearchParams, | ||
} from 'react-router-dom'; | ||
|
||
const TabPanel: Record<string, JSX.Element> = { | ||
followers: <Followers />, | ||
followings: <Followings />, | ||
'user-search': <UserSearch />, | ||
}; | ||
|
||
const DEFAULT_TAB = 'followings'; | ||
|
||
const Friends = () => { | ||
const navigate = useNavigate(); | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
useEffect(() => { | ||
if (!((searchParams.get('tab') ?? '') in TabPanel)) | ||
navigate({ search: `?${createSearchParams([['tab', DEFAULT_TAB]])}` }); | ||
}); | ||
|
||
const renderTablPanel = (tab: string) => TabPanel[tab]; | ||
|
||
return ( | ||
<main className="flex flex-col"> | ||
<nav> | ||
<ul className="flex"> | ||
<li> | ||
<button onClick={() => setSearchParams({ tab: 'followings' })}> | ||
팔로잉 | ||
</button> | ||
</li> | ||
<li> | ||
<button onClick={() => setSearchParams({ tab: 'followers' })}> | ||
팔로워 | ||
</button> | ||
</li> | ||
<li> | ||
<button onClick={() => setSearchParams({ tab: 'user-search' })}> | ||
사용자 검색 | ||
</button> | ||
</li> | ||
</ul> | ||
</nav> | ||
<div className="content"> | ||
{renderTablPanel(searchParams.get('tab') ?? DEFAULT_TAB)} | ||
</div> | ||
</main> | ||
); | ||
}; | ||
|
||
export default Friends; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import React from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
const Home = () => { | ||
return <div></div>; | ||
return ( | ||
<div className="flex"> | ||
<div>gnb</div> | ||
<div>sidebar</div> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Home; |