App.js 7.09 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
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
114
115
116
117
118
119
120
121
122
123
    <>
      <style type="text/css">
        {`
                   @font-face {
                    font-family: 'Jal_Onuel';
                    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_20-10-21@1.0/Jal_Onuel.woff') format('woff');
                    font-weight: normal;
                    font-style: normal;
                }
                body{font-family:'Jal_Onuel'}
                

                Nav{
                  font-color: 'red';
                }
              
                `}
      </style>
      <Container className="vh-100 ">
        <Col xs={12} >
          <Nav className="justify-content-end" bg="#fff" variant="light" style={{}} >
            {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}
                />
                <InputGroup.Append>
                  <Button type='submit' variant="outline-secondary">검색</Button>
                </InputGroup.Append>
              </InputGroup>
            </Form>
          </Row>
          <div class="row mb-2">
            <div class="col-md-6">
              <div class="row g-0 border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
                <div class="col p-4 d-flex flex-column position-static">
                  <strong class="d-inline-block mb-2 text-info">인기관광지</strong>
                  <h3 class="mb-0">{recommend.name}</h3>
                  <Image variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={recommend.img} />
                  <p class="card-text mb-auto">{recommend.address}</p>
                  <Link to={`/place?name=${recommend.name}&src=${recommend.img}&address=${recommend.address}`} >
                    <Button variant="info"> {recommend.name} 자세히 살펴보기</Button>
                  </Link>
                </div>
                <div class="col-auto d-none d-lg-block">

                </div>
124
125
              </div>
            </div>
126
127
128
129
130
131
132
133
134
135
136
137
138
139
            <div class="col-md-6">
              <div class="row g-0 border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
                <div class="col p-4 d-flex flex-column position-static">
                  <strong class="d-inline-block mb-2 text-success">최근검색 관광지</strong>
                  <h3 class="mb-0">{latest.name}</h3>
                  <Image variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={latest.img} />
                  <p class="mb-auto">{latest.address}</p>
                  <Link to={`/place?name=${latest.name}&src=${latest.img}&address=${latest.address}`} >
                    <Button variant="info"> {latest.name} 자세히 살펴보기</Button>
                  </Link>
                </div>
                <div class="col-auto d-none d-lg-block">

                </div>
140
141
142
143
144
              </div>
            </div>
          </div>


145
          {/* <Row  xs={6}>
baesangjune's avatar
baesangjune committed
146
          <Col md={6} xs={12}>
baesangjune's avatar
수정    
baesangjune committed
147
            <h1 className=" d-flex justify-content-center" style={{ marginBottom: "7%" ,marginTop:"30%" }}>인기관광지</h1>
148
            <Card align="center" border="info" style={{ margin: "3%" }}>
baesangjune's avatar
baesangjune committed
149
              <Card.Header style={{  margin: "0",fontSize: '200%', fontWeight: 'bold' }} >{recommend.name}</Card.Header>
150
151
152
153
              <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>
154
                  <Link to={`/place?id=${1}&place=${recommend.name}`} >
baesangjune's avatar
.    
baesangjune committed
155
                  <Button variant="info"> {recommend.name} 자세히 살펴보기</Button>
156
                </Link>
157
158
159
160
              </Card.Body>
            </Card>
          </Col>

baesangjune's avatar
baesangjune committed
161
          <Col md={6} xs={12}>
baesangjune's avatar
수정    
baesangjune committed
162
            <h1 className=" d-flex justify-content-center" style={{ marginBottom: "7%",marginTop:"30%" }}>최근 검색관광지</h1>
baesangjune's avatar
baesangjune committed
163
164
            <Card align="center" border="info" style={{ margin: "3%" }} >
              <Card.Header style={{  margin: "0", fontSize: '200%', fontWeight: 'bold'}} bg="danger">{latest.name}</Card.Header>
165
166
167
168
              <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>
169
                <Link to={`/place?id=${1}&place=${latest.name}`} >
baesangjune's avatar
.    
baesangjune committed
170
                  <Button variant="info"> {latest.name} 자세히 살펴보기</Button>
171
                </Link>
172
173
174
              </Card.Body>
            </Card>
          </Col>
175
        </Row> */}
176
177
178
        </Col>
      </Container>
    </>
Kim, Chaerin's avatar
?    
Kim, Chaerin committed
179
180
181
  );
}

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