]> Untitled Git - lemmy.git/blob - ui/src/components/comment-nodes.tsx
Merge branch 'dev' into federation
[lemmy.git] / ui / src / components / comment-nodes.tsx
1 import { Component } from 'inferno';
2 import {
3   CommentNode as CommentNodeI,
4   CommunityUser,
5   UserView,
6   CommentSortType,
7   SortType,
8 } from '../interfaces';
9 import { commentSort, commentSortSortType } from '../utils';
10 import { CommentNode } from './comment-node';
11
12 interface CommentNodesState {}
13
14 interface CommentNodesProps {
15   nodes: Array<CommentNodeI>;
16   moderators?: Array<CommunityUser>;
17   admins?: Array<UserView>;
18   postCreatorId?: number;
19   noIndent?: boolean;
20   viewOnly?: boolean;
21   locked?: boolean;
22   markable?: boolean;
23   showCommunity?: boolean;
24   sort?: CommentSortType;
25   sortType?: SortType;
26 }
27
28 export class CommentNodes extends Component<
29   CommentNodesProps,
30   CommentNodesState
31 > {
32   constructor(props: any, context: any) {
33     super(props, context);
34   }
35
36   render() {
37     return (
38       <div className="comments">
39         {this.sorter().map(node => (
40           <CommentNode
41             node={node}
42             noIndent={this.props.noIndent}
43             viewOnly={this.props.viewOnly}
44             locked={this.props.locked}
45             moderators={this.props.moderators}
46             admins={this.props.admins}
47             postCreatorId={this.props.postCreatorId}
48             markable={this.props.markable}
49             showCommunity={this.props.showCommunity}
50             sort={this.props.sort}
51             sortType={this.props.sortType}
52           />
53         ))}
54       </div>
55     );
56   }
57
58   sorter(): Array<CommentNodeI> {
59     if (this.props.sort !== undefined) {
60       commentSort(this.props.nodes, this.props.sort);
61     } else if (this.props.sortType !== undefined) {
62       commentSortSortType(this.props.nodes, this.props.sortType);
63     }
64
65     return this.props.nodes;
66   }
67 }