1 import { None, Option, Some } from "@sniptt/monads";
2 import { Component, linkEvent } from "inferno";
3 import { Prompt } from "inferno-router";
10 } from "lemmy-js-client";
11 import { i18n } from "../../i18next";
12 import { WebSocketService } from "../../services";
15 capitalizeFirstLetter,
19 import { Spinner } from "../common/icon";
20 import { ImageUploadForm } from "../common/image-upload-form";
21 import { LanguageSelect } from "../common/language-select";
22 import { ListingTypeSelect } from "../common/listing-type-select";
23 import { MarkdownTextArea } from "../common/markdown-textarea";
25 interface SiteFormProps {
26 siteRes: GetSiteResponse;
30 interface SiteFormState {
33 themeList: Option<string[]>;
36 export class SiteForm extends Component<SiteFormProps, SiteFormState> {
37 private emptyState: SiteFormState = {
38 siteForm: new EditSite({
39 enable_downvotes: None,
40 open_registration: None,
45 require_email_verification: None,
46 require_application: None,
47 application_question: None,
48 private_instance: None,
51 default_post_listing_type: None,
52 legal_information: None,
54 community_creation_admin_only: None,
55 application_email_admins: None,
56 hide_modlog_mod_names: None,
57 discussion_languages: None,
58 slur_filter_regex: None,
59 actor_name_max_length: None,
60 rate_limit_message: None,
61 rate_limit_message_per_second: None,
62 rate_limit_comment: None,
63 rate_limit_comment_per_second: None,
64 rate_limit_image: None,
65 rate_limit_image_per_second: None,
66 rate_limit_post: None,
67 rate_limit_post_per_second: None,
68 rate_limit_register: None,
69 rate_limit_register_per_second: None,
70 rate_limit_search: None,
71 rate_limit_search_per_second: None,
72 federation_enabled: None,
73 federation_debug: None,
74 federation_worker_count: None,
75 federation_strict_allowlist: None,
76 federation_http_fetch_retry_limit: None,
77 captcha_enabled: None,
78 captcha_difficulty: None,
79 allowed_instances: None,
80 blocked_instances: None,
87 constructor(props: any, context: any) {
88 super(props, context);
90 this.state = this.emptyState;
91 this.handleSiteSidebarChange = this.handleSiteSidebarChange.bind(this);
92 this.handleSiteLegalInfoChange = this.handleSiteLegalInfoChange.bind(this);
93 this.handleSiteApplicationQuestionChange =
94 this.handleSiteApplicationQuestionChange.bind(this);
96 this.handleIconUpload = this.handleIconUpload.bind(this);
97 this.handleIconRemove = this.handleIconRemove.bind(this);
99 this.handleBannerUpload = this.handleBannerUpload.bind(this);
100 this.handleBannerRemove = this.handleBannerRemove.bind(this);
102 this.handleDefaultPostListingTypeChange =
103 this.handleDefaultPostListingTypeChange.bind(this);
105 this.handleDiscussionLanguageChange =
106 this.handleDiscussionLanguageChange.bind(this);
108 let site = this.props.siteRes.site_view.site;
109 let ls = this.props.siteRes.site_view.local_site;
110 let lsrl = this.props.siteRes.site_view.local_site_rate_limit;
113 siteForm: new EditSite({
114 name: Some(site.name),
115 sidebar: site.sidebar,
116 description: site.description,
117 enable_downvotes: Some(ls.enable_downvotes),
118 open_registration: Some(ls.open_registration),
119 enable_nsfw: Some(ls.enable_nsfw),
120 community_creation_admin_only: Some(ls.community_creation_admin_only),
123 require_email_verification: Some(ls.require_email_verification),
124 require_application: Some(ls.require_application),
125 application_question: ls.application_question,
126 private_instance: Some(ls.private_instance),
127 default_theme: Some(ls.default_theme),
128 default_post_listing_type: Some(ls.default_post_listing_type),
129 legal_information: ls.legal_information,
130 application_email_admins: Some(ls.application_email_admins),
131 hide_modlog_mod_names: Some(ls.hide_modlog_mod_names),
132 discussion_languages: Some(this.props.siteRes.discussion_languages),
133 slur_filter_regex: ls.slur_filter_regex,
134 actor_name_max_length: Some(ls.actor_name_max_length),
135 rate_limit_message: Some(lsrl.message),
136 rate_limit_message_per_second: Some(lsrl.message_per_second),
137 rate_limit_comment: Some(lsrl.comment),
138 rate_limit_comment_per_second: Some(lsrl.comment_per_second),
139 rate_limit_image: Some(lsrl.image),
140 rate_limit_image_per_second: Some(lsrl.image_per_second),
141 rate_limit_post: Some(lsrl.post),
142 rate_limit_post_per_second: Some(lsrl.post_per_second),
143 rate_limit_register: Some(lsrl.register),
144 rate_limit_register_per_second: Some(lsrl.register_per_second),
145 rate_limit_search: Some(lsrl.search),
146 rate_limit_search_per_second: Some(lsrl.search_per_second),
147 federation_enabled: Some(ls.federation_enabled),
148 federation_debug: Some(ls.federation_debug),
149 federation_worker_count: Some(ls.federation_worker_count),
150 federation_strict_allowlist: Some(ls.federation_strict_allowlist),
151 federation_http_fetch_retry_limit: Some(
152 ls.federation_http_fetch_retry_limit
154 captcha_enabled: Some(ls.captcha_enabled),
155 captcha_difficulty: Some(ls.captcha_difficulty),
156 allowed_instances: this.props.siteRes.federated_instances.andThen(
159 blocked_instances: this.props.siteRes.federated_instances.andThen(
167 async componentDidMount() {
168 this.setState({ themeList: Some(await fetchThemeList()) });
171 // Necessary to stop the loading
172 componentWillReceiveProps() {
173 this.setState({ loading: false });
176 componentDidUpdate() {
178 !this.state.loading &&
179 !this.props.siteRes.site_view.local_site.site_setup &&
180 (this.state.siteForm.name ||
181 this.state.siteForm.sidebar ||
182 this.state.siteForm.application_question ||
183 this.state.siteForm.description)
185 window.onbeforeunload = () => true;
187 window.onbeforeunload = undefined;
191 componentWillUnmount() {
192 window.onbeforeunload = null;
196 let siteSetup = this.props.siteRes.site_view.local_site.site_setup;
201 !this.state.loading &&
203 (this.state.siteForm.name ||
204 this.state.siteForm.sidebar ||
205 this.state.siteForm.application_question ||
206 this.state.siteForm.description)
208 message={i18n.t("block_leaving")}
210 <form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
213 ? capitalizeFirstLetter(i18n.t("save"))
214 : capitalizeFirstLetter(i18n.t("name"))
215 } ${i18n.t("your_site")}`}</h5>
216 <div className="form-group row">
217 <label className="col-12 col-form-label" htmlFor="create-site-name">
220 <div className="col-12">
223 id="create-site-name"
224 className="form-control"
225 value={toUndefined(this.state.siteForm.name)}
226 onInput={linkEvent(this, this.handleSiteNameChange)}
233 <div className="form-group">
234 <label>{i18n.t("icon")}</label>
236 uploadTitle={i18n.t("upload_icon")}
237 imageSrc={this.state.siteForm.icon}
238 onUpload={this.handleIconUpload}
239 onRemove={this.handleIconRemove}
243 <div className="form-group">
244 <label>{i18n.t("banner")}</label>
246 uploadTitle={i18n.t("upload_banner")}
247 imageSrc={this.state.siteForm.banner}
248 onUpload={this.handleBannerUpload}
249 onRemove={this.handleBannerRemove}
252 <div className="form-group row">
253 <label className="col-12 col-form-label" htmlFor="site-desc">
254 {i18n.t("description")}
256 <div className="col-12">
259 className="form-control"
261 value={toUndefined(this.state.siteForm.description)}
262 onInput={linkEvent(this, this.handleSiteDescChange)}
267 <div className="form-group row">
268 <label className="col-12 col-form-label">{i18n.t("sidebar")}</label>
269 <div className="col-12">
271 initialContent={this.state.siteForm.sidebar}
272 initialLanguageId={None}
276 onContentChange={this.handleSiteSidebarChange}
277 hideNavigationWarnings
282 <div className="form-group row">
283 <label className="col-12 col-form-label">
284 {i18n.t("legal_information")}
286 <div className="col-12">
288 initialContent={this.state.siteForm.legal_information}
289 initialLanguageId={None}
293 onContentChange={this.handleSiteLegalInfoChange}
294 hideNavigationWarnings
299 {this.state.siteForm.require_application.unwrapOr(false) && (
300 <div className="form-group row">
301 <label className="col-12 col-form-label">
302 {i18n.t("application_questionnaire")}
304 <div className="col-12">
306 initialContent={this.state.siteForm.application_question}
307 initialLanguageId={None}
311 onContentChange={this.handleSiteApplicationQuestionChange}
312 hideNavigationWarnings
318 <div className="form-group row">
319 <div className="col-12">
320 <div className="form-check">
322 className="form-check-input"
323 id="create-site-downvotes"
325 checked={toUndefined(this.state.siteForm.enable_downvotes)}
328 this.handleSiteEnableDownvotesChange
332 className="form-check-label"
333 htmlFor="create-site-downvotes"
335 {i18n.t("enable_downvotes")}
340 <div className="form-group row">
341 <div className="col-12">
342 <div className="form-check">
344 className="form-check-input"
345 id="create-site-enable-nsfw"
347 checked={toUndefined(this.state.siteForm.enable_nsfw)}
348 onChange={linkEvent(this, this.handleSiteEnableNsfwChange)}
351 className="form-check-label"
352 htmlFor="create-site-enable-nsfw"
354 {i18n.t("enable_nsfw")}
359 <div className="form-group row">
360 <div className="col-12">
361 <div className="form-check">
363 className="form-check-input"
364 id="create-site-open-registration"
366 checked={toUndefined(this.state.siteForm.open_registration)}
369 this.handleSiteOpenRegistrationChange
373 className="form-check-label"
374 htmlFor="create-site-open-registration"
376 {i18n.t("open_registration")}
381 <div className="form-group row">
382 <div className="col-12">
383 <div className="form-check">
385 className="form-check-input"
386 id="create-site-community-creation-admin-only"
388 checked={toUndefined(
389 this.state.siteForm.community_creation_admin_only
393 this.handleSiteCommunityCreationAdminOnly
397 className="form-check-label"
398 htmlFor="create-site-community-creation-admin-only"
400 {i18n.t("community_creation_admin_only")}
405 <div className="form-group row">
406 <div className="col-12">
407 <div className="form-check">
409 className="form-check-input"
410 id="create-site-require-email-verification"
412 checked={toUndefined(
413 this.state.siteForm.require_email_verification
417 this.handleSiteRequireEmailVerification
421 className="form-check-label"
422 htmlFor="create-site-require-email-verification"
424 {i18n.t("require_email_verification")}
429 <div className="form-group row">
430 <div className="col-12">
431 <div className="form-check">
433 className="form-check-input"
434 id="create-site-require-application"
436 checked={toUndefined(this.state.siteForm.require_application)}
437 onChange={linkEvent(this, this.handleSiteRequireApplication)}
440 className="form-check-label"
441 htmlFor="create-site-require-application"
443 {i18n.t("require_registration_application")}
448 <div className="form-group row">
449 <div className="col-12">
450 <div className="form-check">
452 className="form-check-input"
453 id="create-site-application-email-admins"
455 checked={toUndefined(
456 this.state.siteForm.application_email_admins
460 this.handleSiteApplicationEmailAdmins
464 className="form-check-label"
465 htmlFor="create-site-email-admins"
467 {i18n.t("application_email_admins")}
472 <div className="form-group row">
473 <div className="col-12">
475 className="form-check-label mr-2"
476 htmlFor="create-site-default-theme"
481 id="create-site-default-theme"
482 value={toUndefined(this.state.siteForm.default_theme)}
483 onChange={linkEvent(this, this.handleSiteDefaultTheme)}
484 className="custom-select w-auto"
486 <option value="browser">{i18n.t("browser_default")}</option>
487 {this.state.themeList.unwrapOr([]).map(theme => (
488 <option key={theme} value={theme}>
495 {this.props.showLocal && (
496 <form className="form-group row">
497 <label className="col-sm-3">{i18n.t("listing_type")}</label>
498 <div className="col-sm-9">
502 this.state.siteForm.default_post_listing_type.unwrapOr(
508 showSubscribed={false}
509 onChange={this.handleDefaultPostListingTypeChange}
514 <div className="form-group row">
515 <div className="col-12">
516 <div className="form-check">
518 className="form-check-input"
519 id="create-site-private-instance"
521 checked={toUndefined(this.state.siteForm.private_instance)}
522 onChange={linkEvent(this, this.handleSitePrivateInstance)}
525 className="form-check-label"
526 htmlFor="create-site-private-instance"
528 {i18n.t("private_instance")}
533 <div className="form-group row">
534 <div className="col-12">
535 <div className="form-check">
537 className="form-check-input"
538 id="create-site-hide-modlog-mod-names"
540 checked={toUndefined(
541 this.state.siteForm.hide_modlog_mod_names
543 onChange={linkEvent(this, this.handleSiteHideModlogModNames)}
546 className="form-check-label"
547 htmlFor="create-site-hide-modlog-mod-names"
549 {i18n.t("hide_modlog_mod_names")}
554 <div className="form-group row">
556 className="col-12 col-form-label"
557 htmlFor="create-site-slur-filter-regex"
559 {i18n.t("slur_filter_regex")}
561 <div className="col-12">
564 id="create-site-slur-filter-regex"
565 placeholder="(word1|word2)"
566 className="form-control"
567 value={toUndefined(this.state.siteForm.slur_filter_regex)}
568 onInput={linkEvent(this, this.handleSiteSlurFilterRegex)}
574 allLanguages={this.props.siteRes.all_languages}
575 selectedLanguageIds={this.state.siteForm.discussion_languages}
577 onChange={this.handleDiscussionLanguageChange}
579 <div className="form-group row">
581 className="col-12 col-form-label"
582 htmlFor="create-site-actor-name"
584 {i18n.t("actor_name_max_length")}
586 <div className="col-12">
589 id="create-site-actor-name"
590 className="form-control"
592 value={toUndefined(this.state.siteForm.actor_name_max_length)}
593 onInput={linkEvent(this, this.handleSiteActorNameMaxLength)}
597 <div className="form-group row">
598 <div className="col-12">
599 <div className="form-check">
601 className="form-check-input"
602 id="create-site-federation-enabled"
604 checked={toUndefined(this.state.siteForm.federation_enabled)}
605 onChange={linkEvent(this, this.handleSiteFederationEnabled)}
608 className="form-check-label"
609 htmlFor="create-site-federation-enabled"
611 {i18n.t("federation_enabled")}
616 {this.state.siteForm.federation_enabled.unwrapOr(false) && (
618 <div className="form-group row">
620 className="col-12 col-form-label"
621 htmlFor="create-site-allowed-instances"
623 {i18n.t("allowed_instances")}
625 <div className="col-12">
628 placeholder="instance1.tld,instance2.tld"
629 id="create-site-allowed-instances"
630 className="form-control"
631 value={this.instancesToString(
632 this.state.siteForm.allowed_instances
634 onInput={linkEvent(this, this.handleSiteAllowedInstances)}
638 <div className="form-group row">
640 className="col-12 col-form-label"
641 htmlFor="create-site-blocked-instances"
643 {i18n.t("blocked_instances")}
645 <div className="col-12">
648 placeholder="instance1.tld,instance2.tld"
649 id="create-site-blocked-instances"
650 className="form-control"
651 value={this.instancesToString(
652 this.state.siteForm.blocked_instances
654 onInput={linkEvent(this, this.handleSiteBlockedInstances)}
658 <div className="form-group row">
659 <div className="col-12">
660 <div className="form-check">
662 className="form-check-input"
663 id="create-site-federation-debug"
665 checked={toUndefined(
666 this.state.siteForm.federation_debug
668 onChange={linkEvent(this, this.handleSiteFederationDebug)}
671 className="form-check-label"
672 htmlFor="create-site-federation-debug"
674 {i18n.t("federation_debug")}
679 <div className="form-group row">
680 <div className="col-12">
681 <div className="form-check">
683 className="form-check-input"
684 id="create-site-federation-strict-allowlist"
686 checked={toUndefined(
687 this.state.siteForm.federation_strict_allowlist
691 this.handleSiteFederationStrictAllowList
695 className="form-check-label"
696 htmlFor="create-site-federation-strict-allowlist"
698 {i18n.t("federation_strict_allowlist")}
703 <div className="form-group row">
705 className="col-12 col-form-label"
706 htmlFor="create-site-federation-http-fetch-retry-limit"
708 {i18n.t("federation_http_fetch_retry_limit")}
710 <div className="col-12">
713 id="create-site-federation-http-fetch-retry-limit"
714 className="form-control"
717 this.state.siteForm.federation_http_fetch_retry_limit
721 this.handleSiteFederationHttpFetchRetryLimit
726 <div className="form-group row">
728 className="col-12 col-form-label"
729 htmlFor="create-site-federation-worker-count"
731 {i18n.t("federation_worker_count")}
733 <div className="col-12">
736 id="create-site-federation-worker-count"
737 className="form-control"
740 this.state.siteForm.federation_worker_count
744 this.handleSiteFederationWorkerCount
751 <div className="form-group row">
752 <div className="col-12">
753 <div className="form-check">
755 className="form-check-input"
756 id="create-site-captcha-enabled"
758 checked={toUndefined(this.state.siteForm.captcha_enabled)}
759 onChange={linkEvent(this, this.handleSiteCaptchaEnabled)}
762 className="form-check-label"
763 htmlFor="create-site-captcha-enabled"
765 {i18n.t("captcha_enabled")}
770 {this.state.siteForm.captcha_enabled.unwrapOr(false) && (
771 <div className="form-group row">
772 <div className="col-12">
774 className="form-check-label mr-2"
775 htmlFor="create-site-captcha-difficulty"
777 {i18n.t("captcha_difficulty")}
780 id="create-site-captcha-difficulty"
781 value={toUndefined(this.state.siteForm.captcha_difficulty)}
782 onChange={linkEvent(this, this.handleSiteCaptchaDifficulty)}
783 className="custom-select w-auto"
785 <option value="easy">{i18n.t("easy")}</option>
786 <option value="medium">{i18n.t("medium")}</option>
787 <option value="hard">{i18n.t("hard")}</option>
792 <div className="form-group row">
794 className="col-12 col-form-label"
795 htmlFor="create-site-rate-limit-message"
797 {i18n.t("rate_limit_message")}
799 <div className="col-12">
802 id="create-site-rate-limit-message"
803 className="form-control"
805 value={toUndefined(this.state.siteForm.rate_limit_message)}
806 onInput={linkEvent(this, this.handleSiteRateLimitMessage)}
810 <div className="form-group row">
812 className="col-12 col-form-label"
813 htmlFor="create-site-rate-limit-message-per-second"
815 {i18n.t("per_second")}
817 <div className="col-12">
820 id="create-site-rate-limit-message-per-second"
821 className="form-control"
824 this.state.siteForm.rate_limit_message_per_second
828 this.handleSiteRateLimitMessagePerSecond
833 <div className="form-group row">
835 className="col-12 col-form-label"
836 htmlFor="create-site-rate-limit-post"
838 {i18n.t("rate_limit_post")}
840 <div className="col-12">
843 id="create-site-rate-limit-post"
844 className="form-control"
846 value={toUndefined(this.state.siteForm.rate_limit_post)}
847 onInput={linkEvent(this, this.handleSiteRateLimitPost)}
851 <div className="form-group row">
853 className="col-12 col-form-label"
854 htmlFor="create-site-rate-limit-post-per-second"
856 {i18n.t("per_second")}
858 <div className="col-12">
861 id="create-site-rate-limit-post-per-second"
862 className="form-control"
865 this.state.siteForm.rate_limit_post_per_second
867 onInput={linkEvent(this, this.handleSiteRateLimitPostPerSecond)}
871 <div className="form-group row">
873 className="col-12 col-form-label"
874 htmlFor="create-site-rate-limit-register"
876 {i18n.t("rate_limit_register")}
878 <div className="col-12">
881 id="create-site-rate-limit-register"
882 className="form-control"
884 value={toUndefined(this.state.siteForm.rate_limit_register)}
885 onInput={linkEvent(this, this.handleSiteRateLimitRegister)}
889 <div className="form-group row">
891 className="col-12 col-form-label"
892 htmlFor="create-site-rate-limit-register-per-second"
894 {i18n.t("per_second")}
896 <div className="col-12">
899 id="create-site-rate-limit-register-per-second"
900 className="form-control"
903 this.state.siteForm.rate_limit_register_per_second
907 this.handleSiteRateLimitRegisterPerSecond
912 <div className="form-group row">
914 className="col-12 col-form-label"
915 htmlFor="create-site-rate-limit-image"
917 {i18n.t("rate_limit_image")}
919 <div className="col-12">
922 id="create-site-rate-limit-image"
923 className="form-control"
925 value={toUndefined(this.state.siteForm.rate_limit_image)}
926 onInput={linkEvent(this, this.handleSiteRateLimitImage)}
930 <div className="form-group row">
932 className="col-12 col-form-label"
933 htmlFor="create-site-rate-limit-image-per-second"
935 {i18n.t("per_second")}
937 <div className="col-12">
940 id="create-site-rate-limit-image-per-second"
941 className="form-control"
944 this.state.siteForm.rate_limit_image_per_second
948 this.handleSiteRateLimitImagePerSecond
953 <div className="form-group row">
955 className="col-12 col-form-label"
956 htmlFor="create-site-rate-limit-comment"
958 {i18n.t("rate_limit_comment")}
960 <div className="col-12">
963 id="create-site-rate-limit-comment"
964 className="form-control"
966 value={toUndefined(this.state.siteForm.rate_limit_comment)}
967 onInput={linkEvent(this, this.handleSiteRateLimitComment)}
971 <div className="form-group row">
973 className="col-12 col-form-label"
974 htmlFor="create-site-rate-limit-comment-per-second"
976 {i18n.t("per_second")}
978 <div className="col-12">
981 id="create-site-rate-limit-comment-per-second"
982 className="form-control"
985 this.state.siteForm.rate_limit_comment_per_second
989 this.handleSiteRateLimitCommentPerSecond
994 <div className="form-group row">
996 className="col-12 col-form-label"
997 htmlFor="create-site-rate-limit-search"
999 {i18n.t("rate_limit_search")}
1001 <div className="col-12">
1004 id="create-site-rate-limit-search"
1005 className="form-control"
1007 value={toUndefined(this.state.siteForm.rate_limit_search)}
1008 onInput={linkEvent(this, this.handleSiteRateLimitSearch)}
1012 <div className="form-group row">
1014 className="col-12 col-form-label"
1015 htmlFor="create-site-rate-limit-search-per-second"
1017 {i18n.t("per_second")}
1019 <div className="col-12">
1022 id="create-site-rate-limit-search-per-second"
1023 className="form-control"
1026 this.state.siteForm.rate_limit_search_per_second
1030 this.handleSiteRateLimitSearchPerSecond
1035 <div className="form-group row">
1036 <div className="col-12">
1039 className="btn btn-secondary mr-2"
1040 disabled={this.state.loading}
1042 {this.state.loading ? (
1045 capitalizeFirstLetter(i18n.t("save"))
1047 capitalizeFirstLetter(i18n.t("create"))
1057 handleCreateSiteSubmit(i: SiteForm, event: any) {
1058 event.preventDefault();
1059 i.setState({ loading: true });
1060 i.setState(s => ((s.siteForm.auth = auth().unwrap()), s));
1062 if (i.props.siteRes.site_view.local_site.site_setup) {
1063 WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
1065 let sForm = i.state.siteForm;
1066 let form = new CreateSite({
1067 name: sForm.name.unwrapOr("My site"),
1068 sidebar: sForm.sidebar,
1069 description: sForm.description,
1071 banner: sForm.banner,
1072 community_creation_admin_only: sForm.community_creation_admin_only,
1073 enable_nsfw: sForm.enable_nsfw,
1074 enable_downvotes: sForm.enable_downvotes,
1075 require_application: sForm.require_application,
1076 application_question: sForm.application_question,
1077 open_registration: sForm.open_registration,
1078 require_email_verification: sForm.require_email_verification,
1079 private_instance: sForm.private_instance,
1080 default_theme: sForm.default_theme,
1081 default_post_listing_type: sForm.default_post_listing_type,
1082 application_email_admins: sForm.application_email_admins,
1083 auth: auth().unwrap(),
1084 hide_modlog_mod_names: sForm.hide_modlog_mod_names,
1085 legal_information: sForm.legal_information,
1086 slur_filter_regex: sForm.slur_filter_regex,
1087 actor_name_max_length: sForm.actor_name_max_length,
1088 rate_limit_message: sForm.rate_limit_message,
1089 rate_limit_message_per_second: sForm.rate_limit_message_per_second,
1090 rate_limit_comment: sForm.rate_limit_comment,
1091 rate_limit_comment_per_second: sForm.rate_limit_comment_per_second,
1092 rate_limit_image: sForm.rate_limit_image,
1093 rate_limit_image_per_second: sForm.rate_limit_image_per_second,
1094 rate_limit_post: sForm.rate_limit_post,
1095 rate_limit_post_per_second: sForm.rate_limit_post_per_second,
1096 rate_limit_register: sForm.rate_limit_register,
1097 rate_limit_register_per_second: sForm.rate_limit_register_per_second,
1098 rate_limit_search: sForm.rate_limit_search,
1099 rate_limit_search_per_second: sForm.rate_limit_search_per_second,
1100 federation_enabled: sForm.federation_enabled,
1101 federation_debug: sForm.federation_debug,
1102 federation_worker_count: sForm.federation_worker_count,
1103 federation_strict_allowlist: sForm.federation_strict_allowlist,
1104 federation_http_fetch_retry_limit:
1105 sForm.federation_http_fetch_retry_limit,
1106 captcha_enabled: sForm.captcha_enabled,
1107 captcha_difficulty: sForm.captcha_difficulty,
1108 allowed_instances: sForm.allowed_instances,
1109 blocked_instances: sForm.blocked_instances,
1110 discussion_languages: sForm.discussion_languages,
1112 WebSocketService.Instance.send(wsClient.createSite(form));
1114 i.setState(i.state);
1117 instancesToString(opt: Option<string[]>): string {
1118 return opt.map(list => list.join(",")).unwrapOr("");
1121 handleSiteAllowedInstances(i: SiteForm, event: any) {
1122 let list = splitToList(event.target.value);
1123 i.setState(s => ((s.siteForm.allowed_instances = list), s));
1126 handleSiteBlockedInstances(i: SiteForm, event: any) {
1127 let list = splitToList(event.target.value);
1128 i.setState(s => ((s.siteForm.blocked_instances = list), s));
1131 handleSiteNameChange(i: SiteForm, event: any) {
1132 i.state.siteForm.name = Some(event.target.value);
1133 i.setState(i.state);
1136 handleSiteSidebarChange(val: string) {
1137 this.setState(s => ((s.siteForm.sidebar = Some(val)), s));
1140 handleSiteLegalInfoChange(val: string) {
1141 this.setState(s => ((s.siteForm.legal_information = Some(val)), s));
1144 handleSiteApplicationQuestionChange(val: string) {
1145 this.setState(s => ((s.siteForm.application_question = Some(val)), s));
1148 handleSiteDescChange(i: SiteForm, event: any) {
1149 i.state.siteForm.description = Some(event.target.value);
1150 i.setState(i.state);
1153 handleSiteEnableNsfwChange(i: SiteForm, event: any) {
1154 i.state.siteForm.enable_nsfw = Some(event.target.checked);
1155 i.setState(i.state);
1158 handleSiteOpenRegistrationChange(i: SiteForm, event: any) {
1159 i.state.siteForm.open_registration = Some(event.target.checked);
1160 i.setState(i.state);
1163 handleSiteCommunityCreationAdminOnly(i: SiteForm, event: any) {
1164 i.state.siteForm.community_creation_admin_only = Some(event.target.checked);
1165 i.setState(i.state);
1168 handleSiteEnableDownvotesChange(i: SiteForm, event: any) {
1169 i.state.siteForm.enable_downvotes = Some(event.target.checked);
1170 i.setState(i.state);
1173 handleSiteRequireApplication(i: SiteForm, event: any) {
1174 i.state.siteForm.require_application = Some(event.target.checked);
1175 i.setState(i.state);
1178 handleSiteRequireEmailVerification(i: SiteForm, event: any) {
1179 i.state.siteForm.require_email_verification = Some(event.target.checked);
1180 i.setState(i.state);
1183 handleSiteApplicationEmailAdmins(i: SiteForm, event: any) {
1184 i.state.siteForm.application_email_admins = Some(event.target.checked);
1185 i.setState(i.state);
1188 handleSitePrivateInstance(i: SiteForm, event: any) {
1189 i.state.siteForm.private_instance = Some(event.target.checked);
1190 i.setState(i.state);
1193 handleSiteHideModlogModNames(i: SiteForm, event: any) {
1194 i.state.siteForm.hide_modlog_mod_names = Some(event.target.checked);
1195 i.setState(i.state);
1198 handleSiteDefaultTheme(i: SiteForm, event: any) {
1199 i.state.siteForm.default_theme = Some(event.target.value);
1200 i.setState(i.state);
1203 handleIconUpload(url: string) {
1204 this.setState(s => ((s.siteForm.icon = Some(url)), s));
1207 handleIconRemove() {
1208 this.setState(s => ((s.siteForm.icon = Some("")), s));
1211 handleBannerUpload(url: string) {
1212 this.setState(s => ((s.siteForm.banner = Some(url)), s));
1215 handleBannerRemove() {
1216 this.setState(s => ((s.siteForm.banner = Some("")), s));
1219 handleSiteSlurFilterRegex(i: SiteForm, event: any) {
1221 s => ((s.siteForm.slur_filter_regex = Some(event.target.value)), s)
1225 handleSiteActorNameMaxLength(i: SiteForm, event: any) {
1228 (s.siteForm.actor_name_max_length = Some(Number(event.target.value))), s
1233 handleSiteRateLimitMessage(i: SiteForm, event: any) {
1236 (s.siteForm.rate_limit_message = Some(Number(event.target.value))), s
1241 handleSiteRateLimitMessagePerSecond(i: SiteForm, event: any) {
1244 (s.siteForm.rate_limit_message_per_second = Some(
1245 Number(event.target.value)
1252 handleSiteRateLimitPost(i: SiteForm, event: any) {
1254 s => ((s.siteForm.rate_limit_post = Some(Number(event.target.value))), s)
1258 handleSiteRateLimitPostPerSecond(i: SiteForm, event: any) {
1261 (s.siteForm.rate_limit_post_per_second = Some(
1262 Number(event.target.value)
1269 handleSiteRateLimitImage(i: SiteForm, event: any) {
1271 s => ((s.siteForm.rate_limit_image = Some(Number(event.target.value))), s)
1275 handleSiteRateLimitImagePerSecond(i: SiteForm, event: any) {
1278 (s.siteForm.rate_limit_image_per_second = Some(
1279 Number(event.target.value)
1286 handleSiteRateLimitComment(i: SiteForm, event: any) {
1289 (s.siteForm.rate_limit_comment = Some(Number(event.target.value))), s
1294 handleSiteRateLimitCommentPerSecond(i: SiteForm, event: any) {
1297 (s.siteForm.rate_limit_comment_per_second = Some(
1298 Number(event.target.value)
1305 handleSiteRateLimitSearch(i: SiteForm, event: any) {
1308 (s.siteForm.rate_limit_search = Some(Number(event.target.value))), s
1313 handleSiteRateLimitSearchPerSecond(i: SiteForm, event: any) {
1316 (s.siteForm.rate_limit_search_per_second = Some(
1317 Number(event.target.value)
1324 handleSiteRateLimitRegister(i: SiteForm, event: any) {
1327 (s.siteForm.rate_limit_register = Some(Number(event.target.value))), s
1332 handleSiteRateLimitRegisterPerSecond(i: SiteForm, event: any) {
1335 (s.siteForm.rate_limit_register_per_second = Some(
1336 Number(event.target.value)
1343 handleSiteFederationEnabled(i: SiteForm, event: any) {
1344 i.state.siteForm.federation_enabled = Some(event.target.checked);
1345 i.setState(i.state);
1348 handleSiteFederationDebug(i: SiteForm, event: any) {
1349 i.state.siteForm.federation_debug = Some(event.target.checked);
1350 i.setState(i.state);
1353 handleSiteFederationStrictAllowList(i: SiteForm, event: any) {
1354 i.state.siteForm.federation_strict_allowlist = Some(event.target.checked);
1355 i.setState(i.state);
1358 handleSiteFederationWorkerCount(i: SiteForm, event: any) {
1361 (s.siteForm.federation_worker_count = Some(Number(event.target.value))),
1367 handleSiteFederationHttpFetchRetryLimit(i: SiteForm, event: any) {
1370 (s.siteForm.federation_http_fetch_retry_limit = Some(
1371 Number(event.target.value)
1378 handleSiteCaptchaEnabled(i: SiteForm, event: any) {
1379 i.state.siteForm.captcha_enabled = Some(event.target.checked);
1380 i.setState(i.state);
1383 handleSiteCaptchaDifficulty(i: SiteForm, event: any) {
1385 s => ((s.siteForm.captcha_difficulty = Some(event.target.value)), s)
1389 handleDiscussionLanguageChange(val: number[]) {
1390 this.setState(s => ((s.siteForm.discussion_languages = Some(val)), s));
1393 handleDefaultPostListingTypeChange(val: ListingType) {
1396 (s.siteForm.default_post_listing_type = Some(
1397 ListingType[ListingType[val]]
1405 function splitToList(commaList: string): Option<string[]> {
1406 if (commaList !== "") {
1407 let list = commaList.trim().split(",");