Commit 2f7efa72 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

Merge remote-tracking branch 'origin/cherry' into lsy

parents c368c2c6 e08aede8
browser=none
\ No newline at end of file
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { Modal, Container, Row, Button, } from 'react-bootstrap';
function Place(props) {
const [reviews, setReviews] = useState()
const [db, setDb] = useState(false)
const getReview = () => {
axios({ url: `/api/review?keyword=${props.place.name}`, method: 'post', data: { db: db } })
.then(res => {
console.log("place res.data", res.data)
setReviews(res.data.review)
setDb(res.data.db)
console.log(db)
})
.catch(err => {
console.log(err)
})
}
useEffect(() => {
getReview();
}, [])
return (
<Modal {...props}
size="xl"
keyboard="true"
variant="backdrop.in"
aria-labelledby="example-modal-sizes-title-lg">
<Modal.Header closeButton>
<Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '40px' }}>
{props.place.name}
</Modal.Title>
</Modal.Header>
<Modal.Body className="show-grid">
<Container style={{ fontSize: '40px' }}>
{Array.isArray(reviews) ? reviews.map((review) => {
return (
<Row className="mt-4">
<a href={review.link}>{review.title}</a>
<div>{review.summary}</div>
<div>{review.content}</div>
</Row>
)
})
: "리뷰가 없습니다."}
</Container>
</Modal.Body>
<Modal.Footer>
<Button block onClick={props.onHide}>Close</Button>
</Modal.Footer>
</Modal>
);
}
export default Place;
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { Container, Row, Button, } from 'react-bootstrap';
import queryString from 'query-string'
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(() => {
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 (
<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>
);
}
export default Place;
...@@ -58,6 +58,7 @@ function Search(props) { ...@@ -58,6 +58,7 @@ function Search(props) {
setPagePlace(paginate(association, index, 4)) setPagePlace(paginate(association, index, 4))
} }
setEndPage(Math.floor((association.length / 4))) setEndPage(Math.floor((association.length / 4)))
console.log("7489309484839", endPage)
}, [association, index]) }, [association, index])
...@@ -161,7 +162,7 @@ function Search(props) { ...@@ -161,7 +162,7 @@ function Search(props) {
return ( return (
<Container > <Container >
<Link to="/" className="d-flex justify-content-center"><Image src={ohuh} /></Link> <Link to="/path" className="d-flex justify-content-center"><Image src={ohuh} /></Link>
<Row className="mb-2" className="d-flex justify-content-center"> <Row className="mb-2" className="d-flex justify-content-center">
<Form style={{ width: "90vw" }} onSubmit={handleSubmit}> <Form style={{ width: "90vw" }} onSubmit={handleSubmit}>
<InputGroup size="lg"> <InputGroup size="lg">
...@@ -196,22 +197,17 @@ function Search(props) { ...@@ -196,22 +197,17 @@ function Search(props) {
</Button> : null} </Button> : null}
</Card.Title> </Card.Title>
<Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={place.img} /> <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={place.img} />
<Card.Body > <Card.Body>
<Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} > <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
{place.address} </Card.Text> {place.address} </Card.Text>
<Button variant="info" onClick={() => { <Link to={`/place?id=${index}&place=${place.name}`} >
const showArr = [false, false, false, false] <Button variant="primary"> {place.name} 자세히 살펴보기</Button>
showArr[index] = true </Link>
setShowSet(showArr)
}}>{place.name} 자세히 살펴보기</Button>
<Place place={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} />
</Card.Body> </Card.Body>
</Card> </Card>
</Col> </Col>
) )
})} })}
</Row> </Row>
<Row className="mt-2 d-flex justify-content-center"> <Row className="mt-2 d-flex justify-content-center">
<Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations> <Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations>
......
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
Route, Route,
Redirect, Redirect,
} from "react-router-dom"; } from "react-router-dom";
import Place from './Pages/Place';
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
...@@ -22,6 +23,7 @@ ReactDOM.render( ...@@ -22,6 +23,7 @@ ReactDOM.render(
<Switch> <Switch>
<Route exact path="/" component={App} /> <Route exact path="/" component={App} />
<Route path="/search" component={Search} /> <Route path="/search" component={Search} />
<Route path="/place" component={Place} />
<Route path='/signup' component={Signup}/> <Route path='/signup' component={Signup}/>
<Route path='/login' component={Login} /> <Route path='/login' component={Login} />
<PrivateRoute path='/bookmark'><Bookmark/></PrivateRoute> <PrivateRoute path='/bookmark'><Bookmark/></PrivateRoute>
......
...@@ -2,7 +2,6 @@ import Places from '../models/Place.js' ...@@ -2,7 +2,6 @@ import Places from '../models/Place.js'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import fs from 'fs' import fs from 'fs'
import axios from 'axios'; import axios from 'axios';
import { nextTick } from 'process';
const searchPlace = async (req, res, next,) => { const searchPlace = async (req, res, next,) => {
......
...@@ -2,13 +2,14 @@ import Review from '../models/Review.js' ...@@ -2,13 +2,14 @@ import Review from '../models/Review.js'
import cheerio from "cheerio"; import cheerio from "cheerio";
import axios from 'axios'; import axios from 'axios';
const search = async (req, res, next) => { const search = async (req, res) => {
console.log(req.reviews, "1")
try { try {
for (let j = 1; j < 2; j++) {
let reviews = [] let reviews = []
// console.log(req.reviews, "제발")/ console.log(req.reviews, "제발")
let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site%3Atistory.com&page_no=" + j
let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + `+site%3Atistory.com&start=${Number(req.query.index) * 10}`
console.log(url)
let response1 = await axios.get(url) let response1 = await axios.get(url)
let $1 = cheerio.load(response1.data); let $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) { $1('.kCrYT').each(async function (i) {
...@@ -24,28 +25,21 @@ const search = async (req, res, next) => { ...@@ -24,28 +25,21 @@ const search = async (req, res, next) => {
reviews = reviews.filter(e => e) reviews = reviews.filter(e => e)
} }
}) })
reviews.forEach((review, i) => { // reviews.forEach(async (review, i) => {
Review.findOne({ link: review.link }, async function (err, reviewss) { // await Review.updateOne({ link: review.link }, { $push: { bookmark: req.query.keyword } })
console.log("4") // const reviewss = await Review.findOne({ link: review.link })
// if (!reviewss) {
if (err) { return res.status(404).send({ error: err }) } // // reviews["keyword"] = [req.query.keyword]
if (reviewss) { let newReviews = []
reviewss.keyword = [...reviewss.keyword, req.query.keyword] newReviews = [...newReviews, ...reviews]
reviewss.save() // await new Review(review).save()
} // }
if (!reviewss) { // })
reviews["keyword"] = [req.query.keyword] // console.log(req.reviews, "걸러낸 리뷰즈입니다")
let Reviews = await new Review(review).save() // const a = await Promise.all(newReviews)
// console.log(Reviews,"1") // console.log(a, "2")
req.reviews.push(Reviews) console.log(req.query.index, "인덱스ㅡㅡ")
} res.status(200).send({ review: newReviews, db: true, index: Number(req.query.index) + 1 })
})
})
}
const a = await Promise.all(req.reviews)
console.log(a, "2")
res.status(200).send({ review: a, db: true })
} catch (error) { } catch (error) {
console.log("6") console.log("6")
console.log(error) console.log(error)
...@@ -53,22 +47,21 @@ const search = async (req, res, next) => { ...@@ -53,22 +47,21 @@ const search = async (req, res, next) => {
} }
const find = (req, res, next) => { const find = async(req, res, next) => {
console.log("7", req.query.keyword) console.log("7", req.query)
const keyword = req.query.keyword const keyword = req.query.keyword
res.send("dkssud") if (req.body.db) {
// if (req.body.db) { next()
// next() }
// } await Review.find({ keyword: keyword }, function (err, reviews) {
// Review.find({ keyword: keyword }, function (err, reviews) { req.reviews = []
// req.reviews = [] if (reviews) {
// if (reviews) { if (reviews.length > 5) {
// if (reviews.length > 10) { res.status(200).send({ review: reviews, db: true, message: "제발용" })
// res.status(200).send({ review: reviews, db: true }) }
// } req.reviews = reviews
// req.reviews = reviews }
// } next()
// next() })
// })
} }
export default { search, find } export default { search, find }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment