Adding new site setup fields.

This commit is contained in:
Dessalines 2022-11-04 20:41:33 -04:00
parent 8fdbaf4499
commit 0c133fe1a6
34 changed files with 1207 additions and 568 deletions

32
dev.dockerfile Normal file
View file

@ -0,0 +1,32 @@
FROM node:alpine as builder
RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache
WORKDIR /usr/src/app
# Cache deps
COPY package.json yarn.lock ./
RUN yarn install --ignore-scripts --prefer-offline --pure-lockfile
# Build
COPY generate_translations.js \
tsconfig.json \
webpack.config.js \
.babelrc \
./
COPY lemmy-translations lemmy-translations
COPY src src
# Set UI version
RUN echo "export const VERSION = 'dev';" > "src/shared/version.ts"
RUN yarn install --ignore-scripts --prefer-offline
RUN yarn build:dev
FROM node:alpine as runner
COPY --from=builder /usr/src/app/dist /app/dist
COPY --from=builder /usr/src/app/node_modules /app/node_modules
EXPOSE 1234
WORKDIR /app
CMD node dist/js/server.js

@ -1 +1 @@
Subproject commit 94b9b5debdaa40facf13a852cb096ef0cbd34ad7 Subproject commit 46f4b3e8676c23d4a8100ce78330eceed7bcf053

View file

@ -24,7 +24,6 @@
"@babel/preset-typescript": "^7.18.6", "@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.18.9", "@babel/runtime": "^7.18.9",
"@sniptt/monads": "^0.5.10", "@sniptt/monads": "^0.5.10",
"@typescript-eslint/parser": "^5.31.0",
"autosize": "^5.0.1", "autosize": "^5.0.1",
"babel-loader": "^8.2.5", "babel-loader": "^8.2.5",
"babel-plugin-inferno": "^6.5.0", "babel-plugin-inferno": "^6.5.0",
@ -48,7 +47,7 @@
"inferno-server": "^8.0.3", "inferno-server": "^8.0.3",
"isomorphic-cookie": "^1.2.4", "isomorphic-cookie": "^1.2.4",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"lemmy-js-client": "0.17.0-rc.46", "lemmy-js-client": "0.17.0-rc.51",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-container": "^3.0.0", "markdown-it-container": "^3.0.0",
"markdown-it-footnote": "^3.0.3", "markdown-it-footnote": "^3.0.3",
@ -82,6 +81,7 @@
"@types/node-fetch": "^2.6.2", "@types/node-fetch": "^2.6.2",
"@types/serialize-javascript": "^5.0.1", "@types/serialize-javascript": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"bootstrap": "^5.2.0", "bootstrap": "^5.2.0",
"bootswatch": "^5.2.0", "bootswatch": "^5.2.0",
"eslint": "^8.20.0", "eslint": "^8.20.0",

View file

