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

Kim, Chaerin's avatar
Kim, Chaerin committed
9
function App() {
Kim, Chaerin's avatar
Kim, Chaerin committed
10
  const [state, setState] = useState(false);
Kim, Chaerin's avatar
Kim, Chaerin committed
11
  const [search, setSearch] = useState("");
baesangjune's avatar
baesangjune committed
12
13
  const [recommend, setRecommend] = useState([{ name: " ", address: " ", img: " " }]);
  const [latest, setLatest] = useState([{ name: " ", address: " ", img: " " }]);
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
14
  const user = isAuthenticated()
15
16
17
18
19

  useEffect(() => {
    getRecommend()
    getLatest()
  }, []);
Lee SeoYeon's avatar
0113    
Lee SeoYeon committed
20

21

Kim, Chaerin's avatar
Kim, Chaerin committed
22
  if (state !== false) {
Kim, Chaerin's avatar
Kim, Chaerin committed
23
    return <Redirect to={`/search?keyword=${search}`} />;
Kim, Chaerin's avatar
Kim, Chaerin committed
24
  }
Kim, Chaerin's avatar
Kim, Chaerin committed
25
26
27

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

Kim, Chaerin's avatar
Kim, Chaerin committed
30
  const handleSubmit = () => {
Kim, Chaerin's avatar
Kim, Chaerin committed
31
    setState(true);
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
32
  } //submit 버튼을 누르면 state 값을 true로 바뀐다
Kim, Chaerin's avatar
Kim, Chaerin committed
33

baesangjune's avatar
baesangjune committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  const getRecommend = () => {
    axios.get(`/api/app/recommend`)
      .then(res => {
        setRecommend(res.data)
      })
      .catch(err => {
        console.log("APP RECOMMEND ERROR", err)
      })
  }

  const getLatest = () => {
    axios.get(`/api/app/lastest`)
      .then(res => {
        setLatest(res.data)
      })
      .catch(err => {
        console.log("APP LATEST ERROR", err)
      })
52
53
54
  }


baesangjune's avatar
baesangjune committed
55

Kim, Chaerin's avatar
Kim, Chaerin committed
56
  return (
57
    <Container className="vh-100 ">
baesangjune's avatar
baesangjune committed
58
      <Col xs={12} >
59
        <Nav className="justify-content-end" bg="#fff" variant="light" style={{}} >
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
60
61
62
63
64
65
66
67
68
          {user ? <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link>
            : (
              <>
                <Nav.Link href="/signup">회원가입</Nav.Link>
                <Nav.Link href="/login">로그인</Nav.Link>
              </>
            )}
          <Nav.Link href='/bookmark'>북마크</Nav.Link>
        </Nav>
baesangjune's avatar
baesangjune committed
69
70
71
72
        <Row className="justify-content-center" md={2}>
          <Col  className="d-flex justify-content-center">
        <Image src={ohuh}  style={{ margin: "3%", marginTop : "3%" }} fluid />
          </Col>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
73
        </Row>
74
        <Row style={{ marginBottom: "5%" }}>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
75
          <Form className="vw-100" onSubmit={handleSubmit}>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
76
            <InputGroup >
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
77
78
79
80
81
82
83
84
85
86
87
88
89
              <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>
baesangjune's avatar
baesangjune committed
90
91
        <Row  xs={6}>
          <Col md={6} xs={12}>
92
            <h1 className=" d-flex justify-content-center" style={{ marginBottom: "7%" }}>인기관광지</h1>
93
            <Card align="center" border="info" style={{ margin: "3%" }}>
baesangjune's avatar
baesangjune committed
94
              <Card.Header style={{  margin: "0",fontSize: '200%', fontWeight: 'bold' }} >{recommend.name}</Card.Header>
95
96
97
98
              <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={recommend.img} />
              <Card.Body >
                <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
                  {recommend.address} </Card.Text>
99
                  <Link to={`/place?id=${1}&place=${recommend.name}`} >
100
                  <Button variant="info"> {recommend.name} 자세히 살펴보기</Button>
101
                </Link>
102
103
104
105
              </Card.Body>
            </Card>
          </Col>

baesangjune's avatar
baesangjune committed
106
          <Col md={6} xs={12}>
107
            <h1 className=" d-flex justify-content-center" style={{ marginBottom: "7%" }}>최근 검색관광지</h1>
baesangjune's avatar
baesangjune committed
108
109
            <Card align="center" border="info" style={{ margin: "3%" }} >
              <Card.Header style={{  margin: "0", fontSize: '200%', fontWeight: 'bold'}} bg="danger">{latest.name}</Card.Header>
110
111
112
113
              <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={latest.img} />
              <Card.Body >
                <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
                  {latest.address} </Card.Text>
114
                <Link to={`/place?id=${1}&place=${latest.name}`} >
115
                  <Button variant="info"> {latest.name} 자세히 살펴보기</Button>
116
                </Link>
117
118
119
120
              </Card.Body>
            </Card>
          </Col>
        </Row>
Kim, Chaerin's avatar
서연    
Kim, Chaerin committed
121
      </Col>
Kim, Chaerin's avatar
Kim, Chaerin committed
122
    </Container>
123
124


Kim, Chaerin's avatar
Kim, Chaerin committed
125
126
127
  );
}

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