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/comment-nodes.tsx | |
parent | 56cd103209605471b27aa5a854cc3b051f2a65f5 (diff) |
Live post and comment resorting. Fixes #522
- Moving sorting to utils.
Diffstat (limited to 'ui/src/components/comment-nodes.tsx')
-rw-r--r-- | ui/src/components/comment-nodes.tsx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ui/src/components/comment-nodes.tsx b/ui/src/components/comment-nodes.tsx index fb700cc4..b15da520 100644 --- a/ui/src/components/comment-nodes.tsx +++ b/ui/src/components/comment-nodes.tsx @@ -3,7 +3,10 @@ import { CommentNode as CommentNodeI, CommunityUser, UserView, + CommentSortType, + SortType, } from '../interfaces'; +import { commentSort, commentSortSortType } from '../utils'; import { CommentNode } from './comment-node'; interface CommentNodesState {} @@ -18,6 +21,8 @@ interface CommentNodesProps { locked?: boolean; markable?: boolean; showCommunity?: boolean; + sort?: CommentSortType; + sortType?: SortType; } export class CommentNodes extends Component< @@ -31,7 +36,7 @@ export class CommentNodes extends Component< render() { return ( <div className="comments"> - {this.props.nodes.map(node => ( + {this.sorter().map(node => ( <CommentNode node={node} noIndent={this.props.noIndent} @@ -42,9 +47,21 @@ export class CommentNodes extends Component< postCreatorId={this.props.postCreatorId} markable={this.props.markable} showCommunity={this.props.showCommunity} + sort={this.props.sort} + sortType={this.props.sortType} /> ))} </div> ); } + + sorter(): Array<CommentNodeI> { + if (this.props.sort !== undefined) { + commentSort(this.props.nodes, this.props.sort); + } else if (this.props.sortType !== undefined) { + commentSortSortType(this.props.nodes, this.props.sortType); + } + + return this.props.nodes; + } } |