Skip to content

Commit

Permalink
FEAT : 무한 스크롤 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
junvhui committed Feb 24, 2024
1 parent 22f68d2 commit 4df2ba1
Show file tree
Hide file tree
Showing 22 changed files with 2,436 additions and 35 deletions.
16 changes: 13 additions & 3 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ async function connectToMongoDB() {

connectToMongoDB();

app.get('/article', async (req, res) => {
const PAGE_SIZE = 3;

app.get('/articles', async (req, res) => {
const pageNumber = req.query.pageNumber ? parseInt(req.query.pageNumber) : 1;

try {
const articles = await articleCollection.find({}).toArray();
res.json({ result: 'success', article: articles });
const articles = await articleCollection
.find({})
.sort({ _id: -1 }) // _id를 기준으로 역순으로 정렬
.skip((pageNumber - 1) * PAGE_SIZE)
.limit(PAGE_SIZE)
.toArray();

res.json({ result: 'success', articles: articles });
} catch (error) {
console.error('Error fetching articles:', error);
res.status(500).json({ result: 'error', message: 'Internal server error' });
Expand Down
9 changes: 4 additions & 5 deletions backend/article_add.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ async function insertDocument() {
await connectToMongoDB();

const newDocument = {
title: '‘성적 부진’ 투헬, 결국 떠난다…뮌헨, 올여름 이별 결정',
content:
'https://www.goal.com/kr/%EB%89%B4%EC%8A%A4/%E1%84%89%E1%85%A5%E1%86%BC%E1%84%8C%E1%85%A5%E1%86%A8-%E1%84%87%E1%85%AE%E1%84%8C%E1%85%B5%E1%86%AB-%E1%84%90%E1%85%AE%E1%84%92%E1%85%A6%E1%86%AF-%E1%84%80%E1%85%A7%E1%86%AF%E1%84%80%E1%85%AE%E1%86%A8-%E1%84%84%E1%85%A5%E1%84%82%E1%85%A1%E1%86%AB%E1%84%83%E1%85%A1--%E1%84%86%E1%85%B1%E1%86%AB%E1%84%92%E1%85%A6%E1%86%AB-%E1%84%8B%E1%85%A9%E1%86%AF%E1%84%8B%E1%85%A7%E1%84%85%E1%85%B3%E1%86%B7-%E1%84%8B%E1%85%B5%E1%84%87%E1%85%A7%E1%86%AF-%E1%84%80%E1%85%A7%E1%86%AF%E1%84%8C%E1%85%A5%E1%86%BC-%E1%84%8B%E1%85%A9%E1%84%91%E1%85%B5%E1%84%89%E1%85%A7%E1%86%AF/blt4ac8a2abdc725d60',
url: 'https://assets.goal.com/v3/assets/bltcc7a7ffd2fbf71f5/blt40aa60a98719674f/65d5cdad6a9053040ae38f75/20240221_Thomas_Tuchel.jpg?auto=webp&format=pjpg&width=2048&quality=60',
team: '바이에른 뮌헨',
title: '‘주급이라도 아끼자’ 맨유, 앙토니 마샬 1년 연장 옵션 행사 안 한다',
content: 'https://www.stnsports.co.kr/news/articleView.html?idxno=210532',
url: 'https://assets.goal.com/v3/assets/bltcc7a7ffd2fbf71f5/blt75efef14859572cf/65a952bcda2a53040a5cf06a/Martial_Man_United.jpg?auto=webp&format=pjpg&width=2048&quality=60',
team: '맨유',
};

const insertResult = await collection.insertOne(newDocument);
Expand Down
14 changes: 14 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/react-intersection-observer/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

535 changes: 535 additions & 0 deletions node_modules/react-intersection-observer/README.md

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions node_modules/react-intersection-observer/esm/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/react-intersection-observer/esm/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 4df2ba1

Please sign in to comment.