Fixing initial loading of admin page. Fixes #635 (#638)

This commit is contained in:
Dessalines 2022-04-27 15:09:36 -04:00 committed by GitHub
parent 2c97b3d050
commit 2d1111fa74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 19 deletions

View file

@ -35,7 +35,7 @@ import { SiteForm } from "./site-form";
interface AdminSettingsState { interface AdminSettingsState {
siteRes: GetSiteResponse; siteRes: GetSiteResponse;
siteConfigRes: GetSiteConfigResponse; siteConfigRes: GetSiteConfigResponse;
siteConfigForm: SaveSiteConfig; siteConfigHjson: string;
loading: boolean; loading: boolean;
banned: PersonViewSafe[]; banned: PersonViewSafe[];
siteConfigLoading: boolean; siteConfigLoading: boolean;
@ -48,10 +48,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
private subscription: Subscription; private subscription: Subscription;
private emptyState: AdminSettingsState = { private emptyState: AdminSettingsState = {
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
siteConfigForm: { siteConfigHjson: null,
config_hjson: null,
auth: null,
},
siteConfigRes: { siteConfigRes: {
config_hjson: null, config_hjson: null,
}, },
@ -72,13 +69,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
// Only fetch the data if coming from another route // Only fetch the data if coming from another route
if (this.isoData.path == this.context.router.route.match.url) { if (this.isoData.path == this.context.router.route.match.url) {
this.state.siteConfigRes = this.isoData.routeData[0]; this.state.siteConfigRes = this.isoData.routeData[0];
this.state.siteConfigForm.config_hjson = this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.siteConfigRes.config_hjson;
this.state.banned = this.isoData.routeData[1].banned; this.state.banned = this.isoData.routeData[1].banned;
this.state.siteConfigLoading = false; this.state.siteConfigLoading = false;
this.state.loading = false; this.state.loading = false;
} else { } else {
this.state.siteConfigForm.auth = authField();
WebSocketService.Instance.send( WebSocketService.Instance.send(
wsClient.getSiteConfig({ wsClient.getSiteConfig({
auth: authField(), auth: authField(),
@ -211,7 +206,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
<div class="col-12"> <div class="col-12">
<textarea <textarea
id={this.siteConfigTextAreaId} id={this.siteConfigTextAreaId}
value={this.state.siteConfigForm.config_hjson} value={this.state.siteConfigHjson}
onInput={linkEvent(this, this.handleSiteConfigHjsonChange)} onInput={linkEvent(this, this.handleSiteConfigHjsonChange)}
class="form-control text-monospace" class="form-control text-monospace"
rows={3} rows={3}
@ -237,14 +232,16 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
handleSiteConfigSubmit(i: AdminSettings, event: any) { handleSiteConfigSubmit(i: AdminSettings, event: any) {
event.preventDefault(); event.preventDefault();
i.state.siteConfigLoading = true; i.state.siteConfigLoading = true;
WebSocketService.Instance.send( let form: SaveSiteConfig = {
wsClient.saveSiteConfig(i.state.siteConfigForm) config_hjson: this.state.siteConfigHjson,
); auth: authField(),
};
WebSocketService.Instance.send(wsClient.saveSiteConfig(form));
i.setState(i.state); i.setState(i.state);
} }
handleSiteConfigHjsonChange(i: AdminSettings, event: any) { handleSiteConfigHjsonChange(i: AdminSettings, event: any) {
i.state.siteConfigForm.config_hjson = event.target.value; i.state.siteConfigHjson = event.target.value;
i.setState(i.state); i.setState(i.state);
} }
@ -276,8 +273,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
let data = wsJsonToRes<GetSiteConfigResponse>(msg).data; let data = wsJsonToRes<GetSiteConfigResponse>(msg).data;
this.state.siteConfigRes = data; this.state.siteConfigRes = data;
this.state.loading = false; this.state.loading = false;
this.state.siteConfigForm.config_hjson = this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.siteConfigRes.config_hjson;
this.setState(this.state); this.setState(this.state);
var textarea: any = document.getElementById(this.siteConfigTextAreaId); var textarea: any = document.getElementById(this.siteConfigTextAreaId);
autosize(textarea); autosize(textarea);
@ -292,8 +288,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
} else if (op == UserOperation.SaveSiteConfig) { } else if (op == UserOperation.SaveSiteConfig) {
let data = wsJsonToRes<GetSiteConfigResponse>(msg).data; let data = wsJsonToRes<GetSiteConfigResponse>(msg).data;
this.state.siteConfigRes = data; this.state.siteConfigRes = data;
this.state.siteConfigForm.config_hjson = this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.siteConfigRes.config_hjson;
this.state.siteConfigLoading = false; this.state.siteConfigLoading = false;
toast(i18n.t("site_saved")); toast(i18n.t("site_saved"));
this.setState(this.state); this.setState(this.state);

View file

@ -38,7 +38,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
application_question: null, application_question: null,
private_instance: null, private_instance: null,
default_theme: null, default_theme: null,
auth: authField(), auth: authField(false),
}, },
loading: false, loading: false,
themeList: [], themeList: [],
@ -75,7 +75,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
application_question: site.application_question, application_question: site.application_question,
private_instance: site.private_instance, private_instance: site.private_instance,
default_theme: site.default_theme, default_theme: site.default_theme,
auth: authField(), auth: authField(false),
}; };
} }
} }