Fixing post sorting by stickied on front end. Fixes #575
This commit is contained in:
parent
c74d8bfc64
commit
0dae5e910a
2 changed files with 12 additions and 3 deletions
2
ui/src/components/post-listings.tsx
vendored
2
ui/src/components/post-listings.tsx
vendored
|
@ -53,7 +53,7 @@ export class PostListings extends Component<PostListingsProps, any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.sort !== undefined) {
|
if (this.props.sort !== undefined) {
|
||||||
postSort(out, this.props.sort);
|
postSort(out, this.props.sort, this.props.showCommunity == undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
13
ui/src/utils.ts
vendored
13
ui/src/utils.ts
vendored
|
@ -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
|
// First, put removed and deleted comments at the bottom, then do your other sorts
|
||||||
if (
|
if (
|
||||||
sort == SortType.TopAll ||
|
sort == SortType.TopAll ||
|
||||||
|
@ -740,13 +744,17 @@ export function postSort(posts: Array<Post>, sort: SortType) {
|
||||||
) {
|
) {
|
||||||
posts.sort(
|
posts.sort(
|
||||||
(a, b) =>
|
(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) {
|
} else if (sort == SortType.New) {
|
||||||
posts.sort(
|
posts.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
+a.removed - +b.removed ||
|
+a.removed - +b.removed ||
|
||||||
+a.deleted - +b.deleted ||
|
+a.deleted - +b.deleted ||
|
||||||
|
(communityType && +b.stickied - +a.stickied) ||
|
||||||
b.published.localeCompare(a.published)
|
b.published.localeCompare(a.published)
|
||||||
);
|
);
|
||||||
} else if (sort == SortType.Hot) {
|
} else if (sort == SortType.Hot) {
|
||||||
|
@ -754,6 +762,7 @@ export function postSort(posts: Array<Post>, sort: SortType) {
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
+a.removed - +b.removed ||
|
+a.removed - +b.removed ||
|
||||||
+a.deleted - +b.deleted ||
|
+a.deleted - +b.deleted ||
|
||||||
|
(communityType && +b.stickied - +a.stickied) ||
|
||||||
hotRankPost(b) - hotRankPost(a)
|
hotRankPost(b) - hotRankPost(a)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue