]> Untitled Git - lemmy.git/blobdiff - ui/src/components/post-listings.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / post-listings.tsx
index 005c4fe03ce669ca7c32394efcdd7b768a8c741e..2c9b4a882663e4e154c6e406fbf11fd807c775aa 100644 (file)
@@ -1,6 +1,7 @@
 import { Component } from 'inferno';
 import { Link } from 'inferno-router';
-import { Post } from '../interfaces';
+import { Post, SortType } from 'lemmy-js-client';
+import { postSort } from '../utils';
 import { PostListing } from './post-listing';
 import { i18n } from '../i18next';
 import { T } from 'inferno-i18next';
@@ -9,6 +10,9 @@ interface PostListingsProps {
   posts: Array<Post>;
   showCommunity?: boolean;
   removeDuplicates?: boolean;
+  sort?: SortType;
+  enableDownvotes: boolean;
+  enableNsfw: boolean;
 }
 
 export class PostListings extends Component<PostListingsProps, any> {
@@ -20,17 +24,15 @@ 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}
                 showCommunity={this.props.showCommunity}
+                enableDownvotes={this.props.enableDownvotes}
+                enableNsfw={this.props.enableNsfw}
               />
-              <hr class="d-md-none my-2" />
-              <div class="d-none d-md-block my-2"></div>
+              <hr class="my-3" />
             </>
           ))
         ) : (
@@ -47,6 +49,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, this.props.showCommunity == undefined);
+    }
+
+    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>>();