2022-06-21 21:42:29 +00:00
|
|
|
import { None, Some } from "@sniptt/monads/build";
|
2021-07-16 19:40:56 +00:00
|
|
|
import { Component } from "inferno";
|
2020-12-24 01:58:27 +00:00
|
|
|
import {
|
|
|
|
CommentView,
|
2021-03-15 18:09:31 +00:00
|
|
|
GetPersonDetailsResponse,
|
2022-09-22 15:14:58 +00:00
|
|
|
Language,
|
2021-03-15 18:09:31 +00:00
|
|
|
PersonViewSafe,
|
2021-07-17 20:42:55 +00:00
|
|
|
PostView,
|
|
|
|
SortType,
|
2021-02-22 02:39:04 +00:00
|
|
|
} from "lemmy-js-client";
|
2022-07-30 13:28:08 +00:00
|
|
|
import { CommentViewType, PersonDetailsView } from "../../interfaces";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { commentsToFlatNodes, setupTippy } from "../../utils";
|
|
|
|
import { CommentNodes } from "../comment/comment-nodes";
|
|
|
|
import { Paginator } from "../common/paginator";
|
|
|
|
import { PostListing } from "../post/post-listing";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
interface PersonDetailsProps {
|
|
|
|
personRes: GetPersonDetailsResponse;
|
|
|
|
admins: PersonViewSafe[];
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages: Language[];
|
2020-09-06 16:15:25 +00:00
|
|
|
page: number;
|
|
|
|
limit: number;
|
|
|
|
sort: SortType;
|
|
|
|
enableDownvotes: boolean;
|
|
|
|
enableNsfw: boolean;
|
2021-03-15 18:09:31 +00:00
|
|
|
view: PersonDetailsView;
|
2020-09-06 16:15:25 +00:00
|
|
|
onPageChange(page: number): number | any;
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
enum ItemEnum {
|
|
|
|
Comment,
|
|
|
|
Post,
|
|
|
|
}
|
|
|
|
type ItemType = {
|
|
|
|
id: number;
|
|
|
|
type_: ItemEnum;
|
|
|
|
view: CommentView | PostView;
|
|
|
|
published: string;
|
|
|
|
score: number;
|
|
|
|
};
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
export class PersonDetails extends Component<PersonDetailsProps, any> {
|
2020-09-06 16:15:25 +00:00
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
2021-07-16 19:40:56 +00:00
|
|
|
this.handlePageChange = this.handlePageChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
setupTippy();
|
|
|
|
}
|
|
|
|
|
2020-09-09 00:48:17 +00:00
|
|
|
// TODO wut?
|
|
|
|
// componentDidUpdate(lastProps: UserDetailsProps) {
|
|
|
|
// for (const key of Object.keys(lastProps)) {
|
|
|
|
// if (lastProps[key] !== this.props[key]) {
|
|
|
|
// this.fetchUserData();
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.viewSelector(this.props.view)}
|
2021-07-16 19:40:56 +00:00
|
|
|
|
|
|
|
<Paginator page={this.props.page} onChange={this.handlePageChange} />
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
viewSelector(view: PersonDetailsView) {
|
|
|
|
if (
|
|
|
|
view === PersonDetailsView.Overview ||
|
|
|
|
view === PersonDetailsView.Saved
|
|
|
|
) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return this.overview();
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (view === PersonDetailsView.Comments) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return this.comments();
|
2021-03-15 18:09:31 +00:00
|
|
|
} else if (view === PersonDetailsView.Posts) {
|
2020-09-06 16:15:25 +00:00
|
|
|
return this.posts();
|
2020-09-09 00:48:17 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
renderItemType(i: ItemType) {
|
|
|
|
switch (i.type_) {
|
2021-02-22 02:24:09 +00:00
|
|
|
case ItemEnum.Comment: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let c = i.view as CommentView;
|
|
|
|
return (
|
|
|
|
<CommentNodes
|
|
|
|
key={i.id}
|
2022-07-30 13:28:08 +00:00
|
|
|
nodes={[{ comment_view: c, children: [], depth: 0 }]}
|
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
admins={Some(this.props.admins)}
|
|
|
|
moderators={None}
|
|
|
|
maxCommentsShown={None}
|
2020-12-24 01:58:27 +00:00
|
|
|
noBorder
|
|
|
|
noIndent
|
|
|
|
showCommunity
|
|
|
|
showContext
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
|
|
|
case ItemEnum.Post: {
|
2020-12-24 01:58:27 +00:00
|
|
|
let p = i.view as PostView;
|
|
|
|
return (
|
|
|
|
<PostListing
|
|
|
|
key={i.id}
|
|
|
|
post_view={p}
|
2022-06-21 21:42:29 +00:00
|
|
|
admins={Some(this.props.admins)}
|
|
|
|
duplicates={None}
|
|
|
|
moderators={None}
|
2020-12-24 01:58:27 +00:00
|
|
|
showCommunity
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2020-12-24 01:58:27 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-02-22 02:24:09 +00:00
|
|
|
}
|
2020-12-24 01:58:27 +00:00
|
|
|
default:
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
overview() {
|
2020-12-24 01:58:27 +00:00
|
|
|
let id = 0;
|
2021-03-15 18:09:31 +00:00
|
|
|
let comments: ItemType[] = this.props.personRes.comments.map(r => ({
|
2020-12-24 01:58:27 +00:00
|
|
|
id: id++,
|
|
|
|
type_: ItemEnum.Comment,
|
|
|
|
view: r,
|
|
|
|
published: r.comment.published,
|
|
|
|
score: r.counts.score,
|
|
|
|
}));
|
2021-03-15 18:09:31 +00:00
|
|
|
let posts: ItemType[] = this.props.personRes.posts.map(r => ({
|
2020-12-24 01:58:27 +00:00
|
|
|
id: id++,
|
2020-12-26 03:28:05 +00:00
|
|
|
type_: ItemEnum.Post,
|
2020-12-24 01:58:27 +00:00
|
|
|
view: r,
|
|
|
|
published: r.post.published,
|
|
|
|
score: r.counts.score,
|
|
|
|
}));
|
|
|
|
|
|
|
|
let combined = [...comments, ...posts];
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
// Sort it
|
|
|
|
if (this.props.sort === SortType.New) {
|
2020-12-24 01:58:27 +00:00
|
|
|
combined.sort((a, b) => b.published.localeCompare(a.published));
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2020-12-24 01:58:27 +00:00
|
|
|
combined.sort((a, b) => b.score - a.score);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2022-09-22 15:03:35 +00:00
|
|
|
{combined.map(i => [
|
|
|
|
this.renderItemType(i),
|
|
|
|
<hr key={i.type_} className="my-3" />,
|
|
|
|
])}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
comments() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<CommentNodes
|
2021-03-15 18:09:31 +00:00
|
|
|
nodes={commentsToFlatNodes(this.props.personRes.comments)}
|
2022-07-30 13:28:08 +00:00
|
|
|
viewType={CommentViewType.Flat}
|
2022-06-21 21:42:29 +00:00
|
|
|
admins={Some(this.props.admins)}
|
|
|
|
moderators={None}
|
|
|
|
maxCommentsShown={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
noIndent
|
|
|
|
showCommunity
|
|
|
|
showContext
|
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
posts() {
|
|
|
|
return (
|
|
|
|
<div>
|
2021-03-15 18:09:31 +00:00
|
|
|
{this.props.personRes.posts.map(post => (
|
2020-09-06 16:15:25 +00:00
|
|
|
<>
|
|
|
|
<PostListing
|
2020-12-24 01:58:27 +00:00
|
|
|
post_view={post}
|
2022-06-21 21:42:29 +00:00
|
|
|
admins={Some(this.props.admins)}
|
2020-09-06 16:15:25 +00:00
|
|
|
showCommunity
|
2022-06-21 21:42:29 +00:00
|
|
|
duplicates={None}
|
|
|
|
moderators={None}
|
2020-09-06 16:15:25 +00:00
|
|
|
enableDownvotes={this.props.enableDownvotes}
|
|
|
|
enableNsfw={this.props.enableNsfw}
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={this.props.allLanguages}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<hr className="my-3" />
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:40:56 +00:00
|
|
|
handlePageChange(val: number) {
|
|
|
|
this.props.onPageChange(val);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|