App.js 1.97 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
2
import React, { useEffect, useState } from 'react';
import { Link, Redirect } from 'react-router-dom';
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
3
4
5
import ohuh from './ohuh.PNG'
import { Container, Row, Form, Image, InputGroup, Button, Col, FormControl, Navbar, Nav } from 'react-bootstrap';
import { handleLogout, isAuthenticated } from './utils/auth.js'
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
6

Kim, Chaerin's avatar
Kim, Chaerin committed
7
function App() {
Kim, Chaerin's avatar
Kim, Chaerin committed
8
  const [state, setState] = useState(false);
Kim, Chaerin's avatar
Kim, Chaerin committed
9
  const [search, setSearch] = useState("");
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
10
  const user = isAuthenticated()
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
11
  
Kim, Chaerin's avatar
Kim, Chaerin committed
12
13
14
15
16
17
  if (state !== false) {
    return <Redirect to={{
      pathname: `/search/${search}`,
      state: { id: search },
    }} />;
  }
Kim, Chaerin's avatar
Kim, Chaerin committed
18
19
20
21
22

  const handleChange = (e) => {
    setSearch(e.target.value);
  }

Kim, Chaerin's avatar
Kim, Chaerin committed
23
  const handleSubmit = () => {
Kim, Chaerin's avatar
Kim, Chaerin committed
24
25
26
    setState(true);
  }

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
27

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
28

Kim, Chaerin's avatar
Kim, Chaerin committed
29
  return (
Kim, Chaerin's avatar
Kim, Chaerin committed
30
31
    <Container className="vh-100">
      <Row className="d-flex justify-content-md-center">
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
32
33
34
        <Col md={6} className="mt-5">
          <Image src={ohuh} fluid />
        </Col>
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
35
36
37
38
39
40
41
42
43
44
45
46
47
        <Col md={9} className='mr-6'>
          <Navbar bg="#fff" variant="light">
            <Nav className="mr-auto">
              {user ? <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link>
                : (
                  <>
                    <Nav.Link href="/signup">회원가입</Nav.Link>
                    <Nav.Link href="/login">로그인</Nav.Link>
                  </>
                )}
            </Nav>
          </Navbar>
        </Col>
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
48
        <Col lg={{ span: 10, offset: 1 }} > 
Lee SeoYeon's avatar
..    
Lee SeoYeon committed
49
          <InputGroup size="lg" lg={6} xs={4} fluid>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
50
51
            <FormControl
              className="d-flex justify-content-lg-center"
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
52
53
54
55
56
57
              placeholder="검색어를 입력하세요."
              aria-label="Large"
              aria-describedby="inputGroup-sizing-sm"
              onChange={handleChange}
            />
            <InputGroup.Append>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
58
              <Button variant="outline-secondary" onClick={handleSubmit}>검색</Button>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
59
60
            </InputGroup.Append>
          </InputGroup>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
61
        </Col>
Kim, Chaerin's avatar
Kim, Chaerin committed
62
63
      </Row>
    </Container>
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
64

Kim, Chaerin's avatar
Kim, Chaerin committed
65
66
67
  );
}

Kim, Chaerin's avatar
?    
Kim, Chaerin committed
68
export default App;