Place.js 3.12 KB
Newer Older
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
1
/*global kakao*/
Kim, Chaerin's avatar
Kim, Chaerin committed
2
3
import axios from 'axios';
import React, { useEffect, useState } from 'react';
Kim, Chaerin's avatar
Kim, Chaerin committed
4
import { Container, Row, Image, Col } from 'react-bootstrap';
Kim, Chaerin's avatar
Kim, Chaerin committed
5
import queryString from 'query-string'
baesangjune's avatar
수정    
baesangjune committed
6
import { Link } from 'react-router-dom';
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
7
import ohuh from '../ohuh-sm.PNG';
Kim, Chaerin's avatar
Kim, Chaerin committed
8
import catchErrors from '../utils/catchErrors';
Kim, Chaerin's avatar
Kim, Chaerin committed
9
10

function Place(props) {
Kim, Chaerin's avatar
Kim, Chaerin committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  const [error, setError] = useState('')
  const [review, setReviews] = useState({ reviews: [], db: false, index: 0 })
  const { name, src, address } = queryString.parse(props.location.search)
  console.log(review)

  const getReview = async () => {
    try {
      setError('')
      const res = await axios({ url: `/api/review?keyword=${name}&index=${review.index}`, method: 'post', data: { db: review.db } })
      console.log("place res.data", res.data)
      setReviews({ reviews: [...review.reviews, ...res.data.review], db: res.data.db, index: res.data.index })
    } catch (error) {
      catchErrors(error, setError)
    }
Kim, Chaerin's avatar
Kim, Chaerin committed
25
26
  }

Kim, Chaerin's avatar
z    
Kim, Chaerin committed
27

Kim, Chaerin's avatar
Kim, Chaerin committed
28
  useEffect(() => {
Kim, Chaerin's avatar
Kim, Chaerin committed
29
30
31
32
33
    getReview();
  }, []);


  return (
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
34
    <Container>
35
36

      <Link to="/"><Image style={{ margin: "1%" }} src={ohuh} /></Link>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
37
      <div class="d-flex align-items-center p-3 my-3 text-white bg-info rounded shadow-sm">
Kim, Chaerin's avatar
Kim, Chaerin committed
38
          <h1 class="h6 mb-0 text-white">{name}</h1>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
39
40
41
42
      </div>

      <div class="my-3 p-3 bg-white rounded shadow-sm">
        <h6 class="border-bottom pb-2 mb-0">관광지 정보</h6>
Kim, Chaerin's avatar
Kim, Chaerin committed
43
44
45
46
47
48
49
50
51
52
53
54
        <Row>
          <Col>
            <Image variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={src} />
          </Col>
          <Col>
            <div class="d-flex text-muted pt-3">
              <p class="pb-3 mb-0 lh-sm border-bottom">
                <strong class="d-block text-gray-dark">관광지 이름</strong>
                {name}
              </p>
            </div>
            <div class="d-flex text-muted pt-3">
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
55

Kim, Chaerin's avatar
Kim, Chaerin committed
56
57
58
59
60
61
62
              <p class="pb-3 mb-0 lh-sm border-bottom">
                <strong class="d-block text-gray-dark">관광지 주소</strong>
                {address}
              </p>
            </div>
          </Col>
        </Row>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
63
64

        <small class="d-block text-end mt-3">
Kim, Chaerin's avatar
Kim, Chaerin committed
65
          <a href={`https://www.google.com/search?q=${name}&tbm=isch`}>사진 더보러가기</a>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
66
67
68
69
70
        </small>
      </div>

      <div class="my-3 p-3 bg-white rounded shadow-sm">
        <h6 class="border-bottom pb-2 mb-0">관광지 후기</h6>
Kim, Chaerin's avatar
Kim, Chaerin committed
71
        {Array.isArray(review.reviews) ? review.reviews.map((review) => {
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
          return (
            <div class="d-flex text-muted pt-3">
              <div class="pb-3 mb-0 small lh-sm border-bottom w-100">
                <div class="d-flex justify-content-between">
                  <strong class="text-gray-dark">{review.title}</strong>
                  <a href={review.link}>블로그로 이동</a>
                </div>
                <span class="d-block">{review.summary}</span>
              </div>
            </div>
          )
        })
          : "리뷰가 없습니다."}


Kim, Chaerin's avatar
Kim, Chaerin committed
87

Kim, Chaerin's avatar
z    
Kim, Chaerin committed
88
        <small class="d-block text-end mt-3">
Kim, Chaerin's avatar
Kim, Chaerin committed
89
          <a href="#" onClick={getReview} >리뷰 더보기</a>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
90
91
        </small>
      </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
92
93
94
95
96
    </Container>
  );
}

export default Place;