Skip to content

Commit

Permalink
Fixing initial loading of admin page. Fixes #635 (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Apr 27, 2022
1 parent 2c97b3d commit 2d1111f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
29 changes: 12 additions & 17 deletions src/shared/components/home/admin-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { SiteForm } from "./site-form";
interface AdminSettingsState {
siteRes: GetSiteResponse;
siteConfigRes: GetSiteConfigResponse;
siteConfigForm: SaveSiteConfig;
siteConfigHjson: string;
loading: boolean;
banned: PersonViewSafe[];
siteConfigLoading: boolean;
Expand All @@ -48,10 +48,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
private subscription: Subscription;
private emptyState: AdminSettingsState = {
siteRes: this.isoData.site_res,
siteConfigForm: {
config_hjson: null,
auth: null,
},
siteConfigHjson: null,
siteConfigRes: {
config_hjson: null,
},
Expand All @@ -72,13 +69,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
// 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.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.banned = this.isoData.routeData[1].banned;
this.state.siteConfigLoading = false;
this.state.loading = false;
} else {
this.state.siteConfigForm.auth = authField();
WebSocketService.Instance.send(
wsClient.getSiteConfig({
auth: authField(),
Expand Down Expand Up @@ -211,7 +206,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
<div class="col-12">
<textarea
id={this.siteConfigTextAreaId}
value={this.state.siteConfigForm.config_hjson}
value={this.state.siteConfigHjson}
onInput={linkEvent(this, this.handleSiteConfigHjsonChange)}
class="form-control text-monospace"
rows={3}
Expand All @@ -237,14 +232,16 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
handleSiteConfigSubmit(i: AdminSettings, event: any) {
event.preventDefault();
i.state.siteConfigLoading = true;
WebSocketService.Instance.send(
wsClient.saveSiteConfig(i.state.siteConfigForm)
);
let form: SaveSiteConfig = {
config_hjson: this.state.siteConfigHjson,
auth: authField(),
};
WebSocketService.Instance.send(wsClient.saveSiteConfig(form));
i.setState(i.state);
}

handleSiteConfigHjsonChange(i: AdminSettings, event: any) {
i.state.siteConfigForm.config_hjson = event.target.value;
i.state.siteConfigHjson = event.target.value;
i.setState(i.state);
}

Expand Down Expand Up @@ -276,8 +273,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
let data = wsJsonToRes<GetSiteConfigResponse>(msg).data;
this.state.siteConfigRes = data;
this.state.loading = false;
this.state.siteConfigForm.config_hjson =
this.state.siteConfigRes.config_hjson;
this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.setState(this.state);
var textarea: any = document.getElementById(this.siteConfigTextAreaId);
autosize(textarea);
Expand All @@ -292,8 +288,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
} else if (op == UserOperation.SaveSiteConfig) {
let data = wsJsonToRes<GetSiteConfigResponse>(msg).data;
this.state.siteConfigRes = data;
this.state.siteConfigForm.config_hjson =
this.state.siteConfigRes.config_hjson;
this.state.siteConfigHjson = this.state.siteConfigRes.config_hjson;
this.state.siteConfigLoading = false;
toast(i18n.t("site_saved"));
this.setState(this.state);
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/home/site-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
application_question: null,
private_instance: null,
default_theme: null,
auth: authField(),
auth: authField(false),
},
loading: false,
themeList: [],
Expand Down Expand Up @@ -75,7 +75,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
application_question: site.application_question,
private_instance: site.private_instance,
default_theme: site.default_theme,
auth: authField(),
auth: authField(false),
};
}
}
Expand Down

0 comments on commit 2d1111f

Please sign in to comment.