Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/layout #9 헤더, 네비바 설정 #11

Merged
merged 5 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions src/App.css

This file was deleted.

41 changes: 23 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
import { PATH } from './constants/path'
import { createBrowserRouter, RouterProvider } from 'react-router-dom'

import CreatePlaylist from './pages/CreatePlaylist'
import EditProfile from './pages/EditProfile'
import Follow from './pages/Follow'
import Login from './pages/Login'
import Home from './pages/Home'
import CreatePlaylistPage from './pages/CreatePlaylistPage'
import EditProfilePage from './pages/EditProfilePage'
import FollowPage from './pages/FollowPage'
import LoginPage from './pages/LoginPage'
import Page404 from './pages/Page404'
import Playlist from './pages/Playlist'
import Profile from './pages/Profile'
import Search from './pages/Search'
import PlaylistPage from './pages/PlaylistPage'
import ProfilePage from './pages/ProfilePage'
import SearchPage from './pages/SearchPage'
import RootLayout from './layout/Root'
import ChatPage from './pages/ChatPage'
import HomePage from './pages/HomePage'

const router = createBrowserRouter([
{
path: '/',
element: <Home />,
path: PATH.HOME,
element: <RootLayout />,
errorElement: <Page404 />,
children: [
{ path: '/login', element: <Login /> },
{ path: '/search', element: <Search /> },
{ path: '/playlist', element: <Playlist /> },
{ path: '/createplaylist', element: <CreatePlaylist /> },
{ index: true, element: <HomePage /> },
{ path: PATH.LOGIN, element: <LoginPage /> },
{ path: PATH.SEARCH, element: <SearchPage /> },
{ path: PATH.PLAYLIST, element: <PlaylistPage /> },
{ path: PATH.CREATEPLAYLIST, element: <CreatePlaylistPage /> },
{
path: '/profile',
element: <Profile />,
path: PATH.PROFILE,
element: <ProfilePage />,
children: [
{ path: 'editprofile', element: <EditProfile /> },
{ path: 'follow', element: <Follow /> },
{ path: PATH.EDITPROFILE, element: <EditProfilePage /> },
{ path: PATH.FOLLOW, element: <FollowPage /> },
],
},
{ path: PATH.CHAT, element: <ChatPage /> },
],
},
])
Expand Down
30 changes: 30 additions & 0 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import styled from '@emotion/styled'
import { useNavigate } from 'react-router-dom'

interface HeaderProps {
onBack?: () => void
}

const Header: React.FC<HeaderProps> = ({ onBack }) => {
const navigate = useNavigate()

const handleBack = () => {
if (onBack) {
onBack()
} else {
navigate(-1)
}
}

return (
<StyledContainer>
<button onClick={handleBack}>BACK</button>
</StyledContainer>
)
}

export default Header

const StyledContainer = styled.div`
border: 1px solid black;
`
37 changes: 37 additions & 0 deletions src/components/layout/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styled from '@emotion/styled'
import { NavLink } from 'react-router-dom'
import { PATH } from '../../constants/path'

const Navbar = () => {
const menu = [
{ path: PATH.HOME, title: 'HOME' },
{ path: PATH.SEARCH, title: 'SEARCH' },
{ path: PATH.CREATEPLAYLIST, title: 'CREATE PLAYLIST' },
{ path: PATH.CHAT, title: 'CHAT' },
{ path: PATH.PROFILE, title: 'PROFILE' },
]

return (
<nav>
<StyledMenuContainer>
{menu.map(({ path, title }) => (
<StyledMenuItem key={title}>
<NavLink to={path}>{title}</NavLink>
</StyledMenuItem>
))}
</StyledMenuContainer>
</nav>
)
}

export default Navbar

const StyledMenuContainer = styled.div`
display: flex;
margin-top: 20px;
border: 1px solid black;
`

const StyledMenuItem = styled.div`
margin: 15px;
`
12 changes: 12 additions & 0 deletions src/constants/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const PATH = {
HOME: '/',
SEARCH: '/search',
PAGE404: '*',
LOGIN: '/login',
PLAYLIST: '/playlist',
CREATEPLAYLIST: '/createplaylist',
PROFILE: '/profile',
EDITPROFILE: 'editprofile',
FOLLOW: 'follow',
CHAT: '/chat',
}
28 changes: 28 additions & 0 deletions src/layout/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import styled from '@emotion/styled'
import { Outlet } from 'react-router-dom'
import Navbar from '../components/layout/Navbar'
import Header from '../components/layout/Header'

const RootLayout = () => (
<StyledContainer>
<Header />
<Outlet />
<Navbar />
</StyledContainer>
)

const StyledContainer = styled.div`
sjgaru-dev marked this conversation as resolved.
Show resolved Hide resolved
min-width: 500px;
min-height: 700px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
sjgaru-dev marked this conversation as resolved.
Show resolved Hide resolved
border: 1px solid black;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
`

export default RootLayout
5 changes: 5 additions & 0 deletions src/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const ChatPage = () => {
return <div>Chat</div>
}
sjgaru-dev marked this conversation as resolved.
Show resolved Hide resolved

export default ChatPage
5 changes: 0 additions & 5 deletions src/pages/CreatePlaylist.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/CreatePlaylistPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const CreatePlaylistPage = () => {
return <div>CreatePlaylist</div>
}

export default CreatePlaylistPage
5 changes: 0 additions & 5 deletions src/pages/EditProfile.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/EditProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const EditProfilePage = () => {
return <div>EditProfile</div>
}

export default EditProfilePage
5 changes: 0 additions & 5 deletions src/pages/Follow.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/FollowPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const FollowPage = () => {
return <div>Follow</div>
}

export default FollowPage
12 changes: 0 additions & 12 deletions src/pages/Home.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const HomePage = () => {
return <div>Home</div>
}

export default HomePage
5 changes: 0 additions & 5 deletions src/pages/Login.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const LoginPage = () => {
return <div>Login</div>
}

export default LoginPage
5 changes: 0 additions & 5 deletions src/pages/Playlist.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/PlaylistPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const PlaylistPage = () => {
return <div>Playlist</div>
}

export default PlaylistPage
5 changes: 0 additions & 5 deletions src/pages/Profile.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const ProfilePage = () => {
return <div>Profile</div>
}

export default ProfilePage
5 changes: 0 additions & 5 deletions src/pages/Search.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/pages/SearchPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SearchPage = () => {
return <div>Search</div>
}

export default SearchPage