Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infiniteScrollControll #66

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion back/bookReviewList.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ async function bookList(post_id) {
}

return post_obj;
}
}
module.exports = {
bookList,
};

32 changes: 16 additions & 16 deletions back/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const path = require('path');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());//post요청 body parser
const run = require("./recommendationAlgorithm");
const PostViewPage_Algorithm = require("./bookReviewList");
const recommendAlgo = require("./recommendationAlgorithm");
const reviewListAlgo = require("./bookReviewList");


//클라이언트에서 서버로의 HTTP 요청이 서로 다른 출처에서 오더라도 정상적으로 처리
const cors = require('cors');
Expand Down Expand Up @@ -72,12 +73,17 @@ app.delete('/api/post/:postId', (req, res) => {
});
});

// /api/data 로 posts table 내용 보내기
app.get('/api/ScrollView', async(req, res) => {

await run.runQueries();
res.json(await run.runQueries());

//
app.post('/api/ScrollView', async(req, res) => {
const postID = req.body.postID;
console.log("postID: " ,postID);
if(postID==undefined){
const data =await recommendAlgo.runQueries();
res.json(data);
}else{
const data = await reviewListAlgo.bookList()
res.json(data);
}
});

// /api/post/{postid} 로 post 정보 보내기
Expand All @@ -88,7 +94,7 @@ app.get('/api/post/:postId',(req,res)=>{
if(error){
console.log(error);
res.status(500).json({ error: '데이터베이스에서 데이터를 가져오는 중 오류가 발생했습니다.' });
}else{
}else{
console.log(result);
res.json(result);
}
Expand Down Expand Up @@ -155,18 +161,12 @@ app.post('/api/library',(req,res)=>{
res.status(500).json({ error: '데이터베이스에서 데이터를 가져오는 중 오류가 발생했습니다.' });
}
else{
//console.log({result});
res.json({result});
}
})
})
//console.log(run.runQueries());

app.get('/api/recommend',(req,res)=>{
});
//react에서 route 사용하기 - 맨 밑에 둘 것
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, '/../front/build/index.html'));
});

console.log(run.runQueries);
});
8 changes: 4 additions & 4 deletions back/recommendationAlgorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ async function runQueries() {
return post_obj;
}

async function run(){
console.log(await runQueries());
}
// async function run(){
// console.log(await runQueries());
// }

run();
//run();
/*
//1번 리뷰 데이터
let document = [];
Expand Down
15 changes: 12 additions & 3 deletions front/src/components/ScrollView.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, { useEffect, useState } from 'react';
import PostFragment from './PostFragment';
import styles from "../css/ScrollView.module.css";
import { useParams } from 'react-router-dom';
function ScrollView() {//무한스크롤
const count = 7;
const {postId} = useParams();
const reqPostID = {postID : postId};
const count = 1;
let index =0;
const [fragments, setFragments] = useState([]); // PostFragment 컴포넌트들을 담을 상태

Expand All @@ -15,12 +18,18 @@ function ScrollView() {//무한스크롤
entries.forEach((entry) => {
if (entry.isIntersecting) {
console.log("entry.isIntersecting");

fetch("http://localhost:8080/api/ScrollView")
fetch("http://localhost:8080/api/ScrollView",{
method:"POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(reqPostID)
})
.then(res=>res.json())
.then(json=>{
console.log(json);
console.log(json[1]);
if(json[0]==="none");
const newFragments = [];
for (let i = index; i < index + count; i++) {
newFragments.push(<PostFragment key={i} postId={json[i].postID} post={json[i].body}/>);//postID만 가지고 검색할 예정
Expand Down