송용우

Update Header Menu

...@@ -4,6 +4,7 @@ import './App.css'; ...@@ -4,6 +4,7 @@ import './App.css';
4 import LoginPage from './pages/LoginPage'; 4 import LoginPage from './pages/LoginPage';
5 import RegisterPage from './pages/RegisterPage'; 5 import RegisterPage from './pages/RegisterPage';
6 import HomePage from './pages/HomePage'; 6 import HomePage from './pages/HomePage';
7 +import SettingPage from './pages/SettingPage';
7 8
8 function App() { 9 function App() {
9 return ( 10 return (
...@@ -11,6 +12,7 @@ function App() { ...@@ -11,6 +12,7 @@ function App() {
11 <Route component={HomePage} path={['/@:username', '/']} exact /> 12 <Route component={HomePage} path={['/@:username', '/']} exact />
12 <Route component={LoginPage} path="/login" /> 13 <Route component={LoginPage} path="/login" />
13 <Route component={RegisterPage} path="/register" /> 14 <Route component={RegisterPage} path="/register" />
15 + <Route component={SettingPage} path="/setting" />
14 </> 16 </>
15 ); 17 );
16 } 18 }
......
1 +import React from 'react';
2 +import styled from 'styled-components';
3 +import { NavLink } from 'react-router-dom';
4 +
5 +const categories = [
6 + {
7 + name: 'home',
8 + text: '홈',
9 + },
10 + {
11 + name: 'setting',
12 + text: '설정',
13 + },
14 +];
15 +
16 +const CategoriesBlock = styled.div`
17 + display: flex;
18 + padding: 1rem;
19 + margin: 0 auto;
20 + @media screen and (max-width: 768px) {
21 + width: 100%;
22 + overflow-x: auto;
23 + }
24 +`;
25 +
26 +const Category = styled(NavLink)`
27 + font-size: 1.2rem;
28 + cursor: pointer;
29 + white-space: pre;
30 + text-decoration: none;
31 + color: inherit;
32 + padding-bottom: 0.25rem;
33 + &:hover {
34 + color: #495057;
35 + }
36 + & + & {
37 + margin-left: 2rem;
38 + }
39 + &.active {
40 + font-weight: 600;
41 + border-bottom: 2px solid #22b8cf;
42 + color: #22b8cf;
43 + &:hover {
44 + color: #3bc9db;
45 + }
46 + }
47 +`;
48 +
49 +const Categories = () => {
50 + return (
51 + <CategoriesBlock>
52 + {categories.map((c) => (
53 + <Category
54 + activeClassName="active"
55 + key={c.name}
56 + exact={c.name === 'home'}
57 + to={c.name === 'home' ? '/' : `/${c.name}`}
58 + >
59 + {c.text}
60 + </Category>
61 + ))}
62 + </CategoriesBlock>
63 + );
64 +};
65 +
66 +export default Categories;
...@@ -3,6 +3,7 @@ import styled from 'styled-components'; ...@@ -3,6 +3,7 @@ import styled from 'styled-components';
3 import Responsive from './Responsive'; 3 import Responsive from './Responsive';
4 import Button from './Button'; 4 import Button from './Button';
5 import { Link } from 'react-router-dom'; 5 import { Link } from 'react-router-dom';
6 +import Categories from './Categories';
6 7
7 const HeaderBlock = styled.div` 8 const HeaderBlock = styled.div`
8 position: fixed; 9 position: fixed;
...@@ -35,7 +36,7 @@ const UserInfo = styled.div` ...@@ -35,7 +36,7 @@ const UserInfo = styled.div`
35 margin-right: 1rem; 36 margin-right: 1rem;
36 `; 37 `;
37 38
38 -const Header = ({ user, onLogout }) => { 39 +const Header = ({ user, onLogout, category, onSelect }) => {
39 return ( 40 return (
40 <> 41 <>
41 <HeaderBlock> 42 <HeaderBlock>
...@@ -43,6 +44,11 @@ const Header = ({ user, onLogout }) => { ...@@ -43,6 +44,11 @@ const Header = ({ user, onLogout }) => {
43 <Link to="/" className="logo"> 44 <Link to="/" className="logo">
44 작심삼일 45 작심삼일
45 </Link> 46 </Link>
47 + <Categories
48 + category={category}
49 + onSelect={onSelect}
50 + className="right"
51 + />
46 {user ? ( 52 {user ? (
47 <div className="right"> 53 <div className="right">
48 <UserInfo>{user.username}</UserInfo> 54 <UserInfo>{user.username}</UserInfo>
......
...@@ -4,6 +4,7 @@ import Header from '../../components/common/Header'; ...@@ -4,6 +4,7 @@ import Header from '../../components/common/Header';
4 import { logout } from '../../modules/user'; 4 import { logout } from '../../modules/user';
5 const HeaderContainer = () => { 5 const HeaderContainer = () => {
6 const { user } = useSelector(({ user }) => ({ user: user.user })); 6 const { user } = useSelector(({ user }) => ({ user: user.user }));
7 +
7 const dispatch = useDispatch(); 8 const dispatch = useDispatch();
8 const onLogout = () => { 9 const onLogout = () => {
9 dispatch(logout()); 10 dispatch(logout());
......
1 -import axios from './axios'; 1 +import axios from 'axios';
2 const client = axios.create(); 2 const client = axios.create();
3 export default client; 3 export default client;
......
...@@ -6,7 +6,7 @@ const HomePage = () => { ...@@ -6,7 +6,7 @@ const HomePage = () => {
6 return ( 6 return (
7 <div> 7 <div>
8 <HeaderContainer /> 8 <HeaderContainer />
9 - <Button>test</Button> 9 + <Button>home</Button>
10 </div> 10 </div>
11 ); 11 );
12 }; 12 };
......
1 +import React from 'react';
2 +import HeaderContainer from '../containers/common/HeaderContainer';
3 +import Button from '../components/common/Button';
4 +
5 +const SettingPage = () => {
6 + return (
7 + <div>
8 + <HeaderContainer />
9 + <Button>setting</Button>
10 + </div>
11 + );
12 +};
13 +
14 +export default SettingPage;