Removing save and read config hjson. Fixes #695 (#696)

This commit is contained in:
Dessalines 2022-06-23 10:05:56 -04:00 committed by GitHub
parent 46c610990a
commit 75d52f1e4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 114 deletions

View file

@ -77,7 +77,7 @@
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"import-sort-style-module": "^6.0.0",
"lemmy-js-client": "0.17.0-rc.31",
"lemmy-js-client": "0.17.0-rc.32",
"lint-staged": "^12.4.1",
"mini-css-extract-plugin": "^2.6.0",
"node-fetch": "^2.6.1",

View file

@ -171,7 +171,6 @@ export class Community extends Component<any, State> {
componentWillUnmount() {
saveScrollPosition(this.context);
this.subscription.unsubscribe();
window.isoData.path = undefined;
}
static getDerivedStateFromProps(props: any): CommunityProps {

View file

@ -1,16 +1,12 @@
import { None, Option, Some } from "@sniptt/monads";
import { None, Some } from "@sniptt/monads";
import autosize from "autosize";
import { Component, linkEvent } from "inferno";
import {
BannedPersonsResponse,
GetBannedPersons,
GetSiteConfig,
GetSiteConfigResponse,
GetSiteResponse,
PersonViewSafe,
SaveSiteConfig,
SiteResponse,
toUndefined,
UserOperation,
wsJsonToRes,
wsUserOp,
@ -37,29 +33,19 @@ import { SiteForm } from "./site-form";
interface AdminSettingsState {
siteRes: GetSiteResponse;
siteConfigRes: Option<GetSiteConfigResponse>;
siteConfigHjson: Option<string>;
banned: PersonViewSafe[];
loading: boolean;
siteConfigLoading: boolean;
leaveAdminTeamLoading: boolean;
}
export class AdminSettings extends Component<any, AdminSettingsState> {
private siteConfigTextAreaId = `site-config-${randomStr()}`;
private isoData = setIsoData(
this.context,
GetSiteConfigResponse,
BannedPersonsResponse
);
private isoData = setIsoData(this.context, BannedPersonsResponse);
private subscription: Subscription;
private emptyState: AdminSettingsState = {
siteRes: this.isoData.site_res,
siteConfigHjson: None,
siteConfigRes: None,
banned: [],
loading: true,
siteConfigLoading: null,
leaveAdminTeamLoading: null,
};
@ -73,23 +59,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 = Some(
this.isoData.routeData[0] as GetSiteConfigResponse
);
this.state.siteConfigHjson = this.state.siteConfigRes.map(
s => s.config_hjson
);
this.state.banned = (
this.isoData.routeData[1] as BannedPersonsResponse
this.isoData.routeData[0] as BannedPersonsResponse
).banned;
this.state.siteConfigLoading = false;
this.state.loading = false;
} else {
WebSocketService.Instance.send(
wsClient.getSiteConfig({
auth: auth().unwrap(),
})
);
WebSocketService.Instance.send(
wsClient.getBannedPersons({
auth: auth().unwrap(),
@ -101,9 +75,6 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
let promises: Promise<any>[] = [];
let siteConfigForm = new GetSiteConfig({ auth: req.auth.unwrap() });
promises.push(req.client.getSiteConfig(siteConfigForm));
let bannedPersonsForm = new GetBannedPersons({ auth: req.auth.unwrap() });
promises.push(req.client.getBannedPersons(bannedPersonsForm));
@ -155,10 +126,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
),
none: <></>,
})}
</div>
<div class="col-12 col-md-6">
{this.admins()}
{this.bannedUsers()}
</div>
<div class="col-12 col-md-6">{this.adminSettings()}</div>
</div>
)}
</div>
@ -211,60 +183,6 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
);
}
adminSettings() {
return (
<div>
<h5>{i18n.t("admin_settings")}</h5>
<form onSubmit={linkEvent(this, this.handleSiteConfigSubmit)}>
<div class="form-group row">
<label
class="col-12 col-form-label"
htmlFor={this.siteConfigTextAreaId}
>
{i18n.t("site_config")}
</label>
<div class="col-12">
<textarea
id={this.siteConfigTextAreaId}
value={toUndefined(this.state.siteConfigHjson)}
onInput={linkEvent(this, this.handleSiteConfigHjsonChange)}
class="form-control text-monospace"
rows={3}
/>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button type="submit" class="btn btn-secondary mr-2">
{this.state.siteConfigLoading ? (
<Spinner />
) : (
capitalizeFirstLetter(i18n.t("save"))
)}
</button>
</div>
</div>
</form>
</div>
);
}
handleSiteConfigSubmit(i: AdminSettings, event: any) {
event.preventDefault();
i.state.siteConfigLoading = true;
let form = new SaveSiteConfig({
config_hjson: toUndefined(i.state.siteConfigHjson),
auth: auth().unwrap(),
});
WebSocketService.Instance.send(wsClient.saveSiteConfig(form));
i.setState(i.state);
}
handleSiteConfigHjsonChange(i: AdminSettings, event: any) {
i.state.siteConfigHjson = event.target.value;
i.setState(i.state);
}
handleLeaveAdminTeam(i: AdminSettings) {
i.state.leaveAdminTeamLoading = true;
WebSocketService.Instance.send(
@ -290,17 +208,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
} else if (op == UserOperation.GetBannedPersons) {
let data = wsJsonToRes<BannedPersonsResponse>(msg, BannedPersonsResponse);
this.state.banned = data.banned;
this.setState(this.state);
} else if (op == UserOperation.GetSiteConfig) {
let data = wsJsonToRes<GetSiteConfigResponse>(msg, GetSiteConfigResponse);
this.state.siteConfigRes = Some(data);
this.state.loading = false;
this.state.siteConfigHjson = this.state.siteConfigRes.map(
s => s.config_hjson
);
this.setState(this.state);
var textarea: any = document.getElementById(this.siteConfigTextAreaId);
autosize(textarea);
} else if (op == UserOperation.LeaveAdmin) {
let data = wsJsonToRes<GetSiteResponse>(msg, GetSiteResponse);
this.state.siteRes.site_view = data.site_view;
@ -309,15 +218,6 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
toast(i18n.t("left_admin_team"));
this.setState(this.state);
this.context.router.history.push("/");
} else if (op == UserOperation.SaveSiteConfig) {
let data = wsJsonToRes<GetSiteConfigResponse>(msg, GetSiteConfigResponse);
this.state.siteConfigRes = Some(data);
this.state.siteConfigHjson = this.state.siteConfigRes.map(
s => s.config_hjson
);
this.state.siteConfigLoading = false;
toast(i18n.t("site_saved"));
this.setState(this.state);
}
}
}

