summaryrefslogtreecommitdiffstats
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
parent8855b91d0c15bcf9273f81736149e74b8c1a2fe4 (diff)
Fixing post sorting by stickied on front end. Fixes #575
-rw-r--r--ui/src/components/post-listings.tsx2
-rw-r--r--ui/src/utils.ts13
2 files changed, 12 insertions, 3 deletions
diff --git a/ui/src/components/post-listings.tsx b/ui/src/components/post-listings.tsx
index d61f624d..5e6acc0c 100644
--- a/ui/src/components/post-listings.tsx
+++ b/ui/src/components/post-listings.tsx
@@ -53,7 +53,7 @@ export class PostListings extends Component<PostListingsProps, any> {
}
if (this.props.sort !== undefined) {
- postSort(out, this.props.sort);
+ postSort(out, this.props.sort, this.props.showCommunity == undefined);
}
return out;
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)
);
}