App.js 3.96 KB
Newer Older
baesangjune's avatar
baesangjune committed
1
import React, { useState, useEffect } from 'react';
baesangjune's avatar
baesangjune committed
2
import { Redirect } from 'react-router-dom';
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
3
import ohuh from '../ohuh.PNG';
baesangjune's avatar
baesangjune committed
4
5
6
import { Container, Row, Form, Image, InputGroup, Button, Col, Card } from 'react-bootstrap';
import axios from 'axios';
import Place from '../Components/Place';
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
7
8
9
10

function App() {
  const [state, setState] = useState(false);
  const [search, setSearch] = useState("");
baesangjune's avatar
baesangjune committed
11
12
13
  const [show, setShow] = useState(false);
  const [recommend, setRecommend] = useState([{ name: " ", address: " ", img: " " }]);
  const [latest, setLatest] = useState([{ name: " ", address: " ", img: " " }]);
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
14
15

  if (state !== false) {
Kim, Chaerin's avatar
Kim, Chaerin committed
16
    return <Redirect to={`/search?keyword=${search}`} />;
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
17
18
  }

baesangjune's avatar
baesangjune committed
19
  
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
20
21
22
23
24
25
26
27
  const handleChange = (e) => {
    setSearch(e.target.value);
  }

  const handleSubmit = () => {
    setState(true);
  }

baesangjune's avatar
baesangjune committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  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)
      })
    }
    
    
    useEffect(() => {
      getRecommend()
      getLatest()
    }, []);

Kim, Chaerin's avatar
?    
Kim, Chaerin committed
54
  return (
baesangjune's avatar
baesangjune committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    <>
      <Container className="vh-100 ">
        <Col md={12} >
          <Row className="justify-content-center" style={{ margin: "8%" }}>
            <Image src={ohuh} />
          </Row>
          <Row style={{ marginBottom: "10%"}}>
            <Form className="vw-100" onSubmit={handleSubmit}>
              <InputGroup>
                <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>
          <Row>
            <Col md={6}  >
              <h1>인기관광지</h1>
              <Card align="center" border="info" style={{ margin: "3%" }}>
                <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{recommend.name}</Card.Title>
                <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>
                  <Button variant="primary" onClick={() => {
                    setShow(true)
                  }}>{recommend.name} 자세히 살펴보기</Button>
                  <Place place={recommend} show={show} onHide={() => setShow(false)} />
                </Card.Body>
              </Card>
            </Col>

            <Col md={6} >
              <h1>최근 검색관광지</h1>
              <Card align="center" border="info" style={{ margin: "3%" }}>
                <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{latest.name}</Card.Title>
                <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>
                  <Button variant="primary" onClick={() => {
                    setShow(true)
                  }}>{latest.name} 자세히 살펴보기</Button>
                  <Place place={latest} show={show} onHide={() => setShow(false)} />
                </Card.Body>
              </Card>
            </Col>
          </Row>
        </Col>
      </Container>

    </>
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
114
115
116
117
  );
}

export default App;