From fd8814677ec81eff5358c102b6b424ec1c23c2fb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 9 Feb 2020 11:44:24 -0500 Subject: Live post and comment resorting. Fixes #522 - Moving sorting to utils. --- ui/src/components/post.tsx | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'ui/src/components/post.tsx') diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 1f2e40ba..b5b1fce3 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -31,7 +31,6 @@ import { import { WebSocketService, UserService } from '../services'; import { wsJsonToRes, - hotRank, toast, editCommentRes, saveCommentRes, @@ -314,48 +313,9 @@ export class Post extends Component { } } - this.sortTree(tree); - return tree; } - sortTree(tree: Array) { - // First, put removed and deleted comments at the bottom, then do your other sorts - if (this.state.commentSort == CommentSortType.Top) { - tree.sort( - (a, b) => - +a.comment.removed - +b.comment.removed || - +a.comment.deleted - +b.comment.deleted || - b.comment.score - a.comment.score - ); - } else if (this.state.commentSort == CommentSortType.New) { - tree.sort( - (a, b) => - +a.comment.removed - +b.comment.removed || - +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) => - +a.comment.removed - +b.comment.removed || - +a.comment.deleted - +b.comment.deleted || - hotRank(b.comment) - hotRank(a.comment) - ); - } - - for (let node of tree) { - this.sortTree(node.children); - } - } - commentsTree() { let nodes = this.buildCommentsTree(); return ( @@ -366,6 +326,7 @@ export class Post extends Component { moderators={this.state.moderators} admins={this.state.admins} postCreatorId={this.state.post.creator_id} + sort={this.state.commentSort} /> ); -- cgit v1.2.3