View file

@ -194,7 +194,6 @@ export class Home extends Component<any, HomeState> {
componentWillUnmount() {
saveScrollPosition(this.context);
this.subscription.unsubscribe();
window.isoData.path = undefined;
}
static getDerivedStateFromProps(props: any): HomeProps {

View file

@ -98,7 +98,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
default_theme: Some(site.default_theme),
default_post_listing_type: Some(site.default_post_listing_type),
legal_information: site.legal_information,
auth: auth(false).unwrap(),
auth: undefined,
});
},
none: void 0,

View file

@ -198,7 +198,6 @@ export class Post extends Component<any, PostState> {
this.subscription.unsubscribe();
document.removeEventListener("scroll", this.commentScrollDebounced);
window.isoData.path = undefined;
saveScrollPosition(this.context);
}

View file

@ -4948,10 +4948,10 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"
lemmy-js-client@0.17.0-rc.31:
version "0.17.0-rc.31"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.31.tgz#373ad2dcbb1305bd82e7fb13704fbdb8d2f1c438"
integrity sha512-hcjFcOxgplffQullf9HuAGv2ko9wWySrnv+s8FWPPpg4EsixuBjXI+Dh7y0GR/KVs6fRmeXn4YBhR2YdJsBc7A==
lemmy-js-client@0.17.0-rc.32:
version "0.17.0-rc.32"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.32.tgz#d67f432f1fffc54c267f915278fe260ec554b018"
integrity sha512-qPLybaesu3GVr1DMStsyCYanW4maxHrqX71UHadFMeuh+aUK8taC3zfsLRK9dlIlSDRS283xd8IZkI6ZlcOVEQ==
levn@^0.4.1:
version "0.4.1"