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);
50 // componentDidUpdate(lastProps: UserDetailsProps) {
51 // for (const key of Object.keys(lastProps)) {
52 // if (lastProps[key] !== this.props[key]) {
53 // this.fetchUserData();
62 {this.viewSelector(this.props.view)}
64 <Paginator page={this.props.page} onChange={this.handlePageChange} />
69 viewSelector(view: PersonDetailsView) {
71 view === PersonDetailsView.Overview ||
72 view === PersonDetailsView.Saved
74 return this.overview();
75 } else if (view === PersonDetailsView.Comments) {
76 return this.comments();
77 } else if (view === PersonDetailsView.Posts) {
84 renderItemType(i: ItemType) {
86 case ItemEnum.Comment: {
87 let c = i.view as CommentView;
91 nodes={[{ comment_view: c }]}
92 admins={this.props.admins}
97 enableDownvotes={this.props.enableDownvotes}
101 case ItemEnum.Post: {
102 let p = i.view as PostView;
107 admins={this.props.admins}
109 enableDownvotes={this.props.enableDownvotes}
110 enableNsfw={this.props.enableNsfw}
121 let comments: ItemType[] = this.props.personRes.comments.map(r => ({
123 type_: ItemEnum.Comment,
125 published: r.comment.published,
126 score: r.counts.score,
128 let posts: ItemType[] = this.props.personRes.posts.map(r => ({
130 type_: ItemEnum.Post,
132 published: r.post.published,
133 score: r.counts.score,
136 let combined = [...comments, ...posts];
139 if (this.props.sort === SortType.New) {
140 combined.sort((a, b) => b.published.localeCompare(a.published));
142 combined.sort((a, b) => b.score - a.score);
147 {combined.map(i => [this.renderItemType(i), <hr class="my-3" />])}
156 nodes={commentsToFlatNodes(this.props.personRes.comments)}
157 admins={this.props.admins}
161 enableDownvotes={this.props.enableDownvotes}
170 {this.props.personRes.posts.map(post => (
174 admins={this.props.admins}
176 enableDownvotes={this.props.enableDownvotes}
177 enableNsfw={this.props.enableNsfw}
186 handlePageChange(val: number) {
187 this.props.onPageChange(val);