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