Fixing post sorting by stickied on front end. Fixes #575

This commit is contained in:
Dessalines 2020-03-04 11:46:34 -05:00
parent 8855b91d0c
commit fb35518848
2 changed files with 12 additions and 3 deletions

View file

@ -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;

13
ui/src/utils.ts vendored
View file

@ -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)
);
}