mirror of https://github.com/LemmyNet/lemmy-ui.git
parent
46c610990a
commit
75d52f1e4e
|
@ -77,7 +77,7 @@
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"husky": "^7.0.4",
|
"husky": "^7.0.4",
|
||||||
"import-sort-style-module": "^6.0.0",
|
"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",
|
"lint-staged": "^12.4.1",
|
||||||
"mini-css-extract-plugin": "^2.6.0",
|
"mini-css-extract-plugin": "^2.6.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|
|
@ -171,7 +171,6 @@ export class Community extends Component<any, State> {
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
saveScrollPosition(this.context);
|
saveScrollPosition(this.context);
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
window.isoData.path = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: any): CommunityProps {
|
static getDerivedStateFromProps(props: any): CommunityProps {
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
import { None, Option, Some } from "@sniptt/monads";
|
import { None, Some } from "@sniptt/monads";
|
||||||
import autosize from "autosize";
|
import autosize from "autosize";
|
||||||
import { Component, linkEvent } from "inferno";
|
import { Component, linkEvent } from "inferno";
|
||||||
import {
|
import {
|
||||||
BannedPersonsResponse,
|
BannedPersonsResponse,
|
||||||
GetBannedPersons,
|
GetBannedPersons,
|
||||||
GetSiteConfig,
|
|
||||||
GetSiteConfigResponse,
|
|
||||||
GetSiteResponse,
|
GetSiteResponse,
|
||||||
PersonViewSafe,
|
PersonViewSafe,
|
||||||
SaveSiteConfig,
|
|
||||||
SiteResponse,
|
SiteResponse,
|
||||||
toUndefined,
|
|
||||||
UserOperation,
|
UserOperation,
|
||||||
wsJsonToRes,
|
wsJsonToRes,
|
||||||
wsUserOp,
|
wsUserOp,
|
||||||
|
@ -37,29 +33,19 @@ import { SiteForm } from "./site-form";
|
||||||
|
|
||||||
interface AdminSettingsState {
|
interface AdminSettingsState {
|
||||||
siteRes: GetSiteResponse;
|
siteRes: GetSiteResponse;
|
||||||
siteConfigRes: Option<GetSiteConfigResponse>;
|
|
||||||
siteConfigHjson: Option<string>;
|
|
||||||
banned: PersonViewSafe[];
|
banned: PersonViewSafe[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
siteConfigLoading: boolean;
|
|
||||||
leaveAdminTeamLoading: boolean;
|
leaveAdminTeamLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AdminSettings extends Component<any, AdminSettingsState> {
|
export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
private siteConfigTextAreaId = `site-config-${randomStr()}`;
|
private siteConfigTextAreaId = `site-config-${randomStr()}`;
|
||||||
private isoData = setIsoData(
|
private isoData = setIsoData(this.context, BannedPersonsResponse);
|
||||||
this.context,
|
|
||||||
GetSiteConfigResponse,
|
|
||||||
BannedPersonsResponse
|
|
||||||
);
|
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
private emptyState: AdminSettingsState = {
|
private emptyState: AdminSettingsState = {
|
||||||
siteRes: this.isoData.site_res,
|
siteRes: this.isoData.site_res,
|
||||||
siteConfigHjson: None,
|
|
||||||
siteConfigRes: None,
|
|
||||||
banned: [],
|
banned: [],
|
||||||
loading: true,
|
loading: true,
|
||||||
siteConfigLoading: null,
|
|
||||||
leaveAdminTeamLoading: null,
|
leaveAdminTeamLoading: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,23 +59,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 = Some(
|
|
||||||
this.isoData.routeData[0] as GetSiteConfigResponse
|
|
||||||
);
|
|
||||||
this.state.siteConfigHjson = this.state.siteConfigRes.map(
|
|
||||||
s => s.config_hjson
|
|
||||||
);
|
|
||||||
this.state.banned = (
|
this.state.banned = (
|
||||||
this.isoData.routeData[1] as BannedPersonsResponse
|
this.isoData.routeData[0] as BannedPersonsResponse
|
||||||
).banned;
|
).banned;
|
||||||
this.state.siteConfigLoading = false;
|
|
||||||
this.state.loading = false;
|
this.state.loading = false;
|
||||||
} else {
|
} else {
|
||||||
WebSocketService.Instance.send(
|
|
||||||
wsClient.getSiteConfig({
|
|
||||||
auth: auth().unwrap(),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
WebSocketService.Instance.send(
|
WebSocketService.Instance.send(
|
||||||
wsClient.getBannedPersons({
|
wsClient.getBannedPersons({
|
||||||
auth: auth().unwrap(),
|
auth: auth().unwrap(),
|
||||||
|
@ -101,9 +75,6 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
static fetchInitialData(req: InitialFetchRequest): Promise<any>[] {
|
||||||
let promises: 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() });
|
let bannedPersonsForm = new GetBannedPersons({ auth: req.auth.unwrap() });
|
||||||
promises.push(req.client.getBannedPersons(bannedPersonsForm));
|
promises.push(req.client.getBannedPersons(bannedPersonsForm));
|
||||||
|
|
||||||
|
@ -155,10 +126,11 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
),
|
),
|
||||||
none: <></>,
|
none: <></>,
|
||||||
})}
|
})}
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
{this.admins()}
|
{this.admins()}
|
||||||
{this.bannedUsers()}
|
{this.bannedUsers()}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-6">{this.adminSettings()}</div>
|
|
||||||
</div>
|
</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) {
|
handleLeaveAdminTeam(i: AdminSettings) {
|
||||||
i.state.leaveAdminTeamLoading = true;
|
i.state.leaveAdminTeamLoading = true;
|
||||||
WebSocketService.Instance.send(
|
WebSocketService.Instance.send(
|
||||||
|
@ -290,17 +208,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
} else if (op == UserOperation.GetBannedPersons) {
|
} else if (op == UserOperation.GetBannedPersons) {
|
||||||
let data = wsJsonToRes<BannedPersonsResponse>(msg, BannedPersonsResponse);
|
let data = wsJsonToRes<BannedPersonsResponse>(msg, BannedPersonsResponse);
|
||||||
this.state.banned = data.banned;
|
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.loading = false;
|
||||||
this.state.siteConfigHjson = this.state.siteConfigRes.map(
|
|
||||||
s => s.config_hjson
|
|
||||||
);
|
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
var textarea: any = document.getElementById(this.siteConfigTextAreaId);
|
|
||||||
autosize(textarea);
|
|
||||||
} else if (op == UserOperation.LeaveAdmin) {
|
} else if (op == UserOperation.LeaveAdmin) {
|
||||||
let data = wsJsonToRes<GetSiteResponse>(msg, GetSiteResponse);
|
let data = wsJsonToRes<GetSiteResponse>(msg, GetSiteResponse);
|
||||||
this.state.siteRes.site_view = data.site_view;
|
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"));
|
toast(i18n.t("left_admin_team"));
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
this.context.router.history.push("/");
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,6 @@ export class Home extends Component<any, HomeState> {
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
saveScrollPosition(this.context);
|
saveScrollPosition(this.context);
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
window.isoData.path = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: any): HomeProps {
|
static getDerivedStateFromProps(props: any): HomeProps {
|
||||||
|
|
|
@ -98,7 +98,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
||||||
default_theme: Some(site.default_theme),
|
default_theme: Some(site.default_theme),
|
||||||
default_post_listing_type: Some(site.default_post_listing_type),
|
default_post_listing_type: Some(site.default_post_listing_type),
|
||||||
legal_information: site.legal_information,
|
legal_information: site.legal_information,
|
||||||
auth: auth(false).unwrap(),
|
auth: undefined,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
none: void 0,
|
none: void 0,
|
||||||
|
|
|
@ -198,7 +198,6 @@ export class Post extends Component<any, PostState> {
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
document.removeEventListener("scroll", this.commentScrollDebounced);
|
document.removeEventListener("scroll", this.commentScrollDebounced);
|
||||||
|
|
||||||
window.isoData.path = undefined;
|
|
||||||
saveScrollPosition(this.context);
|
saveScrollPosition(this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4948,10 +4948,10 @@ lcid@^1.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
invert-kv "^1.0.0"
|
invert-kv "^1.0.0"
|
||||||
|
|
||||||
lemmy-js-client@0.17.0-rc.31:
|
lemmy-js-client@0.17.0-rc.32:
|
||||||
version "0.17.0-rc.31"
|
version "0.17.0-rc.32"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.31.tgz#373ad2dcbb1305bd82e7fb13704fbdb8d2f1c438"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.32.tgz#d67f432f1fffc54c267f915278fe260ec554b018"
|
||||||
integrity sha512-hcjFcOxgplffQullf9HuAGv2ko9wWySrnv+s8FWPPpg4EsixuBjXI+Dh7y0GR/KVs6fRmeXn4YBhR2YdJsBc7A==
|
integrity sha512-qPLybaesu3GVr1DMStsyCYanW4maxHrqX71UHadFMeuh+aUK8taC3zfsLRK9dlIlSDRS283xd8IZkI6ZlcOVEQ==
|
||||||
|
|
||||||
levn@^0.4.1:
|
levn@^0.4.1:
|
||||||
version "0.4.1"
|
version "0.4.1"
|
||||||
|
|
Loading…
Reference in New Issue