Commit bd46f33f authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

place 페이지 변환

parent b62079ad
[{"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js":"1","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js":"2","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\index.js":"3","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Place.js":"4","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Paginations.js":"5","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\App.js":"6"},{"size":362,"mtime":1608689675665,"results":"7","hashOfConfig":"8"},{"size":7987,"mtime":1611670471858,"results":"9","hashOfConfig":"8"},{"size":889,"mtime":1611497488080,"results":"10","hashOfConfig":"8"},{"size":2548,"mtime":1611668355580,"results":"11","hashOfConfig":"8"},{"size":2199,"mtime":1610325754517,"results":"12","hashOfConfig":"8"},{"size":1456,"mtime":1611495914736,"results":"13","hashOfConfig":"8"},{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1n20xnc",{"filePath":"16","messages":"17","errorCount":0,"warningCount":6,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"18","messages":"19","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"20"},{"filePath":"21","messages":"22","errorCount":0,"warningCount":8,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"23","messages":"24","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","errorCount":0,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js",[],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js",["27","28","29","30","31","32"],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\index.js",["33","34"],"import React from 'react';\r\nimport ReactDOM from 'react-dom';\r\nimport './index.css';\r\nimport 'bootstrap/dist/css/bootstrap.min.css';\r\nimport App from './Pages/App';\r\nimport Search from './Pages/Search';\r\nimport axios from 'axios';\r\nimport reportWebVitals from './reportWebVitals';\r\nimport {\r\n BrowserRouter as Router,\r\n Switch,\r\n Route,\r\n Redirect,\r\n} from \"react-router-dom\";\r\n\r\nReactDOM.render(\r\n <React.StrictMode>\r\n <Router>\r\n <Switch>\r\n <Route exact path=\"/\" component={App} />\r\n <Route path=\"/search\" component={Search} />\r\n </Switch>\r\n </Router>\r\n </React.StrictMode>,\r\n document.getElementById('root')\r\n);\r\n\r\n// If you want to start measuring performance in your app, pass a function\r\n// to log results (for example: reportWebVitals(console.log))\r\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\r\nreportWebVitals();\r\n","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Place.js",["35","36","37","38","39","40","41","42"],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Paginations.js",[],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\App.js",["43","44","45"],{"ruleId":"46","severity":1,"message":"47","line":2,"column":16,"nodeType":"48","messageId":"49","endLine":2,"endColumn":24},{"ruleId":"50","severity":1,"message":"51","line":34,"column":8,"nodeType":"52","endLine":34,"endColumn":10,"suggestions":"53"},{"ruleId":"50","severity":1,"message":"54","line":38,"column":8,"nodeType":"52","endLine":38,"endColumn":21,"suggestions":"55"},{"ruleId":"50","severity":1,"message":"56","line":53,"column":8,"nodeType":"52","endLine":53,"endColumn":10,"suggestions":"57"},{"ruleId":"46","severity":1,"message":"58","line":68,"column":11,"nodeType":"48","messageId":"49","endLine":68,"endColumn":17},{"ruleId":"59","severity":1,"message":"60","line":129,"column":35,"nodeType":"61","endLine":129,"endColumn":76},{"ruleId":"46","severity":1,"message":"62","line":7,"column":8,"nodeType":"48","messageId":"49","endLine":7,"endColumn":13},{"ruleId":"46","severity":1,"message":"47","line":13,"column":3,"nodeType":"48","messageId":"49","endLine":13,"endColumn":11},{"ruleId":"46","severity":1,"message":"63","line":3,"column":33,"nodeType":"48","messageId":"49","endLine":3,"endColumn":36},{"ruleId":"46","severity":1,"message":"64","line":3,"column":46,"nodeType":"48","messageId":"49","endLine":3,"endColumn":51},{"ruleId":"46","severity":1,"message":"65","line":3,"column":53,"nodeType":"48","messageId":"49","endLine":3,"endColumn":57},{"ruleId":"46","severity":1,"message":"66","line":3,"column":59,"nodeType":"48","messageId":"49","endLine":3,"endColumn":68},{"ruleId":"46","severity":1,"message":"67","line":3,"column":70,"nodeType":"48","messageId":"49","endLine":3,"endColumn":78},{"ruleId":"46","severity":1,"message":"68","line":13,"column":10,"nodeType":"48","messageId":"49","endLine":13,"endColumn":15},{"ruleId":"46","severity":1,"message":"69","line":13,"column":17,"nodeType":"48","messageId":"49","endLine":13,"endColumn":25},{"ruleId":"50","severity":1,"message":"70","line":32,"column":6,"nodeType":"52","endLine":32,"endColumn":8,"suggestions":"71"},{"ruleId":"46","severity":1,"message":"72","line":1,"column":17,"nodeType":"48","messageId":"49","endLine":1,"endColumn":26},{"ruleId":"46","severity":1,"message":"73","line":2,"column":10,"nodeType":"48","messageId":"49","endLine":2,"endColumn":14},{"ruleId":"46","severity":1,"message":"74","line":4,"column":64,"nodeType":"48","messageId":"49","endLine":4,"endColumn":75},"no-unused-vars","'Redirect' is defined but never used.","Identifier","unusedVar","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'getAssociation'. Either include it or remove the dependency array.","ArrayExpression",["75"],"React Hook useEffect has a missing dependency: 'index'. Either include it or remove the dependency array. You can also replace multiple useState variables with useReducer if 'setPagePlace' needs the current value of 'index'.",["76"],"React Hook useEffect has missing dependencies: 'getAssociation', 'props.history', 'search', and 'state'. Either include them or remove the dependency array.",["77"],"'places' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute","'axios' is defined but never used.","'Col' is defined but never used.","'Badge' is defined but never used.","'Card' is defined but never used.","'Accordion' is defined but never used.","'Carousel' is defined but never used.","'state' is assigned a value but never used.","'setState' is assigned a value but never used.","React Hook useEffect has missing dependencies: 'getReview' and 'infiniteScroll'. Either include them or remove the dependency array.",["78"],"'useEffect' is defined but never used.","'Link' is defined but never used.","'FormControl' is defined but never used.",{"desc":"79","fix":"80"},{"desc":"81","fix":"82"},{"desc":"83","fix":"84"},{"desc":"85","fix":"86"},"Update the dependencies array to be: [getAssociation]",{"range":"87","text":"88"},"Update the dependencies array to be: [association, index]",{"range":"89","text":"90"},"Update the dependencies array to be: [getAssociation, props.history, search, state]",{"range":"91","text":"92"},"Update the dependencies array to be: [getReview, infiniteScroll]",{"range":"93","text":"94"},[1288,1290],"[getAssociation]",[1398,1411],"[association, index]",[1994,1996],"[getAssociation, props.history, search, state]",[962,964],"[getReview, infiniteScroll]"] [{"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js":"1","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js":"2","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\index.js":"3","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Paginations.js":"4","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\App.js":"5","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Place.js":"6","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Hello.js":"7"},{"size":362,"mtime":1608689675665,"results":"8","hashOfConfig":"9"},{"size":7672,"mtime":1611722932802,"results":"10","hashOfConfig":"9"},{"size":889,"mtime":1611497488080,"results":"11","hashOfConfig":"9"},{"size":2199,"mtime":1610325754517,"results":"12","hashOfConfig":"9"},{"size":1456,"mtime":1611495914736,"results":"13","hashOfConfig":"9"},{"size":2146,"mtime":1611734244694,"results":"14","hashOfConfig":"9"},{"size":2011,"mtime":1611721355007,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1n20xnc",{"filePath":"18","messages":"19","errorCount":0,"warningCount":8,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"20","messages":"21","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"22"},{"filePath":"23","messages":"24","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","errorCount":0,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"27","messages":"28","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"29","messages":"30","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js",[],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js",["31","32","33","34","35","36","37","38"],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\index.js",["39","40"],"import React from 'react';\r\nimport ReactDOM from 'react-dom';\r\nimport './index.css';\r\nimport 'bootstrap/dist/css/bootstrap.min.css';\r\nimport App from './Pages/App';\r\nimport Search from './Pages/Search';\r\nimport axios from 'axios';\r\nimport reportWebVitals from './reportWebVitals';\r\nimport {\r\n BrowserRouter as Router,\r\n Switch,\r\n Route,\r\n Redirect,\r\n} from \"react-router-dom\";\r\n\r\nReactDOM.render(\r\n <React.StrictMode>\r\n <Router>\r\n <Switch>\r\n <Route exact path=\"/\" component={App} />\r\n <Route path=\"/search\" component={Search} />\r\n </Switch>\r\n </Router>\r\n </React.StrictMode>,\r\n document.getElementById('root')\r\n);\r\n\r\n// If you want to start measuring performance in your app, pass a function\r\n// to log results (for example: reportWebVitals(console.log))\r\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\r\nreportWebVitals();\r\n","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Components\\Paginations.js",[],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\App.js",["41","42","43"],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Place.js",["44","45"],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Hello.js",["46"],{"ruleId":"47","severity":1,"message":"48","line":2,"column":16,"nodeType":"49","messageId":"50","endLine":2,"endColumn":24},{"ruleId":"47","severity":1,"message":"51","line":13,"column":12,"nodeType":"49","messageId":"50","endLine":13,"endColumn":19},{"ruleId":"47","severity":1,"message":"52","line":13,"column":21,"nodeType":"49","messageId":"50","endLine":13,"endColumn":31},{"ruleId":"53","severity":1,"message":"54","line":33,"column":8,"nodeType":"55","endLine":33,"endColumn":10,"suggestions":"56"},{"ruleId":"53","severity":1,"message":"57","line":37,"column":8,"nodeType":"55","endLine":37,"endColumn":21,"suggestions":"58"},{"ruleId":"53","severity":1,"message":"59","line":52,"column":8,"nodeType":"55","endLine":52,"endColumn":10,"suggestions":"60"},{"ruleId":"47","severity":1,"message":"61","line":67,"column":11,"nodeType":"49","messageId":"50","endLine":67,"endColumn":17},{"ruleId":"62","severity":1,"message":"63","line":128,"column":35,"nodeType":"64","endLine":128,"endColumn":76},{"ruleId":"47","severity":1,"message":"65","line":7,"column":8,"nodeType":"49","messageId":"50","endLine":7,"endColumn":13},{"ruleId":"47","severity":1,"message":"48","line":13,"column":3,"nodeType":"49","messageId":"50","endLine":13,"endColumn":11},{"ruleId":"47","severity":1,"message":"66","line":1,"column":17,"nodeType":"49","messageId":"50","endLine":1,"endColumn":26},{"ruleId":"47","severity":1,"message":"67","line":2,"column":10,"nodeType":"49","messageId":"50","endLine":2,"endColumn":14},{"ruleId":"47","severity":1,"message":"68","line":4,"column":64,"nodeType":"49","messageId":"50","endLine":4,"endColumn":75},{"ruleId":"47","severity":1,"message":"69","line":3,"column":26,"nodeType":"49","messageId":"50","endLine":3,"endColumn":32},{"ruleId":"53","severity":1,"message":"70","line":34,"column":6,"nodeType":"55","endLine":34,"endColumn":8,"suggestions":"71"},{"ruleId":"47","severity":1,"message":"65","line":1,"column":8,"nodeType":"49","messageId":"50","endLine":1,"endColumn":13},"no-unused-vars","'Redirect' is defined but never used.","Identifier","unusedVar","'showSet' is assigned a value but never used.","'setShowSet' is assigned a value but never used.","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'getAssociation'. Either include it or remove the dependency array.","ArrayExpression",["72"],"React Hook useEffect has a missing dependency: 'index'. Either include it or remove the dependency array. You can also replace multiple useState variables with useReducer if 'setPagePlace' needs the current value of 'index'.",["73"],"React Hook useEffect has missing dependencies: 'getAssociation', 'props.history', 'search', and 'state'. Either include them or remove the dependency array.",["74"],"'places' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute","'axios' is defined but never used.","'useEffect' is defined but never used.","'Link' is defined but never used.","'FormControl' is defined but never used.","'Button' is defined but never used.","React Hook useEffect has missing dependencies: 'getReview' and 'infiniteScroll'. Either include them or remove the dependency array.",["75"],{"desc":"76","fix":"77"},{"desc":"78","fix":"79"},{"desc":"80","fix":"81"},{"desc":"82","fix":"83"},"Update the dependencies array to be: [getAssociation]",{"range":"84","text":"85"},"Update the dependencies array to be: [association, index]",{"range":"86","text":"87"},"Update the dependencies array to be: [getAssociation, props.history, search, state]",{"range":"88","text":"89"},"Update the dependencies array to be: [getReview, infiniteScroll]",{"range":"90","text":"91"},[1248,1250],"[getAssociation]",[1358,1371],"[association, index]",[1954,1956],"[getAssociation, props.history, search, state]",[1102,1104],"[getReview, infiniteScroll]"]
\ No newline at end of file \ 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.index + 1}. {props.place.name}
</Modal.Title>
</Modal.Header>
<Modal.Body className="show-grid">
<Container style={{ fontSize: '40px' }}>
{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>
</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;
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from '../ohuh-sm.PNG'; import ohuh from '../ohuh-sm.PNG';
import Place from '../Components/Place';
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button } from 'react-bootstrap'; import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button } from 'react-bootstrap';
import Paginations from '../Components/Paginations'; import Paginations from '../Components/Paginations';
import axios from 'axios'; import axios from 'axios';
...@@ -13,7 +12,7 @@ function Search(props) { ...@@ -13,7 +12,7 @@ function Search(props) {
const [index, setIndex] = useState(1); const [index, setIndex] = useState(1);
const [showSet, setShowSet] = useState([false, false, false, false]); const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(queryString.parse(props.location.search).keyword); const [search, setSearch] = useState(queryString.parse(props.location.search).keyword);
const [pagePlace, setPagePlace] = useState(); const [pagePlace, setPagePlace] = useState([]);
const [association, setAssociation] = useState([]) const [association, setAssociation] = useState([])
const getAssociation = () => { const getAssociation = () => {
...@@ -125,7 +124,7 @@ function Search(props) { ...@@ -125,7 +124,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">
...@@ -150,15 +149,12 @@ function Search(props) { ...@@ -150,15 +149,12 @@ function Search(props) {
<Card align="center" border="info" style={{ margin: "3%" }}> <Card align="center" border="info" style={{ margin: "3%" }}>
<Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{place.name}</Card.Title> <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }} >{place.name}</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="primary" 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>
...@@ -168,7 +164,7 @@ function Search(props) { ...@@ -168,7 +164,7 @@ function Search(props) {
<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>
</Row> </Row>
</Container> </Container >
); );
} }
......
...@@ -12,6 +12,8 @@ import { ...@@ -12,6 +12,8 @@ import {
Route, Route,
Redirect, Redirect,
} from "react-router-dom"; } from "react-router-dom";
import Place from './Pages/Place';
import Hello from './Pages/Hello';
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
...@@ -19,6 +21,8 @@ ReactDOM.render( ...@@ -19,6 +21,8 @@ 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="/hello" component={Hello} />
</Switch> </Switch>
</Router> </Router>
</React.StrictMode>, </React.StrictMode>,
......
...@@ -2,50 +2,44 @@ import Review from '../models/Review.js' ...@@ -2,50 +2,44 @@ 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 response1 = await axios.get(url)
let $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) {
console.log("3")
let title = $1(this).find('h3').text()
let searchParams = new URLSearchParams($1(this).find('a').attr('href'));
let link = searchParams.get("/url?q")
let summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
if (title) {
reviews[i] = { title: title, link: link }
} else if (summary) {
reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e)
}
})
reviews.forEach((review, i) => {
Review.findOne({ link: review.link }, async function (err, reviewss) {
console.log("4")
if (err) { return res.status(404).send({ error: err }) }
if (reviewss) {
reviewss.keyword = [...reviewss.keyword, req.query.keyword]
reviewss.save()
}
if (!reviewss) {
reviews["keyword"] = [req.query.keyword]
let Reviews = await new Review(review).save()
// console.log(Reviews,"1")
req.reviews.push(Reviews)
}
})
}) let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + `+site%3Atistory.com&start=${Number(req.query.index) * 10}`
} console.log(url)
const a = await Promise.all(req.reviews) let response1 = await axios.get(url)
console.log(a, "2") let $1 = cheerio.load(response1.data);
res.status(200).send({ review: a, db: true }) $1('.kCrYT').each(async function (i) {
console.log("3")
let title = $1(this).find('h3').text()
let searchParams = new URLSearchParams($1(this).find('a').attr('href'));
let link = searchParams.get("/url?q")
let summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
if (title) {
reviews[i] = { title: title, link: link }
} else if (summary) {
reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e)
}
})
// reviews.forEach(async (review, i) => {
// await Review.updateOne({ link: review.link }, { $push: { bookmark: req.query.keyword } })
// const reviewss = await Review.findOne({ link: review.link })
// if (!reviewss) {
// // reviews["keyword"] = [req.query.keyword]
let newReviews = []
newReviews = [...newReviews, ...reviews]
// await new Review(review).save()
// }
// })
// console.log(req.reviews, "걸러낸 리뷰즈입니다")
// const a = await Promise.all(newReviews)
// console.log(a, "2")
console.log(req.query.index, "인덱스ㅡㅡ")
res.status(200).send({ review: newReviews, db: true, index: Number(req.query.index) + 1 })
} catch (error) { } catch (error) {
console.log("6") console.log("6")
console.log(error) console.log(error)
...@@ -53,17 +47,17 @@ const search = async (req, res, next) => { ...@@ -53,17 +47,17 @@ 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
if (req.body.db) { if (req.body.db) {
next() next()
} }
Review.find({ keyword: keyword }, function (err, reviews) { await Review.find({ keyword: keyword }, function (err, reviews) {
req.reviews = [] req.reviews = []
if (reviews) { if (reviews) {
if (reviews.length > 10) { if (reviews.length > 5) {
res.status(200).send({ review: reviews, db: true }) res.status(200).send({ review: reviews, db: true, message: "제발용" })
} }
req.reviews = reviews req.reviews = reviews
} }
......
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