mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
update home
This commit is contained in:
@@ -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
@@ -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 (
|
||||||
|
|||||||
Reference in New Issue
Block a user