|
1 | | -import React, { useState, useCallback } from 'react'; |
2 | | -import ProTypes from 'prop-types'; |
| 1 | +import React, { useCallback } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
3 | 3 | import Link from 'next/link'; |
4 | | -import { |
5 | | - Layout, Menu, Input, Row, Col, |
6 | | -} from 'antd'; |
7 | | -import styled, { createGlobalStyle } from 'styled-components'; |
| 4 | +import { Menu, Input, Row, Col } from 'antd'; |
| 5 | +import styled from 'styled-components'; |
8 | 6 | import { useSelector } from 'react-redux'; |
9 | | -import Router, { useRouter } from 'next/router'; |
| 7 | +import Router from 'next/router'; |
| 8 | + |
10 | 9 | import UserProfile from './UserProfile'; |
11 | 10 | 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 | | -`; |
29 | 13 | const SearchInput = styled(Input.Search)` |
30 | 14 | vertical-align: middle; |
31 | 15 | `; |
| 16 | + |
32 | 17 | const AppLayout = ({ children }) => { |
| 18 | + const [searchInput, onChangeSearchInput] = useInput(''); |
33 | 19 | const { me } = useSelector((state) => state.user); |
34 | | - const [searchInput, setSearchInput] = useState(''); |
35 | | - const onChangeSearchInput = useCallback((e) => { |
36 | | - setSearchInput(e.target.value); |
37 | | - }, [searchInput]); |
| 20 | + |
38 | 21 | const onSearch = useCallback(() => { |
39 | 22 | Router.push(`/hashtag/${searchInput}`); |
40 | 23 | }, [searchInput]); |
41 | | - const router = useRouter(); |
42 | 24 |
|
43 | 25 | return ( |
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> |
| 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> |
78 | 55 | ); |
79 | 56 | }; |
80 | 57 |
|
81 | 58 | AppLayout.propTypes = { |
82 | | - children: ProTypes.node.isRequired, |
| 59 | + children: PropTypes.node.isRequired, |
83 | 60 | }; |
84 | 61 |
|
85 | 62 | export default AppLayout; |
0 commit comments