Place.js 6.07 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
z    
Kim, Chaerin committed
4
import { Container, Row, Button, Image, } from 'react-bootstrap';
Kim, Chaerin's avatar
Kim, Chaerin committed
5
import queryString from 'query-string'
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
6
import { Link } from 'react-bootstrap-icons';
baesangjune's avatar
baesangjune committed
7
import ohuh from '../ohuh-sm.PNG';
Kim, Chaerin's avatar
Kim, Chaerin committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

function Place(props) {
  console.log(props)
  const [db, setDb] = useState(false)
  const [index, setIndex] = useState(0)
  const [reviews, setReviews] = useState([])
  const place = queryString.parse(props.location.search).place

  const getReview = (index) => {
    console.log(index, "dlseprtm")
    axios({ url: `/api/review?keyword=${place}&index=${index}`, method: 'post', data: { db: db } })
      .then(res => {
        console.log("place res.data", res.data)
        setReviews([...reviews, ...res.data.review])
        setDb(res.data.db)
        setIndex(res.data.index)
      })
      .then(() => {
        console.log(index, "인텍스", db)
      })
      .catch(err => {
        console.log(err)
      })
  }

  useEffect(() => {
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    // const script = document.createElement("script");
    // script.async = true;
    // script.src =
    //   "https://dapi.kakao.com/v2/maps/sdk.js?appkey=908d6cabedae3bbac126305e53137d0d&autoload=false";
    // document.head.appendChild(script);

    // script.onload = () => {
    //   kakao.maps.load(() => {
    //     let container = document.getElementById("Mymap");
    //     let options = {
    //       center: new kakao.maps.LatLng(37.506502, 127.053617),
    //       level: 7
    //     };

    //     const map = new window.kakao.maps.Map(container, options);

    //   });
    // }
Kim, Chaerin's avatar
Kim, Chaerin committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    getReview();
    window.addEventListener("scroll", infiniteScroll);
    return () => { window.removeEventListener("scroll", infiniteScroll); }
  }, []);

  // useEffect(() => {
  //   getReview();

  // }, [index])

  const infiniteScroll = () => {
    const { documentElement, body } = document;
    const scrollHeight = Math.max(documentElement.scrollHeight, body.scrollHeight);
    const scrollTop = Math.max(documentElement.scrollTop, body.scrollTop);
    const clientHeight = documentElement.clientHeight;
    if (scrollTop + clientHeight >= scrollHeight) {
      // setIndex(index + 1)
      getReview(index + 1);
      console.log("더불러", index + 1)
    }
    console.log(scrollHeight, scrollTop, clientHeight)
  }

  return (
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
76
    <Container>
77
      <Link to="/" className="d-flex justify-content-center"><Image style={{ margin: "1%" }} src={ohuh} /></Link>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
78
79
80
81
82
83
84
85
      <div class="d-flex align-items-center p-3 my-3 text-white bg-info rounded shadow-sm">
        <div >
          <h1 class="h6 mb-0 text-white">{place}</h1>
        </div>
      </div>

      <div class="my-3 p-3 bg-white rounded shadow-sm">
        <h6 class="border-bottom pb-2 mb-0">관광지 정보</h6>
86
        {/* <MapContents id="Mymap"></MapContents> */}
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
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
124
125
126
127
128
129
130
131
132
133
134
135
136
        {/* <div class="d-flex text-muted pt-3">
          
          <p class="pb-3 mb-0 small lh-sm border-bottom">
            <strong class="d-block text-gray-dark">@username</strong>
        Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
      </p>
        </div>
        <div class="d-flex text-muted pt-3">
          <svg class="bd-placeholder-img flex-shrink-0 me-2 rounded" width="32" height="32" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 32x32" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#e83e8c" /><text x="50%" y="50%" fill="#e83e8c" dy=".3em">32x32</text></svg>

          <p class="pb-3 mb-0 small lh-sm border-bottom">
            <strong class="d-block text-gray-dark">@username</strong>
        Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
      </p>
        </div>
        <div class="d-flex text-muted pt-3">
          <svg class="bd-placeholder-img flex-shrink-0 me-2 rounded" width="32" height="32" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 32x32" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#6f42c1" /><text x="50%" y="50%" fill="#6f42c1" dy=".3em">32x32</text></svg>

          <p class="pb-3 mb-0 small lh-sm border-bottom">
            <strong class="d-block text-gray-dark">@username</strong>
        Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
      </p>
        </div> */}
        <small class="d-block text-end mt-3">
          <a href={`https://www.google.com/search?q=${place}&tbm=isch`}>사진 더보러가기</a>
        </small>
      </div>

      <div class="my-3 p-3 bg-white rounded shadow-sm">
        <h6 class="border-bottom pb-2 mb-0">관광지 후기</h6>
        {Array.isArray(reviews) ? reviews.map((review, index) => {
          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>
          )
        })
          : "리뷰가 없습니다."}


        <small class="d-block text-end mt-3">
          <a href="#">리뷰 더보기</a>
        </small>
      </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
137
    </Container>
Kim, Chaerin's avatar
z    
Kim, Chaerin committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151

    // <Container {...props}>
    //   {place}
    //   {Array.isArray(reviews) ? reviews.map((review, index) => {
    //     return (
    //       <Row className="mt-4">
    //         <a href={review.link}>{review.title}</a>
    //         <div>{review.summary}</div>
    //         <div>{review.content}</div>
    //       </Row>
    //     )
    //   })
    //     : "리뷰가 없습니다."}
    // </Container>
Kim, Chaerin's avatar
Kim, Chaerin committed
152
153
154
155
  );
}

export default Place;