diff options
author | Dessalines <tyhou13@gmx.com> | 2020-02-09 11:44:24 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-02-09 11:44:24 -0500 |
commit | fd8814677ec81eff5358c102b6b424ec1c23c2fb (patch) | |
tree | b715aedaf6b06ccf6bcbb10c099c2d794b2c819c /ui/src/components/post.tsx | |
parent | 56cd103209605471b27aa5a854cc3b051f2a65f5 (diff) |
Live post and comment resorting. Fixes #522
- Moving sorting to utils.
Diffstat (limited to 'ui/src/components/post.tsx')
-rw-r--r-- | ui/src/components/post.tsx | 41 |
1 files changed, 1 insertions, 40 deletions
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<any, PostState> { } } - this.sortTree(tree); - return tree; } - sortTree(tree: Array<CommentNodeI>) { - // 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<any, PostState> { moderators={this.state.moderators} admins={this.state.admins} postCreatorId={this.state.post.creator_id} + sort={this.state.commentSort} /> </div> ); |