1 import { Component, linkEvent } from 'inferno';
2 import { i18n } from '../i18next';
7 GetUserDetailsResponse,
9 } from 'lemmy-js-client';
10 import { UserDetailsView } from '../interfaces';
11 import { commentsToFlatNodes, setupTippy } from '../utils';
12 import { PostListing } from './post-listing';
13 import { CommentNodes } from './comment-nodes';
15 interface UserDetailsProps {
16 userRes: GetUserDetailsResponse;
17 admins: UserViewSafe[];
21 enableDownvotes: boolean;
23 view: UserDetailsView;
24 onPageChange(page: number): number | any;
27 interface UserDetailsState {}
36 view: CommentView | PostView;
41 export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
42 constructor(props: any, context: any) {
43 super(props, context);
52 // componentDidUpdate(lastProps: UserDetailsProps) {
53 // for (const key of Object.keys(lastProps)) {
54 // if (lastProps[key] !== this.props[key]) {
55 // this.fetchUserData();
64 {this.viewSelector(this.props.view)}
70 viewSelector(view: UserDetailsView) {
71 if (view === UserDetailsView.Overview || view === UserDetailsView.Saved) {
72 return this.overview();
73 } else if (view === UserDetailsView.Comments) {
74 return this.comments();
75 } else if (view === UserDetailsView.Posts) {
82 renderItemType(i: ItemType) {
84 case ItemEnum.Comment:
85 let c = i.view as CommentView;
89 nodes={[{ comment_view: c }]}
90 admins={this.props.admins}
95 enableDownvotes={this.props.enableDownvotes}
99 let p = i.view as PostView;
104 admins={this.props.admins}
106 enableDownvotes={this.props.enableDownvotes}
107 enableNsfw={this.props.enableNsfw}
117 let comments: ItemType[] = this.props.userRes.comments.map(r => ({
119 type_: ItemEnum.Comment,
121 published: r.comment.published,
122 score: r.counts.score,
124 let posts: ItemType[] = this.props.userRes.posts.map(r => ({
126 type_: ItemEnum.Post,
128 published: r.post.published,
129 score: r.counts.score,
132 let combined = [...comments, ...posts];
135 if (this.props.sort === SortType.New) {
136 combined.sort((a, b) => b.published.localeCompare(a.published));
138 combined.sort((a, b) => b.score - a.score);
143 {combined.map(i => [this.renderItemType(i), <hr class="my-3" />])}
152 nodes={commentsToFlatNodes(this.props.userRes.comments)}
153 admins={this.props.admins}
157 enableDownvotes={this.props.enableDownvotes}
166 {this.props.userRes.posts.map(post => (
170 admins={this.props.admins}
172 enableDownvotes={this.props.enableDownvotes}
173 enableNsfw={this.props.enableNsfw}
185 {this.props.page > 1 && (
187 class="btn btn-secondary mr-1"
188 onClick={linkEvent(this, this.prevPage)}
193 {this.props.userRes.comments.length + this.props.userRes.posts.length >
196 class="btn btn-secondary"
197 onClick={linkEvent(this, this.nextPage)}
206 nextPage(i: UserDetails) {
207 i.props.onPageChange(i.props.page + 1);
210 prevPage(i: UserDetails) {
211 i.props.onPageChange(i.props.page - 1);