import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { PersonViewSafe, Site, SiteAggregates } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { mdToHtml, numToSI } from "../../utils"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon } from "../common/icon"; import { PersonListing } from "../person/person-listing"; import { SiteForm } from "./site-form"; interface SiteSidebarProps { site: Site; counts?: SiteAggregates; admins?: PersonViewSafe[]; online?: number; } interface SiteSidebarState { collapsed: boolean; showEdit: boolean; } export class SiteSidebar extends Component { private emptyState: SiteSidebarState = { collapsed: false, showEdit: false, }; constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; this.handleEditCancel = this.handleEditCancel.bind(this); this.handleEditSite = this.handleEditSite.bind(this); } render() { let site = this.props.site; return (
{!this.state.showEdit ? (
{this.siteName()} {this.props.admins && this.adminButtons()}
{!this.state.collapsed && ( <> {this.siteInfo()} )}
) : ( )}
); } siteName() { let site = this.props.site; return ( site.name && (
{site.name}
) ); } siteInfo() { let site = this.props.site; return (
{site.description &&
{site.description}
} {site.sidebar && this.siteSidebar()} {this.props.counts && this.badges()} {this.props.admins && this.admins()}
); } adminButtons() { return ( this.canAdmin && ( ) ); } siteSidebar() { return (
); } admins() { return ( ); } badges() { let counts = this.props.counts; let online = this.props.online; return ( ); } get canAdmin(): boolean { return ( UserService.Instance.myUserInfo && this.props.admins .map(a => a.person.id) .includes(UserService.Instance.myUserInfo.local_user_view.person.id) ); } handleCollapseSidebar(i: SiteSidebar) { i.state.collapsed = !i.state.collapsed; i.setState(i.state); } handleEditClick(i: SiteSidebar) { i.state.showEdit = true; i.setState(i.state); } handleEditSite() { this.state.showEdit = false; this.setState(this.state); } handleEditCancel() { this.state.showEdit = false; this.setState(this.state); } }