fixed post count

This commit is contained in:
2026-01-23 19:26:42 +01:00
parent 662e00bec1
commit bc893b644d
3 changed files with 69 additions and 25 deletions

View File

@@ -28,6 +28,8 @@ export default function PortalTopicRow({ thread, forumName, forumId, showForum =
return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`
}
const repliesCount = Math.max((thread.posts_count ?? 0) - 1, 0)
return (
<div className="bb-portal-topic-row">
<div className="bb-portal-topic-main">
@@ -72,7 +74,7 @@ export default function PortalTopicRow({ thread, forumName, forumId, showForum =
</div>
</div>
</div>
<div className="bb-portal-topic-cell">{thread.posts_count ?? 0}</div>
<div className="bb-portal-topic-cell">{repliesCount}</div>
<div className="bb-portal-topic-cell">{thread.views_count ?? 0}</div>
<div className="bb-portal-topic-cell bb-portal-topic-cell--last">
<div className="bb-portal-last">

View File

@@ -91,7 +91,48 @@ export default function Home() {
nodes.forEach((node) => sortNodes(node.children))
}
const aggregateNodes = (node) => {
if (!node.children?.length) {
return {
threads: node.threads_count ?? 0,
views: node.views_count ?? 0,
posts: node.posts_count ?? 0,
last: node.last_post_at ? { at: node.last_post_at, node } : null,
}
}
let threads = node.threads_count ?? 0
let views = node.views_count ?? 0
let posts = node.posts_count ?? 0
let last = node.last_post_at ? { at: node.last_post_at, node } : null
node.children.forEach((child) => {
const agg = aggregateNodes(child)
threads += agg.threads
views += agg.views
posts += agg.posts
if (agg.last && (!last || agg.last.at > last.at)) {
last = agg.last
}
})
node.threads_count = threads
node.views_count = views
node.posts_count = posts
if (last) {
const source = last.node
node.last_post_at = source.last_post_at
node.last_post_user_id = source.last_post_user_id
node.last_post_user_name = source.last_post_user_name
node.last_post_user_rank_color = source.last_post_user_rank_color
node.last_post_user_group_color = source.last_post_user_group_color
}
return { threads, views, posts, last }
}
sortNodes(roots)
roots.forEach((root) => aggregateNodes(root))
return roots
}, [forums])