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;
34 view: CommentView | PostView;
39 export class UserDetails extends Component<UserDetailsProps, 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: UserDetailsView) {
69 if (view === UserDetailsView.Overview || view === UserDetailsView.Saved) {
70 return this.overview();
71 } else if (view === UserDetailsView.Comments) {
72 return this.comments();
73 } else if (view === UserDetailsView.Posts) {
80 renderItemType(i: ItemType) {
82 case ItemEnum.Comment: {
83 let c = i.view as CommentView;
87 nodes={[{ comment_view: c }]}
88 admins={this.props.admins}
93 enableDownvotes={this.props.enableDownvotes}
98 let p = i.view as PostView;
103 admins={this.props.admins}
105 enableDownvotes={this.props.enableDownvotes}
106 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);