import { Component, linkEvent } from "inferno"; import { Subscription } from "rxjs"; import { UserOperation, SiteResponse, GetSiteResponse, SaveSiteConfig, GetSiteConfigResponse, GetSiteConfig, } from "lemmy-js-client"; import { WebSocketService } from "../services"; import { wsJsonToRes, capitalizeFirstLetter, toast, randomStr, setIsoData, wsSubscribe, isBrowser, wsUserOp, wsClient, authField, } from "../utils"; import autosize from "autosize"; import { SiteForm } from "./site-form"; import { PersonListing } from "./person-listing"; import { HtmlTags } from "./html-tags"; import { Spinner } from "./icon"; import { i18n } from "../i18next"; import { InitialFetchRequest } from "shared/interfaces"; interface AdminSettingsState { siteRes: GetSiteResponse; siteConfigRes: GetSiteConfigResponse; siteConfigForm: SaveSiteConfig; loading: boolean; siteConfigLoading: 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, siteConfigForm: { config_hjson: null, auth: authField(), }, siteConfigRes: { config_hjson: null, }, loading: true, siteConfigLoading: 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.siteConfigForm.config_hjson = this.state.siteConfigRes.config_hjson; this.state.siteConfigLoading = false; this.state.loading = false; } else { WebSocketService.Instance.send( wsClient.getSiteConfig({ auth: authField(), }) ); } } static fetchInitialData(req: InitialFetchRequest): Promise[] { let form: GetSiteConfig = { auth: req.auth }; return [req.client.getSiteConfig(form)]; } 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"))}
); } bannedUsers() { return ( <>
{i18n.t("banned_users")}
); } adminSettings() { return (
{i18n.t("admin_settings")}