1 import autosize from "autosize";
2 import { Component, linkEvent } from "inferno";
6 GetFederatedInstancesResponse,
13 } from "lemmy-js-client";
14 import { Subscription } from "rxjs";
15 import { i18n } from "../../i18next";
16 import { InitialFetchRequest } from "../../interfaces";
17 import { WebSocketService } from "../../services";
19 capitalizeFirstLetter,
29 import { HtmlTags } from "../common/html-tags";
30 import { Spinner } from "../common/icon";
31 import Tabs from "../common/tabs";
32 import { PersonListing } from "../person/person-listing";
33 import { EmojiForm } from "./emojis-form";
34 import RateLimitForm from "./rate-limit-form";
35 import { SiteForm } from "./site-form";
36 import { TaglineForm } from "./tagline-form";
38 interface AdminSettingsState {
39 siteRes: GetSiteResponse;
40 instancesRes?: GetFederatedInstancesResponse;
43 leaveAdminTeamLoading: boolean;
46 export class AdminSettings extends Component<any, AdminSettingsState> {
47 private siteConfigTextAreaId = `site-config-${randomStr()}`;
48 private isoData = setIsoData(this.context);
49 private subscription?: Subscription;
50 state: AdminSettingsState = {
51 siteRes: this.isoData.site_res,
54 leaveAdminTeamLoading: false,
57 constructor(props: any, context: any) {
58 super(props, context);
60 this.parseMessage = this.parseMessage.bind(this);
61 this.subscription = wsSubscribe(this.parseMessage);
63 // Only fetch the data if coming from another route
64 if (this.isoData.path == this.context.router.route.match.url) {
67 banned: (this.isoData.routeData[0] as BannedPersonsResponse).banned,
68 instancesRes: this.isoData
69 .routeData[1] as GetFederatedInstancesResponse,
73 const cAuth = myAuth();
75 WebSocketService.Instance.send(
76 wsClient.getBannedPersons({
80 WebSocketService.Instance.send(
81 wsClient.getFederatedInstances({ auth: cAuth })
87 static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
88 const promises: Promise<any>[] = [];
90 const auth = req.auth;
92 const bannedPersonsForm: GetBannedPersons = { auth };
93 promises.push(req.client.getBannedPersons(bannedPersonsForm));
94 promises.push(req.client.getFederatedInstances({ auth }));
100 componentDidMount() {
102 var textarea: any = document.getElementById(this.siteConfigTextAreaId);
107 componentWillUnmount() {
109 this.subscription?.unsubscribe();
113 get documentTitle(): string {
114 return `${i18n.t("admin_settings")} - ${
115 this.state.siteRes.site_view.site.name
121 <div className="container-lg">
123 title={this.documentTitle}
124 path={this.context.router.route.match.url}
126 {this.state.loading ? (
135 label: i18n.t("site"),
137 <div className="row">
138 <div className="col-12 col-md-6">
140 siteRes={this.state.siteRes}
141 instancesRes={this.state.instancesRes}
142 showLocal={showLocal(this.isoData)}
145 <div className="col-12 col-md-6">
153 key: "rate_limiting",
154 label: "Rate Limiting",
158 this.state.siteRes.site_view.local_site_rate_limit
160 applicationQuestion={
161 this.state.siteRes.site_view.local_site
162 .application_question
169 label: i18n.t("taglines"),
171 <div className="row">
172 <TaglineForm siteRes={this.state.siteRes} />
178 label: i18n.t("emojis"),
180 <div className="row">
195 <h5>{capitalizeFirstLetter(i18n.t("admins"))}</h5>
196 <ul className="list-unstyled">
197 {this.state.siteRes.admins.map(admin => (
198 <li key={admin.person.id} className="list-inline-item">
199 <PersonListing person={admin.person} />
211 onClick={linkEvent(this, this.handleLeaveAdminTeam)}
212 className="btn btn-danger mb-2"
214 {this.state.leaveAdminTeamLoading ? (
217 i18n.t("leave_admin_team")
226 <h5>{i18n.t("banned_users")}</h5>
227 <ul className="list-unstyled">
228 {this.state.banned.map(banned => (
229 <li key={banned.person.id} className="list-inline-item">
230 <PersonListing person={banned.person} />
238 handleLeaveAdminTeam(i: AdminSettings) {
239 const auth = myAuth();
241 i.setState({ leaveAdminTeamLoading: true });
242 WebSocketService.Instance.send(wsClient.leaveAdmin({ auth }));
246 parseMessage(msg: any) {
247 const op = wsUserOp(msg);
250 toast(i18n.t(msg.error), "danger");
251 this.context.router.history.push("/");
252 this.setState({ loading: false });
254 } else if (op == UserOperation.EditSite) {
255 const data = wsJsonToRes<SiteResponse>(msg);
256 this.setState(s => ((s.siteRes.site_view = data.site_view), s));
257 toast(i18n.t("site_saved"));
258 } else if (op == UserOperation.GetBannedPersons) {
259 const data = wsJsonToRes<BannedPersonsResponse>(msg);
260 this.setState({ banned: data.banned, loading: false });
261 } else if (op == UserOperation.LeaveAdmin) {
262 const data = wsJsonToRes<GetSiteResponse>(msg);
263 this.setState(s => ((s.siteRes.site_view = data.site_view), s));
264 this.setState({ leaveAdminTeamLoading: false });
265 toast(i18n.t("left_admin_team"));
266 this.context.router.history.push("/");
267 } else if (op == UserOperation.GetFederatedInstances) {
268 const data = wsJsonToRes<GetFederatedInstancesResponse>(msg);
269 this.setState({ instancesRes: data });