1 import { Component, linkEvent } from "inferno";
2 import { i18n } from "../i18next";
7 GetPersonDetailsResponse,
9 } from "lemmy-js-client";
10 import { PersonDetailsView } from "../interfaces";
11 import { commentsToFlatNodes, setupTippy } from "../utils";
12 import { PostListing } from "./post-listing";
13 import { CommentNodes } from "./comment-nodes";
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);
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)}
68 viewSelector(view: PersonDetailsView) {
70 view === PersonDetailsView.Overview ||
71 view === PersonDetailsView.Saved
73 return this.overview();
74 } else if (view === PersonDetailsView.Comments) {
75 return this.comments();
76 } else if (view === PersonDetailsView.Posts) {
83 renderItemType(i: ItemType) {
85 case ItemEnum.Comment: {
86 let c = i.view as CommentView;
90 nodes={[{ comment_view: c }]}
91 admins={this.props.admins}
96 enableDownvotes={this.props.enableDownvotes}
100 case ItemEnum.Post: {
101 let p = i.view as PostView;
106 admins={this.props.admins}
108 enableDownvotes={this.props.enableDownvotes}
109 enableNsfw={this.props.enableNsfw}
120 let comments: ItemType[] = this.props.personRes.comments.map(r => ({
122 type_: ItemEnum.Comment,
124 published: r.comment.published,
125 score: r.counts.score,
127 let posts: ItemType[] = this.props.personRes.posts.map(r => ({
129 type_: ItemEnum.Post,
131 published: r.post.published,
132 score: r.counts.score,
135 let combined = [...comments, ...posts];
138 if (this.props.sort === SortType.New) {
139 combined.sort((a, b) => b.published.localeCompare(a.published));
141 combined.sort((a, b) => b.score - a.score);
146 {combined.map(i => [this.renderItemType(i), <hr class="my-3" />])}
155 nodes={commentsToFlatNodes(this.props.personRes.comments)}
156 admins={this.props.admins}
160 enableDownvotes={this.props.enableDownvotes}
169 {this.props.personRes.posts.map(post => (
173 admins={this.props.admins}
175 enableDownvotes={this.props.enableDownvotes}
176 enableNsfw={this.props.enableNsfw}
188 {this.props.page > 1 && (
190 class="btn btn-secondary mr-1"
191 onClick={linkEvent(this, this.prevPage)}
196 {this.props.personRes.comments.length +
197 this.props.personRes.posts.length >
200 class="btn btn-secondary"
201 onClick={linkEvent(this, this.nextPage)}
210 nextPage(i: PersonDetails) {
211 i.props.onPageChange(i.props.page + 1);
214 prevPage(i: PersonDetails) {
215 i.props.onPageChange(i.props.page - 1);