App.js 2.06 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
  if (state !== false) {
Kim, Chaerin's avatar
Kim, Chaerin committed
13
    return <Redirect to={`/search?keyword=${search}`} />;
Kim, Chaerin's avatar
Kim, Chaerin committed
14
  }
Kim, Chaerin's avatar
Kim, Chaerin committed
15
16
17

  const handleChange = (e) => {
    setSearch(e.target.value);
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
18
  } //바뀌는 것이 있을때 이벤트 발생
Kim, Chaerin's avatar
Kim, Chaerin committed
19

Kim, Chaerin's avatar
Kim, Chaerin committed
20
  const handleSubmit = () => {
Kim, Chaerin's avatar
Kim, Chaerin committed
21
    setState(true);
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
22
  } //submit 버튼을 누르면 state 값을 true로 바뀐다
Kim, Chaerin's avatar
Kim, Chaerin committed
23
24

  return (
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
25
    <Container className="vh-100 d-flex justify-content-md-center align-items-center">
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
26
27
      <Col md={6} style={{ marginTop: 140 }}>
        <Nav className="justify-content-end" bg="#fff" variant="light" >
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
28
          {user ? <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
29
30
31
32
33
34
35
36
37
            : (
              <>
                <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
38
39
          <Image src={ohuh} />
        </Row>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
40
        <Row style={{ marginBottom: 500 }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
41
          <Form className="vw-100" onSubmit={handleSubmit}>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
42
            <InputGroup style={{ width: 560 }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
              <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
57
58
59
60
    </Container>
  );
}

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