1 import { Component } from "inferno";
4 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;
19 allLanguages: Language[];
20 siteLanguages: number[];
24 enableDownvotes: boolean;
26 view: PersonDetailsView;
27 onPageChange(page: bigint): bigint | any;
37 view: CommentView | PostView;
42 export class PersonDetails extends Component<PersonDetailsProps, any> {
43 constructor(props: any, context: any) {
44 super(props, context);
45 this.handlePageChange = this.handlePageChange.bind(this);
53 // componentDidUpdate(lastProps: UserDetailsProps) {
54 // for (const key of Object.keys(lastProps)) {
55 // if (lastProps[key] !== this.props[key]) {
56 // this.fetchUserData();
65 {this.viewSelector(this.props.view)}
67 <Paginator page={this.props.page} onChange={this.handlePageChange} />
72 viewSelector(view: PersonDetailsView) {
74 view === PersonDetailsView.Overview ||
75 view === PersonDetailsView.Saved
77 return this.overview();
78 } else if (view === PersonDetailsView.Comments) {
79 return this.comments();
80 } else if (view === PersonDetailsView.Posts) {
87 renderItemType(i: ItemType) {
89 case ItemEnum.Comment: {
90 let c = i.view as CommentView;
94 nodes={[{ comment_view: c, children: [], depth: 0 }]}
95 viewType={CommentViewType.Flat}
96 admins={this.props.admins}
101 enableDownvotes={this.props.enableDownvotes}
102 allLanguages={this.props.allLanguages}
103 siteLanguages={this.props.siteLanguages}
107 case ItemEnum.Post: {
108 let p = i.view as PostView;
113 admins={this.props.admins}
115 enableDownvotes={this.props.enableDownvotes}
116 enableNsfw={this.props.enableNsfw}
117 allLanguages={this.props.allLanguages}
118 siteLanguages={this.props.siteLanguages}
129 let comments: ItemType[] = this.props.personRes.comments.map(r => ({
131 type_: ItemEnum.Comment,
133 published: r.comment.published,
134 score: r.counts.score,
136 let posts: ItemType[] = this.props.personRes.posts.map(r => ({
138 type_: ItemEnum.Post,
140 published: r.post.published,
141 score: r.counts.score,
144 let combined = [...comments, ...posts];
147 if (this.props.sort === "New") {
148 combined.sort((a, b) => b.published.localeCompare(a.published));
150 combined.sort((a, b) => Number(b.score - a.score));
156 this.renderItemType(i),
157 <hr key={i.type_} className="my-3" />,
167 nodes={commentsToFlatNodes(this.props.personRes.comments)}
168 viewType={CommentViewType.Flat}
169 admins={this.props.admins}
173 enableDownvotes={this.props.enableDownvotes}
174 allLanguages={this.props.allLanguages}
175 siteLanguages={this.props.siteLanguages}
184 {this.props.personRes.posts.map(post => (
188 admins={this.props.admins}
190 enableDownvotes={this.props.enableDownvotes}
191 enableNsfw={this.props.enableNsfw}
192 allLanguages={this.props.allLanguages}
193 siteLanguages={this.props.siteLanguages}
195 <hr className="my-3" />
202 handlePageChange(val: bigint) {
203 this.props.onPageChange(val);