@ -24,10 +24,8 @@ export class App extends Component<any, any> {
<> <>
<Provider i18next={i18n}> <Provider i18next={i18n}>
<div> <div>
<Theme defaultTheme={siteView.map(s => s.site.default_theme)} /> <Theme defaultTheme={siteView.local_site.default_theme} />
{siteView {siteView.site.icon.match({
.andThen(s => s.site.icon)
.match({
some: icon => ( some: icon => (
<Helmet> <Helmet>
<link <link

View file

@ -32,9 +32,7 @@ export class Footer extends Component<FooterProps, any> {
{i18n.t("modlog")} {i18n.t("modlog")}
</NavLink> </NavLink>
</li> </li>
{this.props.site.site_view {this.props.site.site_view.local_site.legal_information.isSome() && (
.andThen(s => s.site.legal_information)
.isSome() && (
<li className="nav-item"> <li className="nav-item">
<NavLink className="nav-link" to="/legal"> <NavLink className="nav-link" to="/legal">
{i18n.t("legal_information")} {i18n.t("legal_information")}

View file

@ -90,10 +90,8 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
}) })
); );
if (this.props.siteRes.site_view.isSome()) {
this.fetchUnreads(); this.fetchUnreads();
} }
}
this.requestNotificationPermission(); this.requestNotificationPermission();
@ -144,11 +142,10 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
// TODO class active corresponding to current page // TODO class active corresponding to current page
navbar() { navbar() {
let siteView = this.props.siteRes.site_view;
return ( return (
<nav className="navbar navbar-expand-md navbar-light shadow-sm p-0 px-3"> <nav className="navbar navbar-expand-md navbar-light shadow-sm p-0 px-3">
<div className="container-lg"> <div className="container-lg">
{this.props.siteRes.site_view.match({
some: siteView => (
<NavLink <NavLink
to="/" to="/"
onMouseUp={linkEvent(this, this.handleHideExpandNavbar)} onMouseUp={linkEvent(this, this.handleHideExpandNavbar)}
@ -156,15 +153,11 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
className="d-flex align-items-center navbar-brand mr-md-3" className="d-flex align-items-center navbar-brand mr-md-3"
> >
{siteView.site.icon.match({ {siteView.site.icon.match({
some: icon => some: icon => showAvatars() && <PictrsImage src={icon} icon />,
showAvatars() && <PictrsImage src={icon} icon />,
none: <></>, none: <></>,
})} })}
{siteView.site.name} {siteView.site.name}
</NavLink> </NavLink>
),
none: <></>,
})}
{UserService.Instance.myUserInfo.isSome() && ( {UserService.Instance.myUserInfo.isSome() && (
<> <>
<ul className="navbar-nav ml-auto"> <ul className="navbar-nav ml-auto">

View file

@ -1,10 +1,9 @@
import { Option } from "@sniptt/monads";
import { Component } from "inferno"; import { Component } from "inferno";
import { Helmet } from "inferno-helmet"; import { Helmet } from "inferno-helmet";
import { UserService } from "../../services"; import { UserService } from "../../services";
interface Props { interface Props {
defaultTheme: Option<string>; defaultTheme: string;
} }
export class Theme extends Component<Props> { export class Theme extends Component<Props> {
@ -26,16 +25,13 @@ export class Theme extends Component<Props> {
/> />
</Helmet> </Helmet>
); );
} else if ( } else if (this.props.defaultTheme != "browser") {
this.props.defaultTheme.isSome() &&
this.props.defaultTheme.unwrap() != "browser"
) {
return ( return (
<Helmet> <Helmet>
<link <link
rel="stylesheet" rel="stylesheet"
type="text/css" type="text/css"
href={`/css/themes/${this.props.defaultTheme.unwrap()}.css`} href={`/css/themes/${this.props.defaultTheme}.css`}
/> />
</Helmet> </Helmet>
); );

View file

@ -109,10 +109,9 @@ export class Communities extends Component<any, CommunitiesState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("communities")} - ${
some: siteView => `${i18n.t("communities")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {

View file

@ -272,11 +272,7 @@ export class Community extends Component<any, State> {
get documentTitle(): string { get documentTitle(): string {
return this.state.communityRes.match({ return this.state.communityRes.match({
some: res => some: res =>
this.state.siteRes.site_view.match({ `${res.community_view.community.title} - ${this.state.siteRes.site_view.site.name}`,
some: siteView =>
`${res.community_view.community.title} - ${siteView.site.name}`,
none: "",
}),
none: "", none: "",
}); });
} }

View file

@ -48,10 +48,9 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("create_community")} - ${
some: siteView => `${i18n.t("create_community")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {

View file

@ -1,4 +1,4 @@
import { None, Some } from "@sniptt/monads"; import { None } from "@sniptt/monads";
import autosize from "autosize"; import autosize from "autosize";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { import {
@ -96,10 +96,9 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("admin_settings")} - ${
some: siteView => `${i18n.t("admin_settings")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {
@ -118,15 +117,10 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
description={None} description={None}
image={None} image={None}
/> />
{this.state.siteRes.site_view.match({
some: siteView => (
<SiteForm <SiteForm
site={Some(siteView.site)} siteRes={this.state.siteRes}
showLocal={showLocal(this.isoData)} showLocal={showLocal(this.isoData)}
/> />
),
none: <></>,
})}
</div> </div>
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
{this.admins()} {this.admins()}
@ -201,7 +195,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
return; return;
} else if (op == UserOperation.EditSite) { } else if (op == UserOperation.EditSite) {
let data = wsJsonToRes<SiteResponse>(msg, SiteResponse); let data = wsJsonToRes<SiteResponse>(msg, SiteResponse);
this.setState(s => ((s.siteRes.site_view = Some(data.site_view)), s)); this.setState(s => ((s.siteRes.site_view = data.site_view), s));
toast(i18n.t("site_saved")); toast(i18n.t("site_saved"));
} else if (op == UserOperation.GetBannedPersons) { } else if (op == UserOperation.GetBannedPersons) {
let data = wsJsonToRes<BannedPersonsResponse>(msg, BannedPersonsResponse); let data = wsJsonToRes<BannedPersonsResponse>(msg, BannedPersonsResponse);

View file

@ -131,10 +131,7 @@ export class Home extends Component<any, HomeState> {
listingType: getListingTypeFromProps( listingType: getListingTypeFromProps(
this.props, this.props,
ListingType[ ListingType[
this.isoData.site_res.site_view.match({ this.isoData.site_res.site_view.local_site.default_post_listing_type
some: type_ => type_.site.default_post_listing_type,
none: ListingType.Local,
})
] ]
), ),
dataType: getDataTypeFromProps(this.props), dataType: getDataTypeFromProps(this.props),
@ -199,7 +196,7 @@ export class Home extends Component<any, HomeState> {
componentDidMount() { componentDidMount() {
// This means it hasn't been set up yet // This means it hasn't been set up yet
if (this.state.siteRes.site_view.isNone()) { if (!this.state.siteRes.site_view.local_site.site_setup) {
this.context.router.history.push("/setup"); this.context.router.history.push("/setup");
} }
setupTippy(); setupTippy();
@ -313,13 +310,10 @@ export class Home extends Component<any, HomeState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ let siteView = this.state.siteRes.site_view;
some: siteView => return this.state.siteRes.site_view.site.description.match({
siteView.site.description.match({
some: desc => `${siteView.site.name} - ${desc}`, some: desc => `${siteView.site.name} - ${desc}`,
none: siteView.site.name, none: siteView.site.name,
}),
none: "Lemmy",
}); });
} }
@ -332,7 +326,7 @@ export class Home extends Component<any, HomeState> {
description={None} description={None}
image={None} image={None}
/> />
{this.state.siteRes.site_view.isSome() && ( {this.state.siteRes.site_view.local_site.site_setup && (
<div className="row"> <div className="row">
<main role="main" className="col-12 col-md-8"> <main role="main" className="col-12 col-md-8">
<div className="d-block d-md-none">{this.mobileView()}</div> <div className="d-block d-md-none">{this.mobileView()}</div>
@ -356,6 +350,7 @@ export class Home extends Component<any, HomeState> {
mobileView() { mobileView() {
let siteRes = this.state.siteRes; let siteRes = this.state.siteRes;
let siteView = siteRes.site_view;
return ( return (
<div className="row"> <div className="row">
<div className="col-12"> <div className="col-12">
@ -399,9 +394,7 @@ export class Home extends Component<any, HomeState> {
classes="icon-inline" classes="icon-inline"
/> />
</button> </button>
{this.state.showSidebarMobile && {this.state.showSidebarMobile && (
siteRes.site_view.match({
some: siteView => (
<SiteSidebar <SiteSidebar
site={siteView.site} site={siteView.site}
admins={Some(siteRes.admins)} admins={Some(siteRes.admins)}
@ -409,9 +402,7 @@ export class Home extends Component<any, HomeState> {
online={Some(siteRes.online)} online={Some(siteRes.online)}
showLocal={showLocal(this.isoData)} showLocal={showLocal(this.isoData)}
/> />
), )}
none: <></>,
})}
{this.state.showTrendingMobile && ( {this.state.showTrendingMobile && (
<div className="col-12 card border-secondary mb-3"> <div className="col-12 card border-secondary mb-3">
<div className="card-body">{this.trendingCommunities()}</div> <div className="card-body">{this.trendingCommunities()}</div>
@ -429,6 +420,7 @@ export class Home extends Component<any, HomeState> {
mySidebar() { mySidebar() {
let siteRes = this.state.siteRes; let siteRes = this.state.siteRes;
let siteView = siteRes.site_view;
return ( return (
<div> <div>
{!this.state.loading && ( {!this.state.loading && (
@ -441,8 +433,6 @@ export class Home extends Component<any, HomeState> {
{this.exploreCommunitiesButton()} {this.exploreCommunitiesButton()}
</div> </div>
</div> </div>
{siteRes.site_view.match({
some: siteView => (
<SiteSidebar <SiteSidebar
site={siteView.site} site={siteView.site}
admins={Some(siteRes.admins)} admins={Some(siteRes.admins)}
@ -450,9 +440,6 @@ export class Home extends Component<any, HomeState> {
online={Some(siteRes.online)} online={Some(siteRes.online)}
showLocal={showLocal(this.isoData)} showLocal={showLocal(this.isoData)}
/> />
),
none: <></>,
})}
{this.hasFollows && ( {this.hasFollows && (
<div className="card border-secondary mb-3"> <div className="card border-secondary mb-3">
<div className="card-body">{this.subscribedCommunities()}</div> <div className="card-body">{this.subscribedCommunities()}</div>
@ -749,7 +736,7 @@ export class Home extends Component<any, HomeState> {
this.setState({ trendingCommunities: data.communities }); this.setState({ trendingCommunities: data.communities });
} else if (op == UserOperation.EditSite) { } else if (op == UserOperation.EditSite) {
let data = wsJsonToRes<SiteResponse>(msg, SiteResponse); let data = wsJsonToRes<SiteResponse>(msg, SiteResponse);
this.setState(s => ((s.siteRes.site_view = Some(data.site_view)), s)); this.setState(s => ((s.siteRes.site_view = data.site_view), s));
toast(i18n.t("site_saved")); toast(i18n.t("site_saved"));
} else if (op == UserOperation.GetPosts) { } else if (op == UserOperation.GetPosts) {
let data = wsJsonToRes<GetPostsResponse>(msg, GetPostsResponse); let data = wsJsonToRes<GetPostsResponse>(msg, GetPostsResponse);

View file

@ -21,10 +21,7 @@ export class Instances extends Component<any, InstancesState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("instances")} - ${this.state.siteRes.site_view.site.name}`;
some: siteView => `${i18n.t("instances")} - ${siteView.site.name}`,
none: "",
});
} }
render() { render() {

View file

@ -33,18 +33,11 @@ export class Legal extends Component<any, LegalState> {
description={None} description={None}
image={None} image={None}
/> />
{this.state.siteRes.site_view.match({ {this.state.siteRes.site_view.local_site.legal_information.match({
some: siteView =>
siteView.site.legal_information.match({
some: legal => ( some: legal => (
<div <div className="md-div" dangerouslySetInnerHTML={mdToHtml(legal)} />
className="md-div"
dangerouslySetInnerHTML={mdToHtml(legal)}
/>
), ),
none: <></>, none: <></>,
}),
none: <></>,
})} })}
</div> </div>
); );

View file

@ -69,10 +69,7 @@ export class Login extends Component<any, State> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("login")} - ${this.state.siteRes.site_view.site.name}`;
some: siteView => `${i18n.t("login")} - ${siteView.site.name}`,
none: "",
});
} }
get isLemmyMl(): boolean { get isLemmyMl(): boolean {
@ -194,6 +191,8 @@ export class Login extends Component<any, State> {
let data = wsJsonToRes<LoginResponse>(msg, LoginResponse); let data = wsJsonToRes<LoginResponse>(msg, LoginResponse);
this.setState(this.emptyState); this.setState(this.emptyState);
UserService.Instance.login(data); UserService.Instance.login(data);
this.props.history.push("/");
location.reload();
} else if (op == UserOperation.PasswordReset) { } else if (op == UserOperation.PasswordReset) {
toast(i18n.t("reset_password_mail_sent")); toast(i18n.t("reset_password_mail_sent"));
} else if (op == UserOperation.GetSite) { } else if (op == UserOperation.GetSite) {

View file

@ -2,6 +2,7 @@ import { None, Some } from "@sniptt/monads";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { Helmet } from "inferno-helmet"; import { Helmet } from "inferno-helmet";
import { import {
GetSiteResponse,
LoginResponse, LoginResponse,
Register, Register,
toUndefined, toUndefined,
@ -13,7 +14,7 @@ import { Subscription } from "rxjs";
import { delay, retryWhen, take } from "rxjs/operators"; import { delay, retryWhen, take } from "rxjs/operators";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { UserService, WebSocketService } from "../../services"; import { UserService, WebSocketService } from "../../services";
import { toast, wsClient } from "../../utils"; import { setIsoData, toast, wsClient } from "../../utils";
import { Spinner } from "../common/icon"; import { Spinner } from "../common/icon";
import { SiteForm } from "./site-form"; import { SiteForm } from "./site-form";
@ -21,10 +22,12 @@ interface State {
userForm: Register; userForm: Register;
doneRegisteringUser: boolean; doneRegisteringUser: boolean;
userLoading: boolean; userLoading: boolean;
siteRes: GetSiteResponse;
} }
export class Setup extends Component<any, State> { export class Setup extends Component<any, State> {
private subscription: Subscription; private subscription: Subscription;
private isoData = setIsoData(this.context);
private emptyState: State = { private emptyState: State = {
userForm: new Register({ userForm: new Register({
@ -41,6 +44,7 @@ export class Setup extends Component<any, State> {
}), }),
doneRegisteringUser: UserService.Instance.myUserInfo.isSome(), doneRegisteringUser: UserService.Instance.myUserInfo.isSome(),
userLoading: false, userLoading: false,
siteRes: this.isoData.site_res,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
@ -75,7 +79,7 @@ export class Setup extends Component<any, State> {
{!this.state.doneRegisteringUser ? ( {!this.state.doneRegisteringUser ? (
this.registerUser() this.registerUser()
) : ( ) : (
<SiteForm site={None} showLocal /> <SiteForm siteRes={this.state.siteRes} showLocal />
)} )}
</div> </div>
</div> </div>

View file

@ -111,14 +111,14 @@ export class Signup extends Component<any, State> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ let siteView = this.state.siteRes.site_view;
some: siteView => `${this.titleName(siteView)} - ${siteView.site.name}`, return `${this.titleName(siteView)} - ${siteView.site.name}`;
none: "",
});
} }
titleName(siteView: SiteView): string { titleName(siteView: SiteView): string {
return i18n.t(siteView.site.private_instance ? "apply_to_join" : "sign_up"); return i18n.t(
siteView.local_site.private_instance ? "apply_to_join" : "sign_up"
);
} }
get isLemmyMl(): boolean { get isLemmyMl(): boolean {
@ -144,8 +144,8 @@ export class Signup extends Component<any, State> {
} }
registerForm() { registerForm() {
return this.state.siteRes.site_view.match({ let siteView = this.state.siteRes.site_view;
some: siteView => ( return (
<form onSubmit={linkEvent(this, this.handleRegisterSubmit)}> <form onSubmit={linkEvent(this, this.handleRegisterSubmit)}>
<h5>{this.titleName(siteView)}</h5> <h5>{this.titleName(siteView)}</h5>
@ -192,20 +192,18 @@ export class Signup extends Component<any, State> {
id="register-email" id="register-email"
className="form-control" className="form-control"
placeholder={ placeholder={
siteView.site.require_email_verification siteView.local_site.require_email_verification
? i18n.t("required") ? i18n.t("required")
: i18n.t("optional") : i18n.t("optional")
} }
value={toUndefined(this.state.registerForm.email)} value={toUndefined(this.state.registerForm.email)}
autoComplete="email" autoComplete="email"
onInput={linkEvent(this, this.handleRegisterEmailChange)} onInput={linkEvent(this, this.handleRegisterEmailChange)}
required={siteView.site.require_email_verification} required={siteView.local_site.require_email_verification}
minLength={3} minLength={3}
/> />
{!siteView.site.require_email_verification && {!siteView.local_site.require_email_verification &&
!this.state.registerForm.email !this.state.registerForm.email.map(validEmail).unwrapOr(true) && (
.map(validEmail)
.unwrapOr(true) && (
<div className="mt-2 mb-0 alert alert-warning" role="alert"> <div className="mt-2 mb-0 alert alert-warning" role="alert">
<Icon icon="alert-triangle" classes="icon-inline mr-2" /> <Icon icon="alert-triangle" classes="icon-inline mr-2" />
{i18n.t("no_password_reset")} {i18n.t("no_password_reset")}
@ -254,10 +252,7 @@ export class Signup extends Component<any, State> {
id="register-verify-password" id="register-verify-password"
value={this.state.registerForm.password_verify} value={this.state.registerForm.password_verify}
autoComplete="new-password" autoComplete="new-password"
onInput={linkEvent( onInput={linkEvent(this, this.handleRegisterPasswordVerifyChange)}
this,
this.handleRegisterPasswordVerifyChange
)}
maxLength={60} maxLength={60}
className="form-control" className="form-control"
required required
@ -265,7 +260,7 @@ export class Signup extends Component<any, State> {
</div> </div>
</div> </div>
{siteView.site.require_application && ( {siteView.local_site.require_application && (
<> <>
<div className="form-group row"> <div className="form-group row">
<div className="offset-sm-2 col-sm-10"> <div className="offset-sm-2 col-sm-10">
@ -273,7 +268,7 @@ export class Signup extends Component<any, State> {
<Icon icon="alert-triangle" classes="icon-inline mr-2" /> <Icon icon="alert-triangle" classes="icon-inline mr-2" />
{i18n.t("fill_out_application")} {i18n.t("fill_out_application")}
</div> </div>
{siteView.site.application_question.match({ {siteView.local_site.application_question.match({
some: question => ( some: question => (
<div <div
className="md-div" className="md-div"
@ -337,7 +332,7 @@ export class Signup extends Component<any, State> {
</div> </div>
</div> </div>
)} )}
{siteView.site.enable_nsfw && ( {siteView.local_site.enable_nsfw && (
<div className="form-group row"> <div className="form-group row">
<div className="col-sm-10"> <div className="col-sm-10">
<div className="form-check"> <div className="form-check">
@ -346,10 +341,7 @@ export class Signup extends Component<any, State> {
id="register-show-nsfw" id="register-show-nsfw"
type="checkbox" type="checkbox"
checked={this.state.registerForm.show_nsfw} checked={this.state.registerForm.show_nsfw}
onChange={linkEvent( onChange={linkEvent(this, this.handleRegisterShowNsfwChange)}
this,
this.handleRegisterShowNsfwChange
)}
/> />
<label <label
className="form-check-label" className="form-check-label"
@ -383,9 +375,7 @@ export class Signup extends Component<any, State> {
</div> </div>
</div> </div>
</form> </form>
), );
none: <></>,
});
} }
showCaptcha() { showCaptcha() {
@ -545,6 +535,7 @@ export class Signup extends Component<any, State> {
if (data.jwt.isSome()) { if (data.jwt.isSome()) {
UserService.Instance.login(data); UserService.Instance.login(data);
this.props.history.push("/communities"); this.props.history.push("/communities");
location.reload();
} else { } else {
if (data.verify_email_sent) { if (data.verify_email_sent) {
toast(i18n.t("verify_email_sent")); toast(i18n.t("verify_email_sent"));

View file

@ -4,8 +4,8 @@ import { Prompt } from "inferno-router";
import { import {
CreateSite, CreateSite,
EditSite, EditSite,
GetSiteResponse,
ListingType, ListingType,
Site,
toUndefined, toUndefined,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
@ -18,14 +18,13 @@ import {
} from "../../utils"; } from "../../utils";
import { Spinner } from "../common/icon"; import { Spinner } from "../common/icon";
import { ImageUploadForm } from "../common/image-upload-form"; import { ImageUploadForm } from "../common/image-upload-form";
import { LanguageSelect } from "../common/language-select";
import { ListingTypeSelect } from "../common/listing-type-select"; import { ListingTypeSelect } from "../common/listing-type-select";
import { MarkdownTextArea } from "../common/markdown-textarea"; import { MarkdownTextArea } from "../common/markdown-textarea";
interface SiteFormProps { interface SiteFormProps {
site: Option<Site>; // If a site is given, that means this is an edit siteRes: GetSiteResponse;
showLocal?: boolean; showLocal?: boolean;
onCancel?(): void;
onEdit?(): void;
} }
interface SiteFormState { interface SiteFormState {
@ -37,9 +36,9 @@ interface SiteFormState {
export class SiteForm extends Component<SiteFormProps, SiteFormState> { export class SiteForm extends Component<SiteFormProps, SiteFormState> {
private emptyState: SiteFormState = { private emptyState: SiteFormState = {
siteForm: new EditSite({ siteForm: new EditSite({
enable_downvotes: Some(true), enable_downvotes: None,
open_registration: Some(true), open_registration: None,
enable_nsfw: Some(true), enable_nsfw: None,
name: None, name: None,
icon: None, icon: None,
banner: None, banner: None,
@ -54,8 +53,32 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
description: None, description: None,
community_creation_admin_only: None, community_creation_admin_only: None,
application_email_admins: None, application_email_admins: None,
hide_modlog_mod_names: None,
discussion_languages: None,
slur_filter_regex: None,
actor_name_max_length: None,
rate_limit_message: None,
rate_limit_message_per_second: None,
rate_limit_comment: None,
rate_limit_comment_per_second: None,
rate_limit_image: None,
rate_limit_image_per_second: None,
rate_limit_post: None,
rate_limit_post_per_second: None,
rate_limit_register: None,
rate_limit_register_per_second: None,
rate_limit_search: None,
rate_limit_search_per_second: None,
federation_enabled: None,
federation_debug: None,
federation_worker_count: None,
federation_strict_allowlist: None,
federation_http_fetch_retry_limit: None,
captcha_enabled: None,
captcha_difficulty: None,
allowed_instances: None,
blocked_instances: None,
auth: undefined, auth: undefined,
hide_modlog_mod_names: Some(true),
}), }),
loading: false, loading: false,
themeList: None, themeList: None,
@ -79,36 +102,67 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
this.handleDefaultPostListingTypeChange = this.handleDefaultPostListingTypeChange =
this.handleDefaultPostListingTypeChange.bind(this); this.handleDefaultPostListingTypeChange.bind(this);
if (this.props.site.isSome()) { this.handleDiscussionLanguageChange =
let site = this.props.site.unwrap(); this.handleDiscussionLanguageChange.bind(this);
let site = this.props.siteRes.site_view.site;
let ls = this.props.siteRes.site_view.local_site;
let lsrl = this.props.siteRes.site_view.local_site_rate_limit;
this.state = { this.state = {
...this.state, ...this.state,
siteForm: new EditSite({ siteForm: new EditSite({
name: Some(site.name), name: Some(site.name),
sidebar: site.sidebar, sidebar: site.sidebar,
description: site.description, description: site.description,
enable_downvotes: Some(site.enable_downvotes), enable_downvotes: Some(ls.enable_downvotes),
open_registration: Some(site.open_registration), open_registration: Some(ls.open_registration),
enable_nsfw: Some(site.enable_nsfw), enable_nsfw: Some(ls.enable_nsfw),
community_creation_admin_only: Some( community_creation_admin_only: Some(ls.community_creation_admin_only),
site.community_creation_admin_only
),
icon: site.icon, icon: site.icon,
banner: site.banner, banner: site.banner,
require_email_verification: Some(site.require_email_verification), require_email_verification: Some(ls.require_email_verification),
require_application: Some(site.require_application), require_application: Some(ls.require_application),
application_question: site.application_question, application_question: ls.application_question,
private_instance: Some(site.private_instance), private_instance: Some(ls.private_instance),
default_theme: Some(site.default_theme), default_theme: Some(ls.default_theme),
default_post_listing_type: Some(site.default_post_listing_type), default_post_listing_type: Some(ls.default_post_listing_type),
legal_information: site.legal_information, legal_information: ls.legal_information,
application_email_admins: Some(site.application_email_admins), application_email_admins: Some(ls.application_email_admins),
hide_modlog_mod_names: site.hide_modlog_mod_names, hide_modlog_mod_names: Some(ls.hide_modlog_mod_names),
discussion_languages: Some(this.props.siteRes.discussion_languages),
slur_filter_regex: ls.slur_filter_regex,
actor_name_max_length: Some(ls.actor_name_max_length),
rate_limit_message: Some(lsrl.message),
rate_limit_message_per_second: Some(lsrl.message_per_second),
rate_limit_comment: Some(lsrl.comment),
rate_limit_comment_per_second: Some(lsrl.comment_per_second),
rate_limit_image: Some(lsrl.image),
rate_limit_image_per_second: Some(lsrl.image_per_second),
rate_limit_post: Some(lsrl.post),
rate_limit_post_per_second: Some(lsrl.post_per_second),
rate_limit_register: Some(lsrl.register),
rate_limit_register_per_second: Some(lsrl.register_per_second),
rate_limit_search: Some(lsrl.search),
rate_limit_search_per_second: Some(lsrl.search_per_second),
federation_enabled: Some(ls.federation_enabled),
federation_debug: Some(ls.federation_debug),
federation_worker_count: Some(ls.federation_worker_count),
federation_strict_allowlist: Some(ls.federation_strict_allowlist),
federation_http_fetch_retry_limit: Some(
ls.federation_http_fetch_retry_limit
),
captcha_enabled: Some(ls.captcha_enabled),
captcha_difficulty: Some(ls.captcha_difficulty),
allowed_instances: this.props.siteRes.federated_instances.andThen(
f => f.allowed
),
blocked_instances: this.props.siteRes.federated_instances.andThen(
f => f.blocked
),
auth: undefined, auth: undefined,
}), }),
}; };
} }
}
async componentDidMount() { async componentDidMount() {
this.setState({ themeList: Some(await fetchThemeList()) }); this.setState({ themeList: Some(await fetchThemeList()) });
@ -122,7 +176,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
componentDidUpdate() { componentDidUpdate() {
if ( if (
!this.state.loading && !this.state.loading &&
this.props.site.isNone() && !this.props.siteRes.site_view.local_site.site_setup &&
(this.state.siteForm.name || (this.state.siteForm.name ||
this.state.siteForm.sidebar || this.state.siteForm.sidebar ||
this.state.siteForm.application_question || this.state.siteForm.application_question ||
@ -139,12 +193,13 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
} }
render() { render() {
let siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return ( return (
<> <>
<Prompt <Prompt
when={ when={
!this.state.loading && !this.state.loading &&
this.props.site.isNone() && !siteSetup &&
(this.state.siteForm.name || (this.state.siteForm.name ||
this.state.siteForm.sidebar || this.state.siteForm.sidebar ||
this.state.siteForm.application_question || this.state.siteForm.application_question ||
@ -154,7 +209,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
/> />
<form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}> <form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
<h5>{`${ <h5>{`${
this.props.site.isSome() siteSetup
? capitalizeFirstLetter(i18n.t("save")) ? capitalizeFirstLetter(i18n.t("save"))
: capitalizeFirstLetter(i18n.t("name")) : capitalizeFirstLetter(i18n.t("name"))
} ${i18n.t("your_site")}`}</h5> } ${i18n.t("your_site")}`}</h5>
@ -496,6 +551,487 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
</div> </div>
</div> </div>
</div> </div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-slur-filter-regex"
>
{i18n.t("slur_filter_regex")}
</label>
<div className="col-12">
<input
type="text"
id="create-site-slur-filter-regex"
placeholder="(word1|word2)"
className="form-control"
value={toUndefined(this.state.siteForm.slur_filter_regex)}
onInput={linkEvent(this, this.handleSiteSlurFilterRegex)}
minLength={3}
/>
</div>
</div>
<LanguageSelect
allLanguages={this.props.siteRes.all_languages}
selectedLanguageIds={this.state.siteForm.discussion_languages}
multiple={true}
onChange={this.handleDiscussionLanguageChange}
/>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-actor-name"
>
{i18n.t("actor_name_max_length")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-actor-name"
className="form-control"
min={5}
value={toUndefined(this.state.siteForm.actor_name_max_length)}
onInput={linkEvent(this, this.handleSiteActorNameMaxLength)}
/>
</div>
</div>
<div className="form-group row">
<div className="col-12">
<div className="form-check">
<input
className="form-check-input"
id="create-site-federation-enabled"
type="checkbox"
checked={toUndefined(this.state.siteForm.federation_enabled)}
onChange={linkEvent(this, this.handleSiteFederationEnabled)}
/>
<label
className="form-check-label"
htmlFor="create-site-federation-enabled"
>
{i18n.t("federation_enabled")}
</label>
</div>
</div>
</div>
{this.state.siteForm.federation_enabled.unwrapOr(false) && (
<>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-allowed-instances"
>
{i18n.t("allowed_instances")}
</label>
<div className="col-12">
<input
type="text"
placeholder="instance1.tld,instance2.tld"
id="create-site-allowed-instances"
className="form-control"
value={this.instancesToString(
this.state.siteForm.allowed_instances
)}
onInput={linkEvent(this, this.handleSiteAllowedInstances)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-blocked-instances"
>
{i18n.t("blocked_instances")}
</label>
<div className="col-12">
<input
type="text"
placeholder="instance1.tld,instance2.tld"
id="create-site-blocked-instances"
className="form-control"
value={this.instancesToString(
this.state.siteForm.blocked_instances
)}
onInput={linkEvent(this, this.handleSiteBlockedInstances)}
/>
</div>
</div>
<div className="form-group row">
<div className="col-12">
<div className="form-check">
<input
className="form-check-input"
id="create-site-federation-debug"
type="checkbox"
checked={toUndefined(
this.state.siteForm.federation_debug
)}
onChange={linkEvent(this, this.handleSiteFederationDebug)}
/>
<label
className="form-check-label"
htmlFor="create-site-federation-debug"
>
{i18n.t("federation_debug")}
</label>
</div>
</div>
</div>
<div className="form-group row">
<div className="col-12">
<div className="form-check">
<input
className="form-check-input"
id="create-site-federation-strict-allowlist"
type="checkbox"
checked={toUndefined(
this.state.siteForm.federation_strict_allowlist
)}
onChange={linkEvent(
this,
this.handleSiteFederationStrictAllowList
)}
/>
<label
className="form-check-label"
htmlFor="create-site-federation-strict-allowlist"
>
{i18n.t("federation_strict_allowlist")}
</label>
</div>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-federation-http-fetch-retry-limit"
>
{i18n.t("federation_http_fetch_retry_limit")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-federation-http-fetch-retry-limit"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.federation_http_fetch_retry_limit
)}
onInput={linkEvent(
this,
this.handleSiteFederationHttpFetchRetryLimit
)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-federation-worker-count"
>
{i18n.t("federation_worker_count")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-federation-worker-count"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.federation_worker_count
)}
onInput={linkEvent(
this,
this.handleSiteFederationWorkerCount
)}
/>
</div>
</div>
</>
)}
<div className="form-group row">
<div className="col-12">
<div className="form-check">
<input
className="form-check-input"
id="create-site-captcha-enabled"
type="checkbox"
checked={toUndefined(this.state.siteForm.captcha_enabled)}
onChange={linkEvent(this, this.handleSiteCaptchaEnabled)}
/>
<label
className="form-check-label"
htmlFor="create-site-captcha-enabled"
>
{i18n.t("captcha_enabled")}
</label>
</div>
</div>
</div>
{this.state.siteForm.captcha_enabled.unwrapOr(false) && (
<div className="form-group row">
<div className="col-12">
<label
className="form-check-label mr-2"
htmlFor="create-site-captcha-difficulty"
>
{i18n.t("captcha_difficulty")}
</label>
<select
id="create-site-captcha-difficulty"
value={toUndefined(this.state.siteForm.captcha_difficulty)}
onChange={linkEvent(this, this.handleSiteCaptchaDifficulty)}
className="custom-select w-auto"
>
<option value="easy">{i18n.t("easy")}</option>
<option value="medium">{i18n.t("medium")}</option>
<option value="hard">{i18n.t("hard")}</option>
</select>
</div>
</div>
)}
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-message"
>
{i18n.t("rate_limit_message")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-message"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_message)}
onInput={linkEvent(this, this.handleSiteRateLimitMessage)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-message-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-message-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_message_per_second
)}
onInput={linkEvent(
this,
this.handleSiteRateLimitMessagePerSecond
)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-post"
>
{i18n.t("rate_limit_post")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-post"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_post)}
onInput={linkEvent(this, this.handleSiteRateLimitPost)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-post-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-post-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_post_per_second
)}
onInput={linkEvent(this, this.handleSiteRateLimitPostPerSecond)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-register"
>
{i18n.t("rate_limit_register")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-register"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_register)}
onInput={linkEvent(this, this.handleSiteRateLimitRegister)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-register-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-register-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_register_per_second
)}
onInput={linkEvent(
this,
this.handleSiteRateLimitRegisterPerSecond
)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-image"
>
{i18n.t("rate_limit_image")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-image"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_image)}
onInput={linkEvent(this, this.handleSiteRateLimitImage)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-image-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-image-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_image_per_second
)}
onInput={linkEvent(
this,
this.handleSiteRateLimitImagePerSecond
)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-comment"
>
{i18n.t("rate_limit_comment")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-comment"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_comment)}
onInput={linkEvent(this, this.handleSiteRateLimitComment)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-comment-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-comment-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_comment_per_second
)}
onInput={linkEvent(
this,
this.handleSiteRateLimitCommentPerSecond
)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-search"
>
{i18n.t("rate_limit_search")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-search"
className="form-control"
min={0}
value={toUndefined(this.state.siteForm.rate_limit_search)}
onInput={linkEvent(this, this.handleSiteRateLimitSearch)}
/>
</div>
</div>
<div className="form-group row">
<label
className="col-12 col-form-label"
htmlFor="create-site-rate-limit-search-per-second"
>
{i18n.t("per_second")}
</label>
<div className="col-12">
<input
type="number"
id="create-site-rate-limit-search-per-second"
className="form-control"
min={0}
value={toUndefined(
this.state.siteForm.rate_limit_search_per_second
)}
onInput={linkEvent(
this,
this.handleSiteRateLimitSearchPerSecond
)}
/>
</div>
</div>
<div className="form-group row"> <div className="form-group row">
<div className="col-12"> <div className="col-12">
<button <button
@ -505,21 +1041,12 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
> >
{this.state.loading ? ( {this.state.loading ? (
<Spinner /> <Spinner />
) : this.props.site.isSome() ? ( ) : siteSetup ? (
capitalizeFirstLetter(i18n.t("save")) capitalizeFirstLetter(i18n.t("save"))
) : ( ) : (
capitalizeFirstLetter(i18n.t("create")) capitalizeFirstLetter(i18n.t("create"))
)} )}
</button> </button>
{this.props.site.isSome() && (
<button
type="button"
className="btn btn-secondary"
onClick={linkEvent(this, this.handleCancel)}
>
{i18n.t("cancel")}
</button>
)}
</div> </div>
</div> </div>
</form> </form>
@ -532,9 +1059,8 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
i.setState({ loading: true }); i.setState({ loading: true });
i.setState(s => ((s.siteForm.auth = auth().unwrap()), s)); i.setState(s => ((s.siteForm.auth = auth().unwrap()), s));
if (i.props.site.isSome()) { if (i.props.siteRes.site_view.local_site.site_setup) {
WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm)); WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
i.props.onEdit();
} else { } else {
let sForm = i.state.siteForm; let sForm = i.state.siteForm;
let form = new CreateSite({ let form = new CreateSite({
@ -556,12 +1082,52 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
application_email_admins: sForm.application_email_admins, application_email_admins: sForm.application_email_admins,
auth: auth().unwrap(), auth: auth().unwrap(),
hide_modlog_mod_names: sForm.hide_modlog_mod_names, hide_modlog_mod_names: sForm.hide_modlog_mod_names,
legal_information: sForm.legal_information,
slur_filter_regex: sForm.slur_filter_regex,
actor_name_max_length: sForm.actor_name_max_length,
rate_limit_message: sForm.rate_limit_message,
rate_limit_message_per_second: sForm.rate_limit_message_per_second,
rate_limit_comment: sForm.rate_limit_comment,
rate_limit_comment_per_second: sForm.rate_limit_comment_per_second,
rate_limit_image: sForm.rate_limit_image,
rate_limit_image_per_second: sForm.rate_limit_image_per_second,
rate_limit_post: sForm.rate_limit_post,
rate_limit_post_per_second: sForm.rate_limit_post_per_second,
rate_limit_register: sForm.rate_limit_register,
rate_limit_register_per_second: sForm.rate_limit_register_per_second,
rate_limit_search: sForm.rate_limit_search,
rate_limit_search_per_second: sForm.rate_limit_search_per_second,
federation_enabled: sForm.federation_enabled,
federation_debug: sForm.federation_debug,
federation_worker_count: sForm.federation_worker_count,
federation_strict_allowlist: sForm.federation_strict_allowlist,
federation_http_fetch_retry_limit:
sForm.federation_http_fetch_retry_limit,
captcha_enabled: sForm.captcha_enabled,
captcha_difficulty: sForm.captcha_difficulty,
allowed_instances: sForm.allowed_instances,
blocked_instances: sForm.blocked_instances,
discussion_languages: sForm.discussion_languages,
}); });
WebSocketService.Instance.send(wsClient.createSite(form)); WebSocketService.Instance.send(wsClient.createSite(form));
} }
i.setState(i.state); i.setState(i.state);
} }
instancesToString(opt: Option<string[]>): string {
return opt.map(list => list.join(",")).unwrapOr("");
}
handleSiteAllowedInstances(i: SiteForm, event: any) {
let list = splitToList(event.target.value);
i.setState(s => ((s.siteForm.allowed_instances = list), s));
}
handleSiteBlockedInstances(i: SiteForm, event: any) {
let list = splitToList(event.target.value);
i.setState(s => ((s.siteForm.blocked_instances = list), s));
}
handleSiteNameChange(i: SiteForm, event: any) { handleSiteNameChange(i: SiteForm, event: any) {
i.state.siteForm.name = Some(event.target.value); i.state.siteForm.name = Some(event.target.value);
i.setState(i.state); i.setState(i.state);
@ -634,10 +1200,6 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
i.setState(i.state); i.setState(i.state);
} }
handleCancel(i: SiteForm) {
i.props.onCancel();
}
handleIconUpload(url: string) { handleIconUpload(url: string) {
this.setState(s => ((s.siteForm.icon = Some(url)), s)); this.setState(s => ((s.siteForm.icon = Some(url)), s));
} }
@ -654,6 +1216,180 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
this.setState(s => ((s.siteForm.banner = Some("")), s)); this.setState(s => ((s.siteForm.banner = Some("")), s));
} }
handleSiteSlurFilterRegex(i: SiteForm, event: any) {
i.setState(
s => ((s.siteForm.slur_filter_regex = Some(event.target.value)), s)
);
}
handleSiteActorNameMaxLength(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.actor_name_max_length = Some(Number(event.target.value))), s
)
);
}
handleSiteRateLimitMessage(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_message = Some(Number(event.target.value))), s
)
);
}
handleSiteRateLimitMessagePerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_message_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteRateLimitPost(i: SiteForm, event: any) {
i.setState(
s => ((s.siteForm.rate_limit_post = Some(Number(event.target.value))), s)
);
}
handleSiteRateLimitPostPerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_post_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteRateLimitImage(i: SiteForm, event: any) {
i.setState(
s => ((s.siteForm.rate_limit_image = Some(Number(event.target.value))), s)
);
}
handleSiteRateLimitImagePerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_image_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteRateLimitComment(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_comment = Some(Number(event.target.value))), s
)
);
}
handleSiteRateLimitCommentPerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_comment_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteRateLimitSearch(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_search = Some(Number(event.target.value))), s
)
);
}
handleSiteRateLimitSearchPerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_search_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteRateLimitRegister(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_register = Some(Number(event.target.value))), s
)
);
}
handleSiteRateLimitRegisterPerSecond(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.rate_limit_register_per_second = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteFederationEnabled(i: SiteForm, event: any) {
i.state.siteForm.federation_enabled = Some(event.target.checked);
i.setState(i.state);
}
handleSiteFederationDebug(i: SiteForm, event: any) {
i.state.siteForm.federation_debug = Some(event.target.checked);
i.setState(i.state);
}
handleSiteFederationStrictAllowList(i: SiteForm, event: any) {
i.state.siteForm.federation_strict_allowlist = Some(event.target.checked);
i.setState(i.state);
}
handleSiteFederationWorkerCount(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.federation_worker_count = Some(Number(event.target.value))),
s
)
);
}
handleSiteFederationHttpFetchRetryLimit(i: SiteForm, event: any) {
i.setState(
s => (
(s.siteForm.federation_http_fetch_retry_limit = Some(
Number(event.target.value)
)),
s
)
);
}
handleSiteCaptchaEnabled(i: SiteForm, event: any) {
i.state.siteForm.captcha_enabled = Some(event.target.checked);
i.setState(i.state);
}
handleSiteCaptchaDifficulty(i: SiteForm, event: any) {
i.setState(
s => ((s.siteForm.captcha_difficulty = Some(event.target.value)), s)
);
}
handleDiscussionLanguageChange(val: number[]) {
this.setState(s => ((s.siteForm.discussion_languages = Some(val)), s));
}
handleDefaultPostListingTypeChange(val: ListingType) { handleDefaultPostListingTypeChange(val: ListingType) {
this.setState( this.setState(
s => ( s => (
@ -665,3 +1401,12 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
); );
} }
} }
function splitToList(commaList: string): Option<string[]> {
if (commaList !== "") {
let list = commaList.trim().split(",");
return Some(list);
} else {
return Some([]);
}
}

View file

@ -1,13 +1,12 @@
import { None, Option, Some } from "@sniptt/monads"; import { None, Option } from "@sniptt/monads";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { Link } from "inferno-router"; import { Link } from "inferno-router";
import { PersonViewSafe, Site, SiteAggregates } from "lemmy-js-client"; import { PersonViewSafe, Site, SiteAggregates } from "lemmy-js-client";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { amAdmin, mdToHtml, numToSI } from "../../utils"; import { mdToHtml, numToSI } from "../../utils";
import { BannerIconHeader } from "../common/banner-icon-header"; import { BannerIconHeader } from "../common/banner-icon-header";
import { Icon } from "../common/icon"; import { Icon } from "../common/icon";
import { PersonListing } from "../person/person-listing"; import { PersonListing } from "../person/person-listing";
import { SiteForm } from "./site-form";
interface SiteSidebarProps { interface SiteSidebarProps {
site: Site; site: Site;
@ -19,58 +18,40 @@ interface SiteSidebarProps {
interface SiteSidebarState { interface SiteSidebarState {
collapsed: boolean; collapsed: boolean;
showEdit: boolean;
} }
export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> { export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
private emptyState: SiteSidebarState = { private emptyState: SiteSidebarState = {
collapsed: false, collapsed: false,
showEdit: false,
}; };
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.state = this.emptyState; this.state = this.emptyState;
this.handleEditCancel = this.handleEditCancel.bind(this);
this.handleEditSite = this.handleEditSite.bind(this);
} }
render() { render() {
let site = this.props.site;
return ( return (
<div className="card border-secondary mb-3"> <div className="card border-secondary mb-3">
<div className="card-body"> <div className="card-body">
{!this.state.showEdit ? (
<div> <div>
<div className="mb-2"> <div className="mb-2">{this.siteName()}</div>
{this.siteName()}
{this.props.admins.isSome() && this.adminButtons()}
</div>
{!this.state.collapsed && ( {!this.state.collapsed && (
<> <>
<BannerIconHeader banner={site.banner} icon={None} /> <BannerIconHeader banner={this.props.site.banner} icon={None} />
{this.siteInfo()} {this.siteInfo()}
</> </>
)} )}
</div> </div>
) : (
<SiteForm
site={Some(site)}
showLocal={this.props.showLocal}
onEdit={this.handleEditSite}
onCancel={this.handleEditCancel}
/>
)}
</div> </div>
</div> </div>
); );
} }
siteName() { siteName() {
let site = this.props.site;
return ( return (
<h5 className="mb-0 d-inline"> <h5 className="mb-0 d-inline">
{site.name} {this.props.site.name}
<button <button
className="btn btn-sm text-muted" className="btn btn-sm text-muted"
onClick={linkEvent(this, this.handleCollapseSidebar)} onClick={linkEvent(this, this.handleCollapseSidebar)}
@ -111,25 +92,6 @@ export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
); );
} }
adminButtons() {
return (
amAdmin() && (
<ul className="list-inline mb-1 text-muted font-weight-bold">
<li className="list-inline-item-action">
<button
className="btn btn-link d-inline-block text-muted"
onClick={linkEvent(this, this.handleEditClick)}
aria-label={i18n.t("edit")}
data-tippy-content={i18n.t("edit")}
>
<Icon icon="edit" classes="icon-inline" />
</button>
</li>
</ul>
)
);
}
siteSidebar(sidebar: string) { siteSidebar(sidebar: string) {
return ( return (
<div className="md-div" dangerouslySetInnerHTML={mdToHtml(sidebar)} /> <div className="md-div" dangerouslySetInnerHTML={mdToHtml(sidebar)} />
@ -248,16 +210,4 @@ export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
handleCollapseSidebar(i: SiteSidebar) { handleCollapseSidebar(i: SiteSidebar) {
i.setState({ collapsed: !i.state.collapsed }); i.setState({ collapsed: !i.state.collapsed });
} }
handleEditClick(i: SiteSidebar) {
i.setState({ showEdit: true });
}
handleEditSite() {
this.setState({ showEdit: false });
}
handleEditCancel() {
this.setState({ showEdit: false });
}
} }

View file

@ -632,10 +632,7 @@ export class Modlog extends Component<any, ModlogState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `Modlog - ${this.state.siteRes.site_view.site.name}`;
some: siteView => `Modlog - ${siteView.site.name}`,
none: "",
});
} }
render() { render() {
@ -708,9 +705,8 @@ export class Modlog extends Component<any, ModlogState> {
</option> </option>
</select> </select>
</div> </div>
{this.state.siteRes.site_view.match({ {!this.state.siteRes.site_view.local_site
some: site_view => .hide_modlog_mod_names && (
!site_view.site.hide_modlog_mod_names.unwrapOr(false) && (
<div className="form-group col-sm-6"> <div className="form-group col-sm-6">
<select <select
id="filter-mod" id="filter-mod"
@ -720,9 +716,7 @@ export class Modlog extends Component<any, ModlogState> {
<option>{i18n.t("filter_by_mod")}</option> <option>{i18n.t("filter_by_mod")}</option>
</select> </select>
</div> </div>
), )}
none: <></>,
})}
<div className="form-group col-sm-6"> <div className="form-group col-sm-6">
<select <select
id="filter-user" id="filter-user"

View file

@ -153,16 +153,12 @@ export class Inbox extends Component<any, InboxState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return UserService.Instance.myUserInfo.match({
some: siteView =>
UserService.Instance.myUserInfo.match({
some: mui => some: mui =>
`@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${ `@${mui.local_user_view.person.name} ${i18n.t("inbox")} - ${
siteView.site.name this.state.siteRes.site_view.site.name
}`, }`,
none: "", none: "",
}),
none: "",
}); });
} }

View file

@ -58,10 +58,9 @@ export class PasswordChange extends Component<any, State> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("password_change")} - ${
some: siteView => `${i18n.t("password_change")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {
@ -164,6 +163,7 @@ export class PasswordChange extends Component<any, State> {
this.setState(this.emptyState); this.setState(this.emptyState);
UserService.Instance.login(data); UserService.Instance.login(data);
this.props.history.push("/"); this.props.history.push("/");
location.reload();
} }
} }
} }

View file

@ -238,13 +238,9 @@ export class Profile extends Component<any, ProfileState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return this.state.personRes.match({
some: siteView =>
this.state.personRes.match({
some: res => some: res =>
`@${res.person_view.person.name} - ${siteView.site.name}`, `@${res.person_view.person.name} - ${this.state.siteRes.site_view.site.name}`,
none: "",
}),
none: "", none: "",
}); });
} }

View file

@ -98,15 +98,11 @@ export class RegistrationApplications extends Component<
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return UserService.Instance.myUserInfo.match({
some: siteView =>
UserService.Instance.myUserInfo.match({
some: mui => some: mui =>
`@${mui.local_user_view.person.name} ${i18n.t( `@${mui.local_user_view.person.name} ${i18n.t(
"registration_applications" "registration_applications"
)} - ${siteView.site.name}`, )} - ${this.state.siteRes.site_view.site.name}`,
none: "",
}),
none: "", none: "",
}); });
} }

View file

@ -150,16 +150,12 @@ export class Reports extends Component<any, ReportsState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return UserService.Instance.myUserInfo.match({
some: siteView =>
UserService.Instance.myUserInfo.match({
some: mui => some: mui =>
`@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${ `@${mui.local_user_view.person.name} ${i18n.t("reports")} - ${
siteView.site.name this.state.siteRes.site_view.site.name
}`, }`,
none: "", none: "",
}),
none: "",
}); });
} }

