Sort thread replies by likes (#1356)

* Sort replies by likes

* Types fix
zio/stable
Paul Frazee 2023-09-01 11:54:51 -07:00 committed by GitHub
parent 4cd3ddecad
commit 3e96373903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -296,7 +296,11 @@ function sortThread(item: MaybeThreadItem) {
if (modScore(a.moderation) !== modScore(b.moderation)) {
return modScore(a.moderation) - modScore(b.moderation)
}
return b.post.indexedAt.localeCompare(a.post.indexedAt) // newest
if (a.post.likeCount === b.post.likeCount) {
return b.post.indexedAt.localeCompare(a.post.indexedAt) // newest
} else {
return (b.post.likeCount || 0) - (a.post.likeCount || 0) // most likes
}
})
item.replies.forEach(reply => sortThread(reply))
}