import { Component } from "inferno"; import { AddAdmin, AddModToCommunity, BanFromCommunity, BanPerson, BlockPerson, CommentId, CommentView, CreateComment, CreateCommentLike, CreateCommentReport, CreatePostLike, CreatePostReport, DeleteComment, DeletePost, DistinguishComment, EditComment, EditPost, FeaturePost, GetComments, GetPersonDetailsResponse, Language, LockPost, MarkCommentReplyAsRead, MarkPersonMentionAsRead, PersonView, PostView, PurgeComment, PurgePerson, PurgePost, RemoveComment, RemovePost, SaveComment, SavePost, SortType, TransferCommunity, } from "lemmy-js-client"; import { CommentViewType, PersonDetailsView } from "../../interfaces"; import { commentsToFlatNodes, setupTippy } from "../../utils"; import { CommentNodes } from "../comment/comment-nodes"; import { Paginator } from "../common/paginator"; import { PostListing } from "../post/post-listing"; interface PersonDetailsProps { personRes: GetPersonDetailsResponse; finished: Map; admins: PersonView[]; allLanguages: Language[]; siteLanguages: number[]; page: number; limit: number; sort: SortType; enableDownvotes: boolean; enableNsfw: boolean; view: PersonDetailsView; onPageChange(page: number): number | any; onSaveComment(form: SaveComment): void; onCommentReplyRead(form: MarkCommentReplyAsRead): void; onPersonMentionRead(form: MarkPersonMentionAsRead): void; onCreateComment(form: CreateComment): void; onEditComment(form: EditComment): void; onCommentVote(form: CreateCommentLike): void; onBlockPerson(form: BlockPerson): void; onDeleteComment(form: DeleteComment): void; onRemoveComment(form: RemoveComment): void; onDistinguishComment(form: DistinguishComment): void; onAddModToCommunity(form: AddModToCommunity): void; onAddAdmin(form: AddAdmin): void; onBanPersonFromCommunity(form: BanFromCommunity): void; onBanPerson(form: BanPerson): void; onTransferCommunity(form: TransferCommunity): void; onFetchChildren?(form: GetComments): void; onCommentReport(form: CreateCommentReport): void; onPurgePerson(form: PurgePerson): void; onPurgeComment(form: PurgeComment): void; onPostEdit(form: EditPost): void; onPostVote(form: CreatePostLike): void; onPostReport(form: CreatePostReport): void; onLockPost(form: LockPost): void; onDeletePost(form: DeletePost): void; onRemovePost(form: RemovePost): void; onSavePost(form: SavePost): void; onFeaturePost(form: FeaturePost): void; onPurgePost(form: PurgePost): void; } enum ItemEnum { Comment, Post, } type ItemType = { id: number; type_: ItemEnum; view: CommentView | PostView; published: string; score: number; }; export class PersonDetails extends Component { constructor(props: any, context: any) { super(props, context); this.handlePageChange = this.handlePageChange.bind(this); } componentDidMount() { setupTippy(); } render() { return (
{this.viewSelector(this.props.view)}
); } viewSelector(view: PersonDetailsView) { if ( view === PersonDetailsView.Overview || view === PersonDetailsView.Saved ) { return this.overview(); } else if (view === PersonDetailsView.Comments) { return this.comments(); } else if (view === PersonDetailsView.Posts) { return this.posts(); } else { return null; } } renderItemType(i: ItemType) { switch (i.type_) { case ItemEnum.Comment: { const c = i.view as CommentView; return ( ); } case ItemEnum.Post: { const p = i.view as PostView; return ( ); } default: return
; } } overview() { let id = 0; const comments: ItemType[] = this.props.personRes.comments.map(r => ({ id: id++, type_: ItemEnum.Comment, view: r, published: r.comment.published, score: r.counts.score, })); const posts: ItemType[] = this.props.personRes.posts.map(r => ({ id: id++, type_: ItemEnum.Post, view: r, published: r.post.published, score: r.counts.score, })); const combined = [...comments, ...posts]; // Sort it if (this.props.sort === "New") { combined.sort((a, b) => b.published.localeCompare(a.published)); } else { combined.sort((a, b) => Number(b.score - a.score)); } return (
{combined.map(i => [ this.renderItemType(i),
, ])}
); } comments() { return (
); } posts() { return (
{this.props.personRes.posts.map(post => ( <>
))}
); } handlePageChange(val: number) { this.props.onPageChange(val); } }