View file

@ -1214,6 +1214,7 @@ export class Settings extends Component<any, SettingsState> {
} else if (op == UserOperation.SaveUserSettings) { } else if (op == UserOperation.SaveUserSettings) {
let data = wsJsonToRes<LoginResponse>(msg, LoginResponse); let data = wsJsonToRes<LoginResponse>(msg, LoginResponse);
UserService.Instance.login(data); UserService.Instance.login(data);
location.reload();
this.setState({ saveUserSettingsLoading: false }); this.setState({ saveUserSettingsLoading: false });
toast(i18n.t("saved")); toast(i18n.t("saved"));
window.scrollTo(0, 0); window.scrollTo(0, 0);

View file

@ -58,10 +58,9 @@ export class VerifyEmail extends Component<any, State> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("verify_email")} - ${
some: siteView => `${i18n.t("verify_email")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {

View file

@ -119,10 +119,9 @@ export class CreatePost extends Component<any, CreatePostState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ return `${i18n.t("create_post")} - ${
some: siteView => `${i18n.t("create_post")} - ${siteView.site.name}`, this.state.siteRes.site_view.site.name
none: "", }`;
});
} }
render() { render() {

View file

@ -317,11 +317,7 @@ export class Post extends Component<any, PostState> {
get documentTitle(): string { get documentTitle(): string {
return this.state.postRes.match({ return this.state.postRes.match({
some: res => some: res =>
this.state.siteRes.site_view.match({ `${res.post_view.post.name} - ${this.state.siteRes.site_view.site.name}`,
some: siteView =>
`${res.post_view.post.name} - ${siteView.site.name}`,
none: "",
}),
none: "", none: "",
}); });
} }

View file

@ -379,13 +379,10 @@ export class Search extends Component<any, SearchState> {
} }
get documentTitle(): string { get documentTitle(): string {
return this.state.siteRes.site_view.match({ let siteName = this.state.siteRes.site_view.site.name;
some: siteView => return this.state.q
this.state.q ? `${i18n.t("search")} - ${this.state.q} - ${siteName}`
? `${i18n.t("search")} - ${this.state.q} - ${siteView.site.name}` : `${i18n.t("search")} - ${siteName}`;
: `${i18n.t("search")} - ${siteView.site.name}`,
none: "",
});
} }
render() { render() {

View file

@ -42,7 +42,6 @@ export class UserService {
toast(i18n.t("logged_in")); toast(i18n.t("logged_in"));
IsomorphicCookie.save("jwt", jwt, { expires, secure: isHttps }); IsomorphicCookie.save("jwt", jwt, { expires, secure: isHttps });
this.setJwtInfo(); this.setJwtInfo();
location.reload();
}, },
none: void 0, none: void 0,
}); });

View file

@ -1425,11 +1425,11 @@ export function auth(throwErr = true): Result<string, string> {
} }
export function enableDownvotes(siteRes: GetSiteResponse): boolean { export function enableDownvotes(siteRes: GetSiteResponse): boolean {
return siteRes.site_view.map(s => s.site.enable_downvotes).unwrapOr(true); return siteRes.site_view.local_site.enable_downvotes;
} }
export function enableNsfw(siteRes: GetSiteResponse): boolean { export function enableNsfw(siteRes: GetSiteResponse): boolean {
return siteRes.site_view.map(s => s.site.enable_nsfw).unwrapOr(false); return siteRes.site_view.local_site.enable_nsfw;
} }
export function postToCommentSortType(sort: SortType): CommentSortType { export function postToCommentSortType(sort: SortType): CommentSortType {
@ -1467,9 +1467,7 @@ export function canCreateCommunity(
siteRes: GetSiteResponse, siteRes: GetSiteResponse,
myUserInfo = UserService.Instance.myUserInfo myUserInfo = UserService.Instance.myUserInfo
): boolean { ): boolean {
let adminOnly = siteRes.site_view let adminOnly = siteRes.site_view.local_site.community_creation_admin_only;
.map(s => s.site.community_creation_admin_only)
.unwrapOr(false);
return !adminOnly || amAdmin(myUserInfo); return !adminOnly || amAdmin(myUserInfo);
} }

View file

@ -19,6 +19,7 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"strictNullChecks": false,
"noFallthroughCasesInSwitch": true "noFallthroughCasesInSwitch": true
}, },
"include": [ "include": [

View file

@ -4879,10 +4879,10 @@ lcid@^1.0.0:
dependencies: dependencies:
invert-kv "^1.0.0" invert-kv "^1.0.0"
lemmy-js-client@0.17.0-rc.46: lemmy-js-client@0.17.0-rc.51:
version "0.17.0-rc.46" version "0.17.0-rc.51"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.46.tgz#c2820821ca46394fd17d1045e54c00a04b15700c" resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.51.tgz#adf554b8837741bc9bb419df090744fc2ef8a1fa"
integrity sha512-9HqKKsvToSB397ywXpl0jPa7KIhDaULWel0g35CgmfOkylvuTlpF8UZW20vMXr02Br9qvbRf0hRvi9s5uaji+Q== integrity sha512-AGXzQptVrdYim/5YrpAnlqAElZl5aTwqZcwffTrzXs4tL91b/APkdoPLUKASGt/5lRng2CP4cQTbykldZyjQRA==
levn@^0.4.1: levn@^0.4.1:
version "0.4.1" version "0.4.1"