1 import { Component, linkEvent } from 'inferno';
2 import { i18n } from '../i18next';
3 import { Post, Comment, SortType, UserDetailsResponse } from 'lemmy-js-client';
4 import { UserDetailsView } from '../interfaces';
5 import { commentsToFlatNodes, setupTippy } from '../utils';
6 import { PostListing } from './post-listing';
7 import { CommentNodes } from './comment-nodes';
9 interface UserDetailsProps {
10 userRes: UserDetailsResponse;
14 enableDownvotes: boolean;
16 view: UserDetailsView;
17 onPageChange(page: number): number | any;
20 interface UserDetailsState {}
22 export class UserDetails extends Component<UserDetailsProps, UserDetailsState> {
23 constructor(props: any, context: any) {
24 super(props, context);
33 // componentDidUpdate(lastProps: UserDetailsProps) {
34 // for (const key of Object.keys(lastProps)) {
35 // if (lastProps[key] !== this.props[key]) {
36 // this.fetchUserData();
45 {this.viewSelector(this.props.view)}
51 viewSelector(view: UserDetailsView) {
52 if (view === UserDetailsView.Overview || view === UserDetailsView.Saved) {
53 return this.overview();
54 } else if (view === UserDetailsView.Comments) {
55 return this.comments();
56 } else if (view === UserDetailsView.Posts) {
64 const comments = this.props.userRes.comments.map((c: Comment) => {
65 return { type: 'comments', data: c };
67 const posts = this.props.userRes.posts.map((p: Post) => {
68 return { type: 'posts', data: p };
71 const combined: { type: string; data: Comment | Post }[] = [
77 if (this.props.sort === SortType.New) {
78 combined.sort((a, b) => b.data.published.localeCompare(a.data.published));
80 combined.sort((a, b) => b.data.score - a.data.score);
88 {i.type === 'posts' ? (
91 key={(i.data as Post).id}
93 admins={this.props.userRes.admins}
95 enableDownvotes={this.props.enableDownvotes}
96 enableNsfw={this.props.enableNsfw}
100 key={(i.data as Comment).id}
101 nodes={[{ comment: i.data as Comment }]}
102 admins={this.props.userRes.admins}
107 enableDownvotes={this.props.enableDownvotes}
122 nodes={commentsToFlatNodes(this.props.userRes.comments)}
123 admins={this.props.userRes.admins}
127 enableDownvotes={this.props.enableDownvotes}
136 {this.props.userRes.posts.map(post => (
141 admins={this.props.userRes.admins}
143 enableDownvotes={this.props.enableDownvotes}
144 enableNsfw={this.props.enableNsfw}
156 {this.props.page > 1 && (
158 class="btn btn-secondary mr-1"
159 onClick={linkEvent(this, this.prevPage)}
164 {this.props.userRes.comments.length + this.props.userRes.posts.length >
167 class="btn btn-secondary"
168 onClick={linkEvent(this, this.nextPage)}
177 nextPage(i: UserDetails) {
178 i.props.onPageChange(i.props.page + 1);
181 prevPage(i: UserDetails) {
182 i.props.onPageChange(i.props.page - 1);