{this.mobileView()}
@@ -356,6 +350,7 @@ export class Home extends Component { mobileView() { let siteRes = this.state.siteRes; + let siteView = siteRes.site_view; return (
@@ -399,19 +394,15 @@ export class Home extends Component { classes="icon-inline" /> - {this.state.showSidebarMobile && - siteRes.site_view.match({ - some: siteView => ( - - ), - none: <>, - })} + {this.state.showSidebarMobile && ( + + )} {this.state.showTrendingMobile && (
{this.trendingCommunities()}
@@ -429,6 +420,7 @@ export class Home extends Component { mySidebar() { let siteRes = this.state.siteRes; + let siteView = siteRes.site_view; return (
{!this.state.loading && ( @@ -441,18 +433,13 @@ export class Home extends Component { {this.exploreCommunitiesButton()}
- {siteRes.site_view.match({ - some: siteView => ( - - ), - none: <>, - })} + {this.hasFollows && (
{this.subscribedCommunities()}
@@ -749,7 +736,7 @@ export class Home extends Component { this.setState({ trendingCommunities: data.communities }); } else if (op == UserOperation.EditSite) { let data = wsJsonToRes(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")); } else if (op == UserOperation.GetPosts) { let data = wsJsonToRes(msg, GetPostsResponse); diff --git a/src/shared/components/home/instances.tsx b/src/shared/components/home/instances.tsx index bd56c484..434fae92 100644 --- a/src/shared/components/home/instances.tsx +++ b/src/shared/components/home/instances.tsx @@ -21,10 +21,7 @@ export class Instances extends Component { } get documentTitle(): string { - return this.state.siteRes.site_view.match({ - some: siteView => `${i18n.t("instances")} - ${siteView.site.name}`, - none: "", - }); + return `${i18n.t("instances")} - ${this.state.siteRes.site_view.site.name}`; } render() { diff --git a/src/shared/components/home/legal.tsx b/src/shared/components/home/legal.tsx index bd07c406..3930db20 100644 --- a/src/shared/components/home/legal.tsx +++ b/src/shared/components/home/legal.tsx @@ -33,17 +33,10 @@ export class Legal extends Component { description={None} image={None} /> - {this.state.siteRes.site_view.match({ - some: siteView => - siteView.site.legal_information.match({ - some: legal => ( -
- ), - none: <>, - }), + {this.state.siteRes.site_view.local_site.legal_information.match({ + some: legal => ( +
+ ), none: <>, })}
diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 4cf9d4a6..650b3173 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -69,10 +69,7 @@ export class Login extends Component { } get documentTitle(): string { - return this.state.siteRes.site_view.match({ - some: siteView => `${i18n.t("login")} - ${siteView.site.name}`, - none: "", - }); + return `${i18n.t("login")} - ${this.state.siteRes.site_view.site.name}`; } get isLemmyMl(): boolean { @@ -194,6 +191,8 @@ export class Login extends Component { let data = wsJsonToRes(msg, LoginResponse); this.setState(this.emptyState); UserService.Instance.login(data); + this.props.history.push("/"); + location.reload(); } else if (op == UserOperation.PasswordReset) { toast(i18n.t("reset_password_mail_sent")); } else if (op == UserOperation.GetSite) { diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx index a288e2a1..8da196ca 100644 --- a/src/shared/components/home/setup.tsx +++ b/src/shared/components/home/setup.tsx @@ -2,6 +2,7 @@ import { None, Some } from "@sniptt/monads"; import { Component, linkEvent } from "inferno"; import { Helmet } from "inferno-helmet"; import { + GetSiteResponse, LoginResponse, Register, toUndefined, @@ -13,7 +14,7 @@ import { Subscription } from "rxjs"; import { delay, retryWhen, take } from "rxjs/operators"; import { i18n } from "../../i18next"; import { UserService, WebSocketService } from "../../services"; -import { toast, wsClient } from "../../utils"; +import { setIsoData, toast, wsClient } from "../../utils"; import { Spinner } from "../common/icon"; import { SiteForm } from "./site-form"; @@ -21,10 +22,12 @@ interface State { userForm: Register; doneRegisteringUser: boolean; userLoading: boolean; + siteRes: GetSiteResponse; } export class Setup extends Component { private subscription: Subscription; + private isoData = setIsoData(this.context); private emptyState: State = { userForm: new Register({ @@ -41,6 +44,7 @@ export class Setup extends Component { }), doneRegisteringUser: UserService.Instance.myUserInfo.isSome(), userLoading: false, + siteRes: this.isoData.site_res, }; constructor(props: any, context: any) { @@ -75,7 +79,7 @@ export class Setup extends Component { {!this.state.doneRegisteringUser ? ( this.registerUser() ) : ( - + )}
diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 53162114..2f628503 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -111,14 +111,14 @@ export class Signup extends Component { } get documentTitle(): string { - return this.state.siteRes.site_view.match({ - some: siteView => `${this.titleName(siteView)} - ${siteView.site.name}`, - none: "", - }); + let siteView = this.state.siteRes.site_view; + return `${this.titleName(siteView)} - ${siteView.site.name}`; } 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 { @@ -144,248 +144,238 @@ export class Signup extends Component { } registerForm() { - return this.state.siteRes.site_view.match({ - some: siteView => ( -
-
{this.titleName(siteView)}
- - {this.isLemmyMl && ( -
-
- - ## - -
-
- )} + let siteView = this.state.siteRes.site_view; + return ( + +
{this.titleName(siteView)}
+ {this.isLemmyMl && (
- - -
- +
+ + ## +
+ )} -
- -
- - {!siteView.site.require_email_verification && - !this.state.registerForm.email - .map(validEmail) - .unwrapOr(true) && ( -
- - {i18n.t("no_password_reset")} -
- )} -
+
+ + +
+
+
-
- -
- - {this.state.registerForm.password && ( -
- {i18n.t(this.passwordStrength as I18nKeys)} +
+ +
+ + {!siteView.local_site.require_email_verification && + !this.state.registerForm.email.map(validEmail).unwrapOr(true) && ( +
+ + {i18n.t("no_password_reset")}
)} -
+
-
- -
- -
+
+ +
+ + {this.state.registerForm.password && ( +
+ {i18n.t(this.passwordStrength as I18nKeys)} +
+ )}
+
- {siteView.site.require_application && ( - <> -
-
-
- - {i18n.t("fill_out_application")} -
- {siteView.site.application_question.match({ - some: question => ( -
- ), - none: <>, - })} -
-
+
+ +
+ +
+
-
- -
- -
-
- - )} - - {this.state.captcha.isSome() && ( + {siteView.local_site.require_application && ( + <>
-
+
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+
+ + +
+
+
+ {this.state.siteForm.federation_enabled.unwrapOr(false) && ( + <> +
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + )} +
+
+
+ + +
+
+
+ {this.state.siteForm.captcha_enabled.unwrapOr(false) && ( +
+
+ + +
+
+ )} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
- {this.props.site.isSome() && ( - - )}
@@ -532,9 +1059,8 @@ export class SiteForm extends Component { i.setState({ loading: true }); 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)); - i.props.onEdit(); } else { let sForm = i.state.siteForm; let form = new CreateSite({ @@ -556,12 +1082,52 @@ export class SiteForm extends Component { application_email_admins: sForm.application_email_admins, auth: auth().unwrap(), 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)); } i.setState(i.state); } + instancesToString(opt: Option): 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) { i.state.siteForm.name = Some(event.target.value); i.setState(i.state); @@ -634,10 +1200,6 @@ export class SiteForm extends Component { i.setState(i.state); } - handleCancel(i: SiteForm) { - i.props.onCancel(); - } - handleIconUpload(url: string) { this.setState(s => ((s.siteForm.icon = Some(url)), s)); } @@ -654,6 +1216,180 @@ export class SiteForm extends Component { 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) { this.setState( s => ( @@ -665,3 +1401,12 @@ export class SiteForm extends Component { ); } } + +function splitToList(commaList: string): Option { + if (commaList !== "") { + let list = commaList.trim().split(","); + return Some(list); + } else { + return Some([]); + } +} diff --git a/src/shared/components/home/site-sidebar.tsx b/src/shared/components/home/site-sidebar.tsx index e8642c78..e321ae9f 100644 --- a/src/shared/components/home/site-sidebar.tsx +++ b/src/shared/components/home/site-sidebar.tsx @@ -1,13 +1,12 @@ -import { None, Option, Some } from "@sniptt/monads"; +import { None, Option } from "@sniptt/monads"; import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { PersonViewSafe, Site, SiteAggregates } from "lemmy-js-client"; import { i18n } from "../../i18next"; -import { amAdmin, mdToHtml, numToSI } from "../../utils"; +import { mdToHtml, numToSI } from "../../utils"; import { BannerIconHeader } from "../common/banner-icon-header"; import { Icon } from "../common/icon"; import { PersonListing } from "../person/person-listing"; -import { SiteForm } from "./site-form"; interface SiteSidebarProps { site: Site; @@ -19,58 +18,40 @@ interface SiteSidebarProps { interface SiteSidebarState { collapsed: boolean; - showEdit: boolean; } export class SiteSidebar extends Component { private emptyState: SiteSidebarState = { collapsed: false, - showEdit: false, }; constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; - this.handleEditCancel = this.handleEditCancel.bind(this); - this.handleEditSite = this.handleEditSite.bind(this); } render() { - let site = this.props.site; return (
- {!this.state.showEdit ? ( -
-
- {this.siteName()} - {this.props.admins.isSome() && this.adminButtons()} -
- {!this.state.collapsed && ( - <> - - {this.siteInfo()} - - )} -
- ) : ( - - )} +
+
{this.siteName()}
+ {!this.state.collapsed && ( + <> + + {this.siteInfo()} + + )} +
); } siteName() { - let site = this.props.site; return (
- {site.name} + {this.props.site.name} -