summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post-listings.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-02-09 11:44:24 -0500
committerDessalines <tyhou13@gmx.com>2020-02-09 11:44:24 -0500
commitfd8814677ec81eff5358c102b6b424ec1c23c2fb (patch)
treeb715aedaf6b06ccf6bcbb10c099c2d794b2c819c /ui/src/components/post-listings.tsx
parent56cd103209605471b27aa5a854cc3b051f2a65f5 (diff)
Live post and comment resorting. Fixes #522
- Moving sorting to utils.
Diffstat (limited to 'ui/src/components/post-listings.tsx')
-rw-r--r--ui/src/components/post-listings.tsx22
1 files changed, 17 insertions, 5 deletions
diff --git a/ui/src/components/post-listings.tsx b/ui/src/components/post-listings.tsx
index 005c4fe0..d61f624d 100644
--- a/ui/src/components/post-listings.tsx
+++ b/ui/src/components/post-listings.tsx
@@ -1,6 +1,7 @@
import { Component } from 'inferno';
import { Link } from 'inferno-router';
-import { Post } from '../interfaces';
+import { Post, SortType } from '../interfaces';
+import { postSort } from '../utils';
import { PostListing } from './post-listing';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -9,6 +10,7 @@ interface PostListingsProps {
posts: Array<Post>;
showCommunity?: boolean;
removeDuplicates?: boolean;
+ sort?: SortType;
}
export class PostListings extends Component<PostListingsProps, any> {
@@ -20,10 +22,7 @@ export class PostListings extends Component<PostListingsProps, any> {
return (
<div>
{this.props.posts.length > 0 ? (
- (this.props.removeDuplicates
- ? this.removeDuplicates(this.props.posts)
- : this.props.posts
- ).map(post => (
+ this.outer().map(post => (
<>
<PostListing
post={post}
@@ -47,6 +46,19 @@ export class PostListings extends Component<PostListingsProps, any> {
);
}
+ outer(): Array<Post> {
+ let out = this.props.posts;
+ if (this.props.removeDuplicates) {
+ out = this.removeDuplicates(out);
+ }
+
+ if (this.props.sort !== undefined) {
+ postSort(out, this.props.sort);
+ }
+
+ return out;
+ }
+
removeDuplicates(posts: Array<Post>): Array<Post> {
// A map from post url to list of posts (dupes)
let urlMap = new Map<string, Array<Post>>();