App.js 2.02 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
0113    
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
27
    setState(true);
  }

  return (
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
28
    <Container className="vh-100 d-flex justify-content-md-center align-items-center">
Lee SeoYeon's avatar
0113    
Lee SeoYeon committed
29
      <Col md={6} style={{marginTop:140}}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
30
31
32
        <Row style={{marginBottom:20}}>
          <Image src={ohuh} />
        </Row>
Lee SeoYeon's avatar
0113    
Lee SeoYeon committed
33
34
35
36
37
38
39
40
41
42
43
44
45
        <Row>
        <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>
        </Row>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
46
47
        <Row style={{marginBottom:500}}>
          <Form className="vw-100" onSubmit={handleSubmit}>
Lee SeoYeon's avatar
0113    
Lee SeoYeon committed
48
            <InputGroup style={{width:560}}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
              <Form.Control
                size="lg"
                placeholder="검색어를 입력하세요."
                aria-label="Large"
                aria-describedby="inputGroup-sizing-sm"
                onChange={handleChange}
              />
              <InputGroup.Append>
                <Button type='submit' variant="outline-secondary">검색</Button>
              </InputGroup.Append>
            </InputGroup>
          </Form>
        </Row>
      </Col>
Kim, Chaerin's avatar
Kim, Chaerin committed
63
64
65
66
    </Container>
  );
}

Lee SeoYeon's avatar
0113    
Lee SeoYeon committed
67
export default App;