diff --git a/package-lock.json b/package-lock.json index 12164b41..33a6371c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,7 @@ "devDependencies": { "@svgr/webpack": "^8.1.0", "@tanstack/eslint-plugin-query": "^5.50.0", + "@types/lodash": "^4.17.7", "@types/node": "^20.14.10", "@types/qs": "^6.9.15", "@types/react": "^18.3.3", @@ -4259,6 +4260,12 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.17.7", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", + "integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==", + "dev": true + }, "node_modules/@types/node": { "version": "20.14.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", diff --git a/src/components/main/RecentComment.tsx b/src/components/main/RecentComment.tsx index 26df8734..f1ca4e88 100644 --- a/src/components/main/RecentComment.tsx +++ b/src/components/main/RecentComment.tsx @@ -17,7 +17,7 @@ function RecentComments() { useEffect(() => { if (data) { - setComments((prevComments) => [...prevComments, ...data.list]); + setComments((prevComments) => [...prevComments.filter((comment) => !data.list.some((newComment) => newComment.id === comment.id)), ...data.list]); if (data.list.length > 0) { setCursor(data.list[data.list.length - 1].id); } diff --git a/src/components/main/RecentEpigram.tsx b/src/components/main/RecentEpigram.tsx index 64a167bd..9dbf0a74 100644 --- a/src/components/main/RecentEpigram.tsx +++ b/src/components/main/RecentEpigram.tsx @@ -19,7 +19,7 @@ function RecentEpigrams() { useEffect(() => { if (data) { - setEpigrams((prevEpigrams) => [...prevEpigrams, ...data.list]); + setEpigrams((prevEpigrams) => [...prevEpigrams.filter((epigram) => !data.list.some((newEpigram) => newEpigram.id === epigram.id)), ...data.list]); if (data.list.length > 0) { setCursor(data.list[data.list.length - 1].id); } diff --git a/src/pageLayout/Feed/EpigramFeed.tsx b/src/pageLayout/Feed/EpigramFeed.tsx index e26a6b79..0d9dbe14 100644 --- a/src/pageLayout/Feed/EpigramFeed.tsx +++ b/src/pageLayout/Feed/EpigramFeed.tsx @@ -24,7 +24,7 @@ function EpigramFeed() { useEffect(() => { if (data) { - setEpigrams((prevEpigrams) => [...prevEpigrams, ...data.list]); + setEpigrams((prevEpigrams) => [...prevEpigrams, ...data.list.filter((epigram) => !new Set(prevEpigrams.map((e) => e.id)).has(epigram.id))]); if (data.list.length > 0) { setCursor(data.list[data.list.length - 1].id); }