App.js 1.99 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
.    
Lee SeoYeon committed
29
30
      <Col md={6} style={{ marginTop: 140 }}>
        <Nav className="justify-content-end" bg="#fff" variant="light" >
31
          {user ? <Nav.Links={() => handleLogout()}>로그아웃</Nav.Link>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
32
33
34
35
36
37
38
39
40
            : (
              <>
                <Nav.Link href="/signup">회원가입</Nav.Link>
                <Nav.Link href="/login">로그인</Nav.Link>
              </>
            )}
          <Nav.Link href='/bookmark'>북마크</Nav.Link>
        </Nav>
        <Row style={{ marginBottom: 20 }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
41
42
          <Image src={ohuh} />
        </Row>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
43
        <Row style={{ marginBottom: 500 }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
44
          <Form className="vw-100" onSubmit={handleSubmit}>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
45
            <InputGroup style={{ width: 560 }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
              <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
60
61
62
63
    </Container>
  );
}

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