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' ? (
90 key={(i.data as Post).id}
92 admins={this.props.userRes.admins}
94 enableDownvotes={this.props.enableDownvotes}
95 enableNsfw={this.props.enableNsfw}
99 key={(i.data as Comment).id}
100 nodes={[{ comment: i.data as Comment }]}
101 admins={this.props.userRes.admins}
106 enableDownvotes={this.props.enableDownvotes}
121 nodes={commentsToFlatNodes(this.props.userRes.comments)}
122 admins={this.props.userRes.admins}
126 enableDownvotes={this.props.enableDownvotes}
135 {this.props.userRes.posts.map(post => (
139 admins={this.props.userRes.admins}
141 enableDownvotes={this.props.enableDownvotes}
142 enableNsfw={this.props.enableNsfw}
154 {this.props.page > 1 && (
156 class="btn btn-secondary mr-1"
157 onClick={linkEvent(this, this.prevPage)}
162 {this.props.userRes.comments.length + this.props.userRes.posts.length >
165 class="btn btn-secondary"
166 onClick={linkEvent(this, this.nextPage)}
175 nextPage(i: UserDetails) {
176 i.props.onPageChange(i.props.page + 1);
179 prevPage(i: UserDetails) {
180 i.props.onPageChange(i.props.page - 1);