From: abias Date: Sun, 21 May 2023 13:07:22 +0000 (-0400) Subject: Put rate limit options in its own tab X-Git-Url: http://these/git/readmes/static/git-logo.png?a=commitdiff_plain;h=2e3c1a6cfa81ce0cb4e1ba81a80e8038e5800213;p=lemmy-ui.git Put rate limit options in its own tab --- diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index 3a2238b..8370bec 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -31,6 +31,7 @@ import { Spinner } from "../common/icon"; import Tabs from "../common/tabs"; import { PersonListing } from "../person/person-listing"; import { EmojiForm } from "./emojis-form"; +import RateLimitForm from "./rate-limit-form"; import { SiteForm } from "./site-form"; import { TaglineForm } from "./tagline-form"; @@ -148,6 +149,17 @@ export class AdminSettings extends Component { ), }, + { + key: "rate_limiting", + label: "Rate Limiting", + getNode: () => ( + + ), + }, { key: "taglines", label: i18n.t("taglines"), diff --git a/src/shared/components/home/rate-limit-form.tsx b/src/shared/components/home/rate-limit-form.tsx index b99c263..95f7fee 100644 --- a/src/shared/components/home/rate-limit-form.tsx +++ b/src/shared/components/home/rate-limit-form.tsx @@ -1,11 +1,161 @@ -import { Component } from "inferno"; +import { Component, FormEventHandler, linkEvent } from "inferno"; +import { LocalSiteRateLimit } from "lemmy-js-client"; +import { i18n } from "../../i18next"; +import Tabs from "../common/tabs"; -export default class RateLimitForm extends Component { - constructor(props, context) { +const rateLimitTypes = [ + "message", + "post", + "image", + "comment", + "search", + "register", +] as const; + +interface RateLimitsProps { + handleRateLimit: FormEventHandler; + handleRateLimitPerSecond: FormEventHandler; + rateLimitLabel: string; + rateLimitValue?: number; + rateLimitPerSecondValue?: number; +} + +interface RateLimitFormProps { + localSiteRateLimit: LocalSiteRateLimit; +} + +interface RateLimitFormState { + message?: number; + message_per_second?: number; + post?: number; + post_per_second?: number; + comment?: number; + comment_per_second?: number; + image?: number; + image_per_second?: number; + search?: number; + search_per_second?: number; + register?: number; + register_per_second?: number; +} + +function RateLimits({ + handleRateLimit, + handleRateLimitPerSecond, + rateLimitLabel, + rateLimitPerSecondValue, + rateLimitValue, +}: RateLimitsProps) { + return ( +
+ + + + +
+ ); +} + +function handleRateLimitChange( + { rateLimitType, ctx }: { rateLimitType: string; ctx: RateLimitsForm }, + event: any +) { + ctx.setState({ + [rateLimitType]: Number(event.target.value), + }); +} + +function handlePerSecondChange( + { rateLimitType, ctx }: { rateLimitType: string; ctx: RateLimitsForm }, + event: any +) { + ctx.setState({ + [`${rateLimitType}_per_second`]: Number(event.target.value), + }); +} + +export default class RateLimitsForm extends Component< + RateLimitFormProps, + RateLimitFormState +> { + state: RateLimitFormState = {}; + constructor(props: RateLimitFormProps, context) { super(props, context); + + const { + comment, + comment_per_second, + image, + image_per_second, + message, + message_per_second, + post, + post_per_second, + register, + register_per_second, + search, + search_per_second, + } = props.localSiteRateLimit; + + this.state = { + comment, + comment_per_second, + image, + image_per_second, + message, + message_per_second, + post, + post_per_second, + register, + register_per_second, + search, + search_per_second, + }; } render() { - return <>; + return ( + ({ + key: rateLimitType, + label: rateLimitType, + getNode: () => ( + + ), + }))} + /> + ); } } diff --git a/src/shared/components/home/site-form.tsx b/src/shared/components/home/site-form.tsx index ea4d25e..d3d3679 100644 --- a/src/shared/components/home/site-form.tsx +++ b/src/shared/components/home/site-form.tsx @@ -78,7 +78,6 @@ export class SiteForm extends Component { 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, siteForm: { @@ -103,18 +102,6 @@ export class SiteForm extends Component { discussion_languages: this.props.siteRes.discussion_languages, slur_filter_regex: ls.slur_filter_regex, actor_name_max_length: ls.actor_name_max_length, - rate_limit_message: lsrl.message, - rate_limit_message_per_second: lsrl.message_per_second, - rate_limit_comment: lsrl.comment, - rate_limit_comment_per_second: lsrl.comment_per_second, - rate_limit_image: lsrl.image, - rate_limit_image_per_second: lsrl.image_per_second, - rate_limit_post: lsrl.post, - rate_limit_post_per_second: lsrl.post_per_second, - rate_limit_register: lsrl.register, - rate_limit_register_per_second: lsrl.register_per_second, - rate_limit_search: lsrl.search, - rate_limit_search_per_second: lsrl.search_per_second, federation_enabled: ls.federation_enabled, federation_debug: ls.federation_debug, federation_worker_count: ls.federation_worker_count, @@ -655,238 +642,6 @@ export class SiteForm extends Component { )} -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-