1 import { None, Some } from "@sniptt/monads/build";
2 import { Component } from "inferno";
5 GetPersonDetailsResponse,
9 } from "lemmy-js-client";
10 import { CommentViewType, PersonDetailsView } from "../../interfaces";
11 import { commentsToFlatNodes, setupTippy } from "../../utils";
12 import { CommentNodes } from "../comment/comment-nodes";
13 import { Paginator } from "../common/paginator";
14 import { PostListing } from "../post/post-listing";
16 interface PersonDetailsProps {
17 personRes: GetPersonDetailsResponse;
18 admins: PersonViewSafe[];
22 enableDownvotes: boolean;
24 view: PersonDetailsView;
25 onPageChange(page: number): number | any;
35 view: CommentView | PostView;
40 export class PersonDetails extends Component<PersonDetailsProps, any> {
41 constructor(props: any, context: any) {
42 super(props, context);
43 this.handlePageChange = this.handlePageChange.bind(this);
51 // componentDidUpdate(lastProps: UserDetailsProps) {
52 // for (const key of Object.keys(lastProps)) {
53 // if (lastProps[key] !== this.props[key]) {
54 // this.fetchUserData();
63 {this.viewSelector(this.props.view)}
65 <Paginator page={this.props.page} onChange={this.handlePageChange} />
70 viewSelector(view: PersonDetailsView) {
72 view === PersonDetailsView.Overview ||
73 view === PersonDetailsView.Saved
75 return this.overview();
76 } else if (view === PersonDetailsView.Comments) {
77 return this.comments();
78 } else if (view === PersonDetailsView.Posts) {
85 renderItemType(i: ItemType) {
87 case ItemEnum.Comment: {
88 let c = i.view as CommentView;
92 nodes={[{ comment_view: c, children: [], depth: 0 }]}
93 viewType={CommentViewType.Flat}
94 admins={Some(this.props.admins)}
96 maxCommentsShown={None}
101 enableDownvotes={this.props.enableDownvotes}
105 case ItemEnum.Post: {
106 let p = i.view as PostView;
111 admins={Some(this.props.admins)}
115 enableDownvotes={this.props.enableDownvotes}
116 enableNsfw={this.props.enableNsfw}
127 let comments: ItemType[] = this.props.personRes.comments.map(r => ({
129 type_: ItemEnum.Comment,
131 published: r.comment.published,
132 score: r.counts.score,
134 let posts: ItemType[] = this.props.personRes.posts.map(r => ({
136 type_: ItemEnum.Post,
138 published: r.post.published,
139 score: r.counts.score,
142 let combined = [...comments, ...posts];
145 if (this.props.sort === SortType.New) {
146 combined.sort((a, b) => b.published.localeCompare(a.published));
148 combined.sort((a, b) => b.score - a.score);
154 this.renderItemType(i),
155 <hr key={i.type_} className="my-3" />,
165 nodes={commentsToFlatNodes(this.props.personRes.comments)}
166 viewType={CommentViewType.Flat}
167 admins={Some(this.props.admins)}
169 maxCommentsShown={None}
173 enableDownvotes={this.props.enableDownvotes}
182 {this.props.personRes.posts.map(post => (
186 admins={Some(this.props.admins)}
190 enableDownvotes={this.props.enableDownvotes}
191 enableNsfw={this.props.enableNsfw}
193 <hr className="my-3" />
200 handlePageChange(val: number) {
201 this.props.onPageChange(val);