1 import { Component, linkEvent } from "inferno";
2 import { PersonView, Site, SiteAggregates } from "lemmy-js-client";
3 import { i18n } from "../../i18next";
4 import { mdToHtml } from "../../utils";
5 import { Badges } from "../common/badges";
6 import { BannerIconHeader } from "../common/banner-icon-header";
7 import { Icon } from "../common/icon";
8 import { PersonListing } from "../person/person-listing";
10 interface SiteSidebarProps {
13 counts?: SiteAggregates;
14 admins?: PersonView[];
18 interface SiteSidebarState {
22 export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
23 state: SiteSidebarState = {
27 constructor(props: any, context: any) {
28 super(props, context);
33 <div className="site-sidebar accordion">
34 <section id="sidebarInfo" className="card border-secondary mb-3">
36 className="card-header d-flex align-items-center"
37 id="sidebarInfoHeader"
40 {!this.state.collapsed && (
41 <BannerIconHeader banner={this.props.site.banner} />
45 {!this.state.collapsed && (
46 <div id="sidebarInfoBody" aria-labelledby="sidebarInfoHeader">
47 <div className="card-body">{this.siteInfo()}</div>
58 <h5 className="mb-0 d-inline">{this.props.site.name}</h5>
59 {!this.props.isMobile && (
62 className="btn btn-sm"
63 onClick={linkEvent(this, this.handleCollapseSidebar)}
65 this.state.collapsed ? i18n.t("expand") : i18n.t("collapse")
68 this.state.collapsed ? i18n.t("expand") : i18n.t("collapse")
70 data-bs-toggle="collapse"
71 data-bs-target="#sidebarInfoBody"
73 aria-controls="sidebarInfoBody"
75 {this.state.collapsed ? (
76 <Icon icon="plus-square" classes="icon-inline" />
78 <Icon icon="minus-square" classes="icon-inline" />
87 const site = this.props.site;
90 {site.description && <h6>{site.description}</h6>}
91 {site.sidebar && this.siteSidebar(site.sidebar)}
92 {this.props.counts && <Badges counts={this.props.counts} />}
93 {this.props.admins && this.admins(this.props.admins)}
98 siteSidebar(sidebar: string) {
100 <div className="md-div" dangerouslySetInnerHTML={mdToHtml(sidebar)} />
104 admins(admins: PersonView[]) {
106 <ul className="mt-1 list-inline small mb-0">
107 <li className="list-inline-item">{i18n.t("admins")}:</li>
109 <li key={av.person.id} className="list-inline-item">
110 <PersonListing person={av.person} />
117 handleCollapseSidebar(i: SiteSidebar) {
118 i.setState({ collapsed: !i.state.collapsed });