summaryrefslogtreecommitdiffstats
path: root/ui/src/utils.ts
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-03-04 11:46:34 -0500
committerDessalines <tyhou13@gmx.com>2020-03-04 11:46:34 -0500
commitfb355188487bcd1e4185b8a034f95560cc28946d (patch)
tree21e2c6026e17e913cd8ac93569c02b08b7e5c9ba /ui/src/utils.ts
parent8855b91d0c15bcf9273f81736149e74b8c1a2fe4 (diff)
Fixing post sorting by stickied on front end. Fixes #575
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r--ui/src/utils.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index d531a7ca..5987070c 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -729,7 +729,11 @@ function convertCommentSortType(sort: SortType): CommentSortType {
}
}
-export function postSort(posts: Array<Post>, sort: SortType) {
+export function postSort(
+ posts: Array<Post>,
+ sort: SortType,
+ communityType: boolean
+) {
// First, put removed and deleted comments at the bottom, then do your other sorts
if (
sort == SortType.TopAll ||
@@ -740,13 +744,17 @@ export function postSort(posts: Array<Post>, sort: SortType) {
) {
posts.sort(
(a, b) =>
- +a.removed - +b.removed || +a.deleted - +b.deleted || b.score - a.score
+ +a.removed - +b.removed ||
+ +a.deleted - +b.deleted ||
+ (communityType && +b.stickied - +a.stickied) ||
+ b.score - a.score
);
} else if (sort == SortType.New) {
posts.sort(
(a, b) =>
+a.removed - +b.removed ||
+a.deleted - +b.deleted ||
+ (communityType && +b.stickied - +a.stickied) ||
b.published.localeCompare(a.published)
);
} else if (sort == SortType.Hot) {
@@ -754,6 +762,7 @@ export function postSort(posts: Array<Post>, sort: SortType) {
(a, b) =>
+a.removed - +b.removed ||
+a.deleted - +b.deleted ||
+ (communityType && +b.stickied - +a.stickied) ||
hotRankPost(b) - hotRankPost(a)
);
}