1 import { Component } from "inferno";
4 GetPersonDetailsResponse,
8 } from "lemmy-js-client";
9 import { PersonDetailsView } from "../../interfaces";
10 import { commentsToFlatNodes, setupTippy } from "../../utils";
11 import { CommentNodes } from "../comment/comment-nodes";
12 import { Paginator } from "../common/paginator";
13 import { PostListing } from "../post/post-listing";
15 interface PersonDetailsProps {
16 personRes: GetPersonDetailsResponse;
17 admins: PersonViewSafe[];
21 enableDownvotes: boolean;
23 view: PersonDetailsView;
24 onPageChange(page: number): number | any;
34 view: CommentView | PostView;
39 export class PersonDetails extends Component<PersonDetailsProps, any> {
40 constructor(props: any, context: any) {
41 super(props, context);
42 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 }]}
93 admins={this.props.admins}
98 enableDownvotes={this.props.enableDownvotes}
102 case ItemEnum.Post: {
103 let p = i.view as PostView;
108 admins={this.props.admins}
110 enableDownvotes={this.props.enableDownvotes}
111 enableNsfw={this.props.enableNsfw}
122 let comments: ItemType[] = this.props.personRes.comments.map(r => ({
124 type_: ItemEnum.Comment,
126 published: r.comment.published,
127 score: r.counts.score,
129 let posts: ItemType[] = this.props.personRes.posts.map(r => ({
131 type_: ItemEnum.Post,
133 published: r.post.published,
134 score: r.counts.score,
137 let combined = [...comments, ...posts];
140 if (this.props.sort === SortType.New) {
141 combined.sort((a, b) => b.published.localeCompare(a.published));
143 combined.sort((a, b) => b.score - a.score);
148 {combined.map(i => [this.renderItemType(i), <hr class="my-3" />])}
157 nodes={commentsToFlatNodes(this.props.personRes.comments)}
158 admins={this.props.admins}
162 enableDownvotes={this.props.enableDownvotes}
171 {this.props.personRes.posts.map(post => (
175 admins={this.props.admins}
177 enableDownvotes={this.props.enableDownvotes}
178 enableNsfw={this.props.enableNsfw}
187 handlePageChange(val: number) {
188 this.props.onPageChange(val);