Place.js 3.33 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 (
baesangjune's avatar
baesangjune committed
34
35
36
37
38
39
40
41
42
    <>
    <style type="text/css">
        {`
                         .link{
                  color: #17a2b8;
                }
              
                `}
      </style>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
43
    <Container>
44
45

      <Link to="/"><Image style={{ margin: "1%" }} src={ohuh} /></Link>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
46
      <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
47
          <h1 class="h6 mb-0 text-white">{name}</h1>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
48
49
50
51
      </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
52
53
        <Row>
          <Col>
baesangjune's avatar
baesangjune committed
54
            <Image variant="top" style={{ padding: "5%", width: "100%", height: "100%" }} src={src} />
Kim, Chaerin's avatar
Kim, Chaerin committed
55
56
57
58
59
60
61
62
63
          </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
64

Kim, Chaerin's avatar
Kim, Chaerin committed
65
66
67
68
69
70
71
              <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
72
73

        <small class="d-block text-end mt-3">
baesangjune's avatar
baesangjune committed
74
          <a class="link" href={`https://www.google.com/search?q=${name}&tbm=isch`}>사진 더보러가기</a>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
75
76
77
78
79
        </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
80
        {Array.isArray(review.reviews) ? review.reviews.map((review) => {
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
81
82
83
84
85
          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>
baesangjune's avatar
baesangjune committed
86
                  <a class="link" href={review.link}>블로그로 이동</a>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
87
88
89
90
91
92
93
94
95
                </div>
                <span class="d-block">{review.summary}</span>
              </div>
            </div>
          )
        })
          : "리뷰가 없습니다."}


Kim, Chaerin's avatar
Kim, Chaerin committed
96

Kim, Chaerin's avatar
z    
Kim, Chaerin committed
97
        <small class="d-block text-end mt-3">
Kim, Chaerin's avatar
Kim, Chaerin committed
98
          <a href="#" onClick={getReview} >리뷰 더보기</a>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
99
100
        </small>
      </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
101
    </Container>
baesangjune's avatar
baesangjune committed
102
    </>
Kim, Chaerin's avatar
Kim, Chaerin committed
103
104
105
106
  );
}

export default Place;