update home

This commit is contained in:
plebeius.eth
2024-05-03 15:00:25 +02:00
parent 02b287fc12
commit b0fdbfc13e
2 changed files with 34 additions and 21 deletions
+1 -1
View File
@@ -218,7 +218,7 @@
line-height: 0; line-height: 0;
} }
.popularThread .mediaContainer img { .popularThread .mediaContainer img, .popularThread .mediaContainer video {
max-width: 150px; max-width: 150px;
max-height: 150px; max-height: 150px;
} }
+33 -20
View File
@@ -136,47 +136,60 @@ const PopularThreadCard = ({ post, boardTitle, boardShortAddress }: PopularThrea
const PopularThreads = ({ subplebbits }: { subplebbits: any }) => { const PopularThreads = ({ subplebbits }: { subplebbits: any }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [popularPosts, setPopularPosts] = useState([]); const [popularPosts, setPopularPosts] = useState<any[]>([]);
useEffect(() => { useEffect(() => {
let subplebbitToPost: any = {}; const subplebbitToPost: { [key: string]: any } = {};
const uniqueLinks: Set<string> = new Set();
subplebbits.forEach((subplebbit: any) => { subplebbits.forEach((subplebbit: any) => {
let maxTimestamp = -Infinity;
let mostRecentPost = null; let mostRecentPost = null;
if (subplebbit?.posts?.pages?.hot?.comments) { if (subplebbit?.posts?.pages?.hot?.comments) {
for (const comment of Object.values(subplebbit.posts.pages.hot.comments) as Comment[]) { for (const post of Object.values(subplebbit.posts.pages.hot.comments as Comment)) {
const { deleted, locked, pinned, removed, replyCount, timestamp } = comment; const { deleted, link, locked, pinned, removed, replyCount, timestamp } = post;
const commentMediaInfo = getCommentMediaInfo(post);
const commentMediaInfo = getCommentMediaInfo(comment); const isMediaShowed = getHasThumbnail(commentMediaInfo, link);
const isMediaShowed = getHasThumbnail(commentMediaInfo, comment.link);
if ( if (
isMediaShowed && isMediaShowed &&
replyCount >= 2 && replyCount >= 2 &&
!removed &&
!deleted && !deleted &&
!removed &&
!locked && !locked &&
!pinned && // criteria !pinned &&
timestamp > Date.now() / 1000 - 60 * 60 * 24 * 30 // 30 days timestamp > Date.now() / 1000 - 60 * 60 * 24 * 30 &&
timestamp > maxTimestamp &&
!uniqueLinks.has(link)
) { ) {
if (!mostRecentPost || comment.timestamp > mostRecentPost.timestamp) { maxTimestamp = post.timestamp;
mostRecentPost = comment; mostRecentPost = post;
} uniqueLinks.add(link);
} }
}
if (mostRecentPost) { if (mostRecentPost) {
subplebbitToPost[subplebbit.address] = mostRecentPost; subplebbitToPost[subplebbit.address] = { post: mostRecentPost, timestamp: maxTimestamp };
}
} }
} }
}); });
const newPopularPosts: any = Object.values(subplebbitToPost) const sortedPosts = Object.values(subplebbitToPost)
.sort((a: any, b: any) => b.timestamp - a.timestamp) .sort((a, b) => b.timestamp - a.timestamp)
.slice(0, 8); .map((item) => item.post);
setPopularPosts(newPopularPosts); setPopularPosts((prevPosts) => {
const updatedPosts = [...prevPosts];
sortedPosts.forEach((post) => {
if (!updatedPosts.find((p) => p.cid === post.cid)) {
if (updatedPosts.length < 8) {
updatedPosts.push(post);
}
}
});
return updatedPosts;
});
}, [subplebbits]); }, [subplebbits]);
return ( return (