]> Untitled Git - lemmy.git/commitdiff
Add sorting by old (date, ascending) to comment frontend
authorD Anzorge <d.anzorge@gmail.com>
Tue, 28 Jan 2020 18:52:28 +0000 (19:52 +0100)
committerD Anzorge <d.anzorge@gmail.com>
Tue, 28 Jan 2020 19:14:08 +0000 (20:14 +0100)
ui/src/components/post.tsx
ui/src/interfaces.ts
ui/src/translations/en.ts

index 9ea275ce2615c5aaf4ff19a6dde4959756dbd002..366212488fe2620b0c06ce2ff9a0feccd3b0d703 100644 (file)
@@ -235,6 +235,18 @@ export class Post extends Component<any, PostState> {
             onChange={linkEvent(this, this.handleCommentSortChange)}
           />
         </label>
+        <label
+          className={`btn btn-sm btn-secondary pointer ${this.state
+            .commentSort === CommentSortType.Old && 'active'}`}
+        >
+          {i18n.t('old')}
+          <input
+            type="radio"
+            value={CommentSortType.Old}
+            checked={this.state.commentSort === CommentSortType.Old}
+            onChange={linkEvent(this, this.handleCommentSortChange)}
+          />
+        </label>
       </div>
     );
   }
@@ -317,6 +329,13 @@ export class Post extends Component<any, PostState> {
           +a.comment.deleted - +b.comment.deleted ||
           b.comment.published.localeCompare(a.comment.published)
       );
+    } else if (this.state.commentSort == CommentSortType.Old) {
+      tree.sort(
+        (a, b) =>
+          +a.comment.removed - +b.comment.removed ||
+          +a.comment.deleted - +b.comment.deleted ||
+          a.comment.published.localeCompare(b.comment.published)
+      );
     } else if (this.state.commentSort == CommentSortType.Hot) {
       tree.sort(
         (a, b) =>
index b0594e8de0282ca24659e9dee593a61116978459..f83595d776b076e5ac7037f8763f737c742dfd38 100644 (file)
@@ -47,6 +47,7 @@ export enum CommentSortType {
   Hot,
   Top,
   New,
+  Old,
 }
 
 export enum ListingType {
index c932014f84f33431ab1ca244e9b962fd21a6ebeb..90aff0b93573e094113e520c375fbf9ca57f8a2e 100644 (file)
@@ -97,6 +97,7 @@ export const en = {
     sort_type: 'Sort type',
     hot: 'Hot',
     new: 'New',
+    old: 'Old',
     top_day: 'Top day',
     week: 'Week',
     month: 'Month',