import autosize from "autosize"; import { Component, linkEvent } from "inferno"; import { BannedPersonsResponse, GetBannedPersons, GetSiteConfig, GetSiteConfigResponse, GetSiteResponse, PersonViewSafe, SaveSiteConfig, SiteResponse, UserOperation, } from "lemmy-js-client"; import { Subscription } from "rxjs"; import { i18n } from "../../i18next"; import { InitialFetchRequest } from "../../interfaces"; import { WebSocketService } from "../../services"; import { authField, capitalizeFirstLetter, isBrowser, randomStr, setIsoData, toast, wsClient, wsJsonToRes, wsSubscribe, wsUserOp, } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import { PersonListing } from "../person/person-listing"; import { SiteForm } from "./site-form"; interface AdminSettingsState { siteRes: GetSiteResponse; siteConfigRes: GetSiteConfigResponse; siteConfigHjson: string; loading: boolean; banned: PersonViewSafe[]; siteConfigLoading: boolean; leaveAdminTeamLoading: boolean; } export class AdminSettings extends Component { private siteConfigTextAreaId = `site-config-${randomStr()}`; private isoData = setIsoData(this.context); private subscription: Subscription; private emptyState: AdminSettingsState = { siteRes: this.isoData.site_res, siteConfigHjson: null, siteConfigRes: { config_hjson: null, }, banned: [], loading: true, siteConfigLoading: null, leaveAdminTeamLoading: null, }; constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); // Only fetch the data if coming from another route if (this.isoData.path == this.context.router.route.match.url) { this.state.siteConfigRes = this.isoData.routeData[0]; this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson; this.state.banned = this.isoData.routeData[1].banned; this.state.siteConfigLoading = false; this.state.loading = false; } else { WebSocketService.Instance.send( wsClient.getSiteConfig({ auth: authField(), }) ); WebSocketService.Instance.send( wsClient.getBannedPersons({ auth: authField(), }) ); } } static fetchInitialData(req: InitialFetchRequest): Promise[] { let promises: Promise[] = []; let siteConfigForm: GetSiteConfig = { auth: req.auth }; promises.push(req.client.getSiteConfig(siteConfigForm)); let bannedPersonsForm: GetBannedPersons = { auth: req.auth }; promises.push(req.client.getBannedPersons(bannedPersonsForm)); return promises; } componentDidMount() { if (isBrowser()) { var textarea: any = document.getElementById(this.siteConfigTextAreaId); autosize(textarea); } } componentWillUnmount() { if (isBrowser()) { this.subscription.unsubscribe(); } } get documentTitle(): string { return `${i18n.t("admin_settings")} - ${ this.state.siteRes.site_view.site.name }`; } render() { return (
{this.state.loading ? (
) : (
{this.state.siteRes.site_view.site.id && ( )} {this.admins()} {this.bannedUsers()}
{this.adminSettings()}
)}
); } admins() { return ( <>
{capitalizeFirstLetter(i18n.t("admins"))}
    {this.state.siteRes.admins.map(admin => (
  • ))}
{this.leaveAdmin()} ); } leaveAdmin() { return ( ); } bannedUsers() { return ( <>
{i18n.t("banned_users")}
    {this.state.banned.map(banned => (
  • ))}
); } adminSettings() { return (
{i18n.t("admin_settings")}