]> Untitled Git - lemmy.git/blob - ui/src/components/comment-nodes.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / comment-nodes.tsx
1 import { Component } from 'inferno';
2 import { CommentSortType } from '../interfaces';
3 import {
4   CommentNode as CommentNodeI,
5   CommunityUser,
6   UserView,
7   SortType,
8 } from 'lemmy-js-client';
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   noBorder?: boolean;
20   noIndent?: boolean;
21   viewOnly?: boolean;
22   locked?: boolean;
23   markable?: boolean;
24   showContext?: boolean;
25   showCommunity?: boolean;
26   sort?: CommentSortType;
27   sortType?: SortType;
28   enableDownvotes: boolean;
29 }
30
31 export class CommentNodes extends Component<
32   CommentNodesProps,
33   CommentNodesState
34 > {
35   constructor(props: any, context: any) {
36     super(props, context);
37   }
38
39   render() {
40     return (
41       <div className="comments">
42         {this.sorter().map(node => (
43           <CommentNode
44             key={node.comment.id}
45             node={node}
46             noBorder={this.props.noBorder}
47             noIndent={this.props.noIndent}
48             viewOnly={this.props.viewOnly}
49             locked={this.props.locked}
50             moderators={this.props.moderators}
51             admins={this.props.admins}
52             postCreatorId={this.props.postCreatorId}
53             markable={this.props.markable}
54             showContext={this.props.showContext}
55             showCommunity={this.props.showCommunity}
56             sort={this.props.sort}
57             sortType={this.props.sortType}
58             enableDownvotes={this.props.enableDownvotes}
59           />
60         ))}
61       </div>
62     );
63   }
64
65   sorter(): Array<CommentNodeI> {
66     if (this.props.sort !== undefined) {
67       commentSort(this.props.nodes, this.props.sort);
68     } else if (this.props.sortType !== undefined) {
69       commentSortSortType(this.props.nodes, this.props.sortType);
70     }
71
72     return this.props.nodes;
73   }
74 }