import { None, Option, Some } from "@sniptt/monads"; import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { PersonViewSafe, Site, SiteAggregates } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { amAdmin, 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; showLocal: boolean; counts: Option; admins: Option; online: Option; } 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.isSome() && this.adminButtons()}
{!this.state.collapsed && ( <> {this.siteInfo()} )}
) : ( )}
); } siteName() { let site = this.props.site; return (
{site.name}
); } siteInfo() { let site = this.props.site; return (
{site.description.match({ some: description =>
{description}
, none: <>, })} {site.sidebar.match({ some: sidebar => this.siteSidebar(sidebar), none: <>, })} {this.props.counts.match({ some: counts => this.badges(counts), none: <>, })} {this.props.admins.match({ some: admins => this.admins(admins), none: <>, })}
); } adminButtons() { return ( amAdmin(this.props.admins) && (
) ); } siteSidebar(sidebar: string) { return (
); } admins(admins: PersonViewSafe[]) { return (
  • {i18n.t("admins")}:
  • {admins.map(av => (
  • ))}
); } badges(siteAggregates: SiteAggregates) { let counts = siteAggregates; let online = this.props.online.unwrapOr(1); return (
  • {i18n.t("number_online", { count: online, formattedCount: numToSI(online), })}
  • {i18n.t("number_of_users", { count: counts.users_active_day, formattedCount: numToSI(counts.users_active_day), })}{" "} / {i18n.t("day")}
  • {i18n.t("number_of_users", { count: counts.users_active_week, formattedCount: numToSI(counts.users_active_week), })}{" "} / {i18n.t("week")}
  • {i18n.t("number_of_users", { count: counts.users_active_month, formattedCount: numToSI(counts.users_active_month), })}{" "} / {i18n.t("month")}
  • {i18n.t("number_of_users", { count: counts.users_active_half_year, formattedCount: numToSI(counts.users_active_half_year), })}{" "} / {i18n.t("number_of_months", { count: 6, formattedCount: 6 })}
  • {i18n.t("number_of_users", { count: counts.users, formattedCount: numToSI(counts.users), })}
  • {i18n.t("number_of_communities", { count: counts.communities, formattedCount: numToSI(counts.communities), })}
  • {i18n.t("number_of_posts", { count: counts.posts, formattedCount: numToSI(counts.posts), })}
  • {i18n.t("number_of_comments", { count: counts.comments, formattedCount: numToSI(counts.comments), })}
  • {i18n.t("modlog")}
); } handleCollapseSidebar(i: SiteSidebar) { i.setState({ collapsed: !i.state.collapsed }); } handleEditClick(i: SiteSidebar) { i.setState({ showEdit: true }); } handleEditSite() { this.setState({ showEdit: false }); } handleEditCancel() { this.setState({ showEdit: false }); } }