|
1 | | -import React, { useCallback } from 'react'; |
2 | | -import PropTypes from 'prop-types'; |
| 1 | +import React, { useState, useCallback } from 'react'; |
| 2 | +import ProTypes from 'prop-types'; |
3 | 3 | import Link from 'next/link'; |
4 | | -import { Menu, Input, Row, Col } from 'antd'; |
5 | | -import styled from 'styled-components'; |
| 4 | +import { |
| 5 | + Layout, Menu, Input, Row, Col, |
| 6 | +} from 'antd'; |
| 7 | +import styled, { createGlobalStyle } from 'styled-components'; |
6 | 8 | import { useSelector } from 'react-redux'; |
7 | | -import Router from 'next/router'; |
8 | | - |
| 9 | +import Router, { useRouter } from 'next/router'; |
9 | 10 | import UserProfile from './UserProfile'; |
10 | 11 | import LoginForm from './LoginForm'; |
11 | | -import useInput from '../hooks/useInput'; |
12 | 12 |
|
| 13 | +const { Header, Content } = Layout; |
| 14 | +const Global = createGlobalStyle` |
| 15 | + .ant-row { |
| 16 | + margin-left: 0 !important; |
| 17 | + margin-right: 0 !important; |
| 18 | + } |
| 19 | + .ant-col:first-child { |
| 20 | + margin-left: 0 !important; |
| 21 | + } |
| 22 | + .ant-col:last-child { |
| 23 | + margin-right: 0 !important; |
| 24 | + } |
| 25 | + .ant-form-item-explain-error { |
| 26 | + font-size: 11px; |
| 27 | + } |
| 28 | +`; |
13 | 29 | const SearchInput = styled(Input.Search)` |
14 | 30 | vertical-align: middle; |
15 | 31 | `; |
16 | | - |
17 | 32 | const AppLayout = ({ children }) => { |
18 | | - const [searchInput, onChangeSearchInput] = useInput(''); |
19 | 33 | const { me } = useSelector((state) => state.user); |
20 | | - |
| 34 | + const [searchInput, setSearchInput] = useState(''); |
| 35 | + const onChangeSearchInput = useCallback((e) => { |
| 36 | + setSearchInput(e.target.value); |
| 37 | + }, [searchInput]); |
21 | 38 | const onSearch = useCallback(() => { |
22 | 39 | Router.push(`/hashtag/${searchInput}`); |
23 | 40 | }, [searchInput]); |
| 41 | + const router = useRouter(); |
24 | 42 |
|
25 | 43 | return ( |
26 | | - <div> |
27 | | - <Menu mode="horizontal"> |
28 | | - <Menu.Item> |
29 | | - <Link href="/"><a>노드버드</a></Link> |
30 | | - </Menu.Item> |
31 | | - <Menu.Item> |
32 | | - <Link href="/profile"><a>프로필</a></Link> |
33 | | - </Menu.Item> |
34 | | - <Menu.Item> |
35 | | - <SearchInput |
36 | | - enterButton |
37 | | - value={searchInput} |
38 | | - onChange={onChangeSearchInput} |
39 | | - onSearch={onSearch} |
40 | | - /> |
41 | | - </Menu.Item> |
42 | | - </Menu> |
43 | | - <Row gutter={8}> |
44 | | - <Col xs={24} md={6}> |
45 | | - {me ? <UserProfile /> : <LoginForm />} |
46 | | - </Col> |
47 | | - <Col xs={24} md={12}> |
48 | | - {children} |
49 | | - </Col> |
50 | | - <Col xs={24} md={6}> |
51 | | - <a href="https://www.zerocho.com" target="_blank" rel="noreferrer noopener">Made by ZeroCho</a> |
52 | | - </Col> |
53 | | - </Row> |
54 | | - </div> |
| 44 | + <Layout className="layout"> |
| 45 | + <Global /> |
| 46 | + <Header style={{ position: 'fixed', zIndex: 1, width: '100%' }}> |
| 47 | + <Menu theme="dark" mode="horizontal" defaultSelectedKeys={[router.pathname]}> |
| 48 | + <Menu.Item key="/"> |
| 49 | + <Link href="/"><a>노드버드</a></Link> |
| 50 | + </Menu.Item> |
| 51 | + <Menu.Item key="/profile"> |
| 52 | + <Link href="/profile"><a>프로필</a></Link> |
| 53 | + </Menu.Item> |
| 54 | + <Menu.Item key="/search"> |
| 55 | + <SearchInput |
| 56 | + enterButton |
| 57 | + value={searchInput} |
| 58 | + onChange={onChangeSearchInput} |
| 59 | + onSearch={onSearch} |
| 60 | + /> |
| 61 | + </Menu.Item> |
| 62 | + </Menu> |
| 63 | + </Header> |
| 64 | + <Content style={{ padding: '0 50px', marginTop: 64 }}> |
| 65 | + <div style={{ minHeight: '400px', padding: '24px', backgroundColor: '#FFF' }}> |
| 66 | + {/* gutter 컬럼 사이의 간격 */} |
| 67 | + <Row gutter={12}> |
| 68 | + <Col xs={24} sm={24} md={8} lg={4} style={{ paddingTop: '12px' }}> |
| 69 | + {me ? <UserProfile /> : <LoginForm />} |
| 70 | + </Col> |
| 71 | + <Col xs={24} sm={24} md={16} lg={20} style={{ paddingTop: '12px' }}> |
| 72 | + {children} |
| 73 | + </Col> |
| 74 | + </Row> |
| 75 | + </div> |
| 76 | + </Content> |
| 77 | + </Layout> |
55 | 78 | ); |
56 | 79 | }; |
57 | 80 |
|
58 | 81 | AppLayout.propTypes = { |
59 | | - children: PropTypes.node.isRequired, |
| 82 | + children: ProTypes.node.isRequired, |
60 | 83 | }; |
61 | 84 |
|
62 | 85 | export default AppLayout; |
0 commit comments