App.js 5.25 KB
Newer Older
baesangjune's avatar
baesangjune committed
1
import React, { useState, useEffect } from 'react';
2
import { Link, Redirect } from 'react-router-dom';
baesangjune's avatar
baesangjune committed
3
import ohuh from '../ohuh.PNG';
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'
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
  const [recommend, setRecommend] = useState([{ name: " ", address: " ", img: " " }]);
  const [latest, setLatest] = useState([{ name: " ", address: " ", img: " " }]);
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
13

14
15
16
17
18

  useEffect(() => {
    getRecommend()
    getLatest()
  }, []);
Lee SeoYeon's avatar
0111    
Lee SeoYeon committed
19
  const user = isAuthenticated()
20

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

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

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

baesangjune's avatar
baesangjune committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  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)
      })
51
52
53
  }


baesangjune's avatar
baesangjune committed
54

Kim, Chaerin's avatar
?    
Kim, Chaerin committed
55
  return (
56
57
58
    <>
      <style type="text/css">
        {`
baesangjune's avatar
baesangjune committed
59
60
                         .nav-link{
                  color: #17a2b8;
61
62
63
64
65
66
                }
              
                `}
      </style>
      <Container className="vh-100 ">
        <Col xs={12} >
baesangjune's avatar
baesangjune committed
67
          <Nav className="justify-content-end" bg="#fff" variant="light" id="nav">
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
            {user ? <>
              <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link>
              <Nav.Link href='/bookmark'>북마크</Nav.Link>
            </>
              : (
                <>
                  <Nav.Link href="/signup">회원가입</Nav.Link>
                  <Nav.Link href="/login">로그인</Nav.Link>
                </>
              )}
          </Nav>
          <Row className="justify-content-center" md={2}>
            <Col className="d-flex justify-content-center">
              <Image src={ohuh} style={{ margin: "3%", marginTop: "3%" }} fluid />
            </Col>
          </Row>
          <Row style={{ marginBottom: "5%" }}>
            <Form className="vw-100" onSubmit={handleSubmit}>
              <InputGroup >
                <Form.Control
                  size="lg"
                  placeholder="검색어를 입력하세요."
                  aria-label="Large"
                  aria-describedby="inputGroup-sizing-sm"
                  onChange={handleChange}
                />
baesangjune's avatar
baesangjune committed
94
                <InputGroup.Append  >
95
96
97
98
99
                  <Button type='submit' variant="outline-secondary">검색</Button>
                </InputGroup.Append>
              </InputGroup>
            </Form>
          </Row>
baesangjune's avatar
baesangjune committed
100
101
102

          <Row xs={6}>
            <Col md={6} xs={12}>
baesangjune's avatar
baesangjune committed
103
              <Card border="info" style={{ margin: "2%" }}>
baesangjune's avatar
baesangjune committed
104
                <Card.Title style={{ margin: "0", paddingTop: "3%", fontSize: '200%', fontWeight: 'bold' }} >
Kim, Chaerin's avatar
last    
Kim, Chaerin committed
105
                  <Row style={{ fontSize: "60%", marginLeft: "7%" }}><strong className="border p-2 text-danger mb-2">인기관광지</strong></Row>
baesangjune's avatar
baesangjune committed
106
107
108
                  <Row style={{ fontSize: "100%", marginLeft: "8%" }}>{recommend.name}</Row></Card.Title>
                <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={recommend.img} />
                <Card.Body style={{ paddingTop: "0" }} >
baesangjune's avatar
baesangjune committed
109
                  <Card.Text style={{ margin: "0", overflow: 'auto', fontSize: '120%', width: '100%', height: "65px" }} >
baesangjune's avatar
baesangjune committed
110
                    {recommend.address} </Card.Text>
baesangjune's avatar
baesangjune committed
111
                    <Link to={`/place?name=${recommend.name}&src=${recommend.img}&address=${recommend.address}`} >
baesangjune's avatar
baesangjune committed
112
113
114
115
116
117
118
                    <Button variant="info"> {recommend.name} 자세히 살펴보기</Button>
                  </Link>
                </Card.Body>
              </Card>
            </Col>

            <Col md={6} xs={12}>
baesangjune's avatar
baesangjune committed
119
              <Card border="info" style={{ margin: "2%" }} >
baesangjune's avatar
baesangjune committed
120
                <Card.Title style={{ margin: "0", paddingTop: "3%", fontSize: '200%', fontWeight: 'bold' }} >
Kim, Chaerin's avatar
last    
Kim, Chaerin committed
121
                  <Row style={{ fontSize: "60%", marginLeft: "7%" }}><strong className="border p-2 text-success mb-2">최근 검색 관광지</strong></Row>
baesangjune's avatar
baesangjune committed
122
123
124
                  <Row style={{ fontSize: "100%", marginLeft: "8%" }}>{latest.name}</Row></Card.Title>
                <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={latest.img} />
                <Card.Body style={{ paddingTop: "0" }}>
baesangjune's avatar
baesangjune committed
125
                  <Card.Text style={{ margin: "0", overflow: 'auto', fontSize: '120%', width: '100%', height: "65px" }} >
baesangjune's avatar
baesangjune committed
126
                    {latest.address} </Card.Text>
baesangjune's avatar
baesangjune committed
127
                    <Link to={`/place?name=${latest.name}&src=${latest.img}&address=${latest.address}`} >
baesangjune's avatar
baesangjune committed
128
129
130
131
132
133
                    <Button variant="info"> {latest.name} 자세히 살펴보기</Button>
                  </Link>
                </Card.Body>
              </Card>
            </Col>
          </Row>
134
135
136
        </Col>
      </Container>
    </>
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
137
138
139
  );
}

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