2022-06-21 21:42:29 +00:00
|
|
|
import { None, Option, Some } from "@sniptt/monads";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { Prompt } from "inferno-router";
|
2022-06-21 21:42:29 +00:00
|
|
|
import {
|
|
|
|
CreateSite,
|
|
|
|
EditSite,
|
|
|
|
ListingType,
|
|
|
|
Site,
|
|
|
|
toUndefined,
|
|
|
|
} from "lemmy-js-client";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { WebSocketService } from "../../services";
|
2022-02-25 13:35:17 +00:00
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
auth,
|
2022-02-25 13:35:17 +00:00
|
|
|
capitalizeFirstLetter,
|
2022-03-02 15:35:59 +00:00
|
|
|
fetchThemeList,
|
2022-02-25 13:35:17 +00:00
|
|
|
wsClient,
|
|
|
|
} from "../../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { Spinner } from "../common/icon";
|
|
|
|
import { ImageUploadForm } from "../common/image-upload-form";
|
2022-05-23 19:19:14 +00:00
|
|
|
import { ListingTypeSelect } from "../common/listing-type-select";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { MarkdownTextArea } from "../common/markdown-textarea";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface SiteFormProps {
|
2022-06-21 21:42:29 +00:00
|
|
|
site: Option<Site>; // If a site is given, that means this is an edit
|
|
|
|
showLocal?: boolean;
|
|
|
|
onCancel?(): void;
|
|
|
|
onEdit?(): void;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface SiteFormState {
|
2020-12-24 01:58:27 +00:00
|
|
|
siteForm: EditSite;
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
themeList: Option<string[]>;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
|
|
|
private emptyState: SiteFormState = {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteForm: new EditSite({
|
|
|
|
enable_downvotes: Some(true),
|
|
|
|
open_registration: Some(true),
|
|
|
|
enable_nsfw: Some(true),
|
|
|
|
name: None,
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
|
|
|
require_email_verification: None,
|
|
|
|
require_application: None,
|
|
|
|
application_question: None,
|
|
|
|
private_instance: None,
|
|
|
|
default_theme: None,
|
|
|
|
sidebar: None,
|
|
|
|
default_post_listing_type: None,
|
|
|
|
legal_information: None,
|
|
|
|
description: None,
|
|
|
|
community_creation_admin_only: None,
|
|
|
|
auth: undefined,
|
2022-06-04 16:47:10 +00:00
|
|
|
hide_modlog_mod_names: Some(true),
|
2022-06-21 21:42:29 +00:00
|
|
|
}),
|
2020-09-06 16:15:25 +00:00
|
|
|
loading: false,
|
2022-06-21 21:42:29 +00:00
|
|
|
themeList: None,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = this.emptyState;
|
2021-04-23 22:26:36 +00:00
|
|
|
this.handleSiteSidebarChange = this.handleSiteSidebarChange.bind(this);
|
2022-05-26 20:48:58 +00:00
|
|
|
this.handleSiteLegalInfoChange = this.handleSiteLegalInfoChange.bind(this);
|
2021-12-30 15:26:45 +00:00
|
|
|
this.handleSiteApplicationQuestionChange =
|
|
|
|
this.handleSiteApplicationQuestionChange.bind(this);
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
this.handleIconUpload = this.handleIconUpload.bind(this);
|
|
|
|
this.handleIconRemove = this.handleIconRemove.bind(this);
|
|
|
|
|
|
|
|
this.handleBannerUpload = this.handleBannerUpload.bind(this);
|
|
|
|
this.handleBannerRemove = this.handleBannerRemove.bind(this);
|
|
|
|
|
2022-05-23 19:19:14 +00:00
|
|
|
this.handleDefaultPostListingTypeChange =
|
|
|
|
this.handleDefaultPostListingTypeChange.bind(this);
|
|
|
|
|
2022-09-22 15:03:35 +00:00
|
|
|
if (this.props.site.isSome()) {
|
|
|
|
let site = this.props.site.unwrap();
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
|
|
|
siteForm: new EditSite({
|
2022-06-21 21:42:29 +00:00
|
|
|
name: Some(site.name),
|
|
|
|
sidebar: site.sidebar,
|
|
|
|
description: site.description,
|
|
|
|
enable_downvotes: Some(site.enable_downvotes),
|
|
|
|
open_registration: Some(site.open_registration),
|
|
|
|
enable_nsfw: Some(site.enable_nsfw),
|
|
|
|
community_creation_admin_only: Some(
|
|
|
|
site.community_creation_admin_only
|
|
|
|
),
|
|
|
|
icon: site.icon,
|
|
|
|
banner: site.banner,
|
|
|
|
require_email_verification: Some(site.require_email_verification),
|
|
|
|
require_application: Some(site.require_application),
|
|
|
|
application_question: site.application_question,
|
|
|
|
private_instance: Some(site.private_instance),
|
|
|
|
default_theme: Some(site.default_theme),
|
|
|
|
default_post_listing_type: Some(site.default_post_listing_type),
|
|
|
|
legal_information: site.legal_information,
|
2022-06-04 16:47:10 +00:00
|
|
|
hide_modlog_mod_names: site.hide_modlog_mod_names,
|
2022-06-23 14:05:56 +00:00
|
|
|
auth: undefined,
|
2022-09-22 15:03:35 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:35:59 +00:00
|
|
|
async componentDidMount() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ themeList: Some(await fetchThemeList()) });
|
2022-03-02 15:35:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
// Necessary to stop the loading
|
|
|
|
componentWillReceiveProps() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ loading: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
if (
|
|
|
|
!this.state.loading &&
|
2022-06-21 21:42:29 +00:00
|
|
|
this.props.site.isNone() &&
|
2021-04-23 22:26:36 +00:00
|
|
|
(this.state.siteForm.name ||
|
|
|
|
this.state.siteForm.sidebar ||
|
2021-12-30 15:26:45 +00:00
|
|
|
this.state.siteForm.application_question ||
|
2021-04-23 22:26:36 +00:00
|
|
|
this.state.siteForm.description)
|
2020-09-06 16:15:25 +00:00
|
|
|
) {
|
|
|
|
window.onbeforeunload = () => true;
|
|
|
|
} else {
|
|
|
|
window.onbeforeunload = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Prompt
|
|
|
|
when={
|
|
|
|
!this.state.loading &&
|
2022-06-21 21:42:29 +00:00
|
|
|
this.props.site.isNone() &&
|
2021-04-23 22:26:36 +00:00
|
|
|
(this.state.siteForm.name ||
|
|
|
|
this.state.siteForm.sidebar ||
|
2021-12-30 15:26:45 +00:00
|
|
|
this.state.siteForm.application_question ||
|
2021-04-23 22:26:36 +00:00
|
|
|
this.state.siteForm.description)
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2021-02-22 02:39:04 +00:00
|
|
|
message={i18n.t("block_leaving")}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
<form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
|
|
|
|
<h5>{`${
|
2022-06-21 21:42:29 +00:00
|
|
|
this.props.site.isSome()
|
2021-02-22 02:39:04 +00:00
|
|
|
? capitalizeFirstLetter(i18n.t("save"))
|
|
|
|
: capitalizeFirstLetter(i18n.t("name"))
|
|
|
|
} ${i18n.t("your_site")}`}</h5>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-12 col-form-label" htmlFor="create-site-name">
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("name")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="create-site-name"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control"
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.siteForm.name)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onInput={linkEvent(this, this.handleSiteNameChange)}
|
|
|
|
required
|
|
|
|
minLength={3}
|
|
|
|
maxLength={20}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
2021-02-22 02:39:04 +00:00
|
|
|
<label>{i18n.t("icon")}</label>
|
2020-09-06 16:15:25 +00:00
|
|
|
<ImageUploadForm
|
2021-02-22 02:39:04 +00:00
|
|
|
uploadTitle={i18n.t("upload_icon")}
|
2020-09-06 16:15:25 +00:00
|
|
|
imageSrc={this.state.siteForm.icon}
|
|
|
|
onUpload={this.handleIconUpload}
|
|
|
|
onRemove={this.handleIconRemove}
|
|
|
|
rounded
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group">
|
2021-02-22 02:39:04 +00:00
|
|
|
<label>{i18n.t("banner")}</label>
|
2020-09-06 16:15:25 +00:00
|
|
|
<ImageUploadForm
|
2021-02-22 02:39:04 +00:00
|
|
|
uploadTitle={i18n.t("upload_banner")}
|
2020-09-06 16:15:25 +00:00
|
|
|
imageSrc={this.state.siteForm.banner}
|
|
|
|
onUpload={this.handleBannerUpload}
|
|
|
|
onRemove={this.handleBannerRemove}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-12 col-form-label" htmlFor="site-desc">
|
2021-04-23 22:26:36 +00:00
|
|
|
{i18n.t("description")}
|
|
|
|
</label>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12">
|
2021-04-23 22:26:36 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-control"
|
2021-04-23 22:26:36 +00:00
|
|
|
id="site-desc"
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.siteForm.description)}
|
2021-04-23 22:26:36 +00:00
|
|
|
onInput={linkEvent(this, this.handleSiteDescChange)}
|
|
|
|
maxLength={150}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-12 col-form-label">{i18n.t("sidebar")}</label>
|
|
|
|
<div className="col-12">
|
2020-09-06 16:15:25 +00:00
|
|
|
<MarkdownTextArea
|
2021-04-23 22:26:36 +00:00
|
|
|
initialContent={this.state.siteForm.sidebar}
|
2022-09-22 15:14:58 +00:00
|
|
|
initialLanguageId={None}
|
2022-06-21 21:42:29 +00:00
|
|
|
placeholder={None}
|
|
|
|
buttonTitle={None}
|
|
|
|
maxLength={None}
|
2021-04-23 22:26:36 +00:00
|
|
|
onContentChange={this.handleSiteSidebarChange}
|
2020-09-06 16:15:25 +00:00
|
|
|
hideNavigationWarnings
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={[]}
|
2020-09-06 16:15:25 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-12 col-form-label">
|
2022-05-26 20:48:58 +00:00
|
|
|
{i18n.t("legal_information")}
|
|
|
|
</label>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12">
|
2022-05-26 20:48:58 +00:00
|
|
|
<MarkdownTextArea
|
|
|
|
initialContent={this.state.siteForm.legal_information}
|
2022-09-22 15:14:58 +00:00
|
|
|
initialLanguageId={None}
|
2022-06-21 21:42:29 +00:00
|
|
|
placeholder={None}
|
|
|
|
buttonTitle={None}
|
|
|
|
maxLength={None}
|
2022-05-26 20:48:58 +00:00
|
|
|
onContentChange={this.handleSiteLegalInfoChange}
|
|
|
|
hideNavigationWarnings
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={[]}
|
2022-05-26 20:48:58 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.siteForm.require_application.unwrapOr(false) && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-12 col-form-label">
|
2021-12-30 15:26:45 +00:00
|
|
|
{i18n.t("application_questionnaire")}
|
|
|
|
</label>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="col-12">
|
2021-12-30 15:26:45 +00:00
|
|
|
<MarkdownTextArea
|
|
|
|
initialContent={this.state.siteForm.application_question}
|
2022-09-22 15:14:58 +00:00
|
|
|
initialLanguageId={None}
|
2022-06-21 21:42:29 +00:00
|
|
|
placeholder={None}
|
|
|
|
buttonTitle={None}
|
|
|
|
maxLength={None}
|
2021-12-30 15:26:45 +00:00
|
|
|
onContentChange={this.handleSiteApplicationQuestionChange}
|
|
|
|
hideNavigationWarnings
|
2022-09-22 15:14:58 +00:00
|
|
|
allLanguages={[]}
|
2021-12-30 15:26:45 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2020-09-06 16:15:25 +00:00
|
|
|
id="create-site-downvotes"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(this.state.siteForm.enable_downvotes)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSiteEnableDownvotesChange
|
|
|
|
)}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<label
|
|
|
|
className="form-check-label"
|
|
|
|
htmlFor="create-site-downvotes"
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("enable_downvotes")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2020-09-06 16:15:25 +00:00
|
|
|
id="create-site-enable-nsfw"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(this.state.siteForm.enable_nsfw)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={linkEvent(this, this.handleSiteEnableNsfwChange)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2020-09-06 16:15:25 +00:00
|
|
|
htmlFor="create-site-enable-nsfw"
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("enable_nsfw")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2020-09-06 16:15:25 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2020-09-06 16:15:25 +00:00
|
|
|
id="create-site-open-registration"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(this.state.siteForm.open_registration)}
|
2020-09-06 16:15:25 +00:00
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSiteOpenRegistrationChange
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2020-09-06 16:15:25 +00:00
|
|
|
htmlFor="create-site-open-registration"
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("open_registration")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2021-04-24 03:55:51 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2021-04-24 03:55:51 +00:00
|
|
|
id="create-site-community-creation-admin-only"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(
|
|
|
|
this.state.siteForm.community_creation_admin_only
|
|
|
|
)}
|
2021-04-24 03:55:51 +00:00
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSiteCommunityCreationAdminOnly
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-04-24 03:55:51 +00:00
|
|
|
htmlFor="create-site-community-creation-admin-only"
|
|
|
|
>
|
|
|
|
{i18n.t("community_creation_admin_only")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2021-12-30 15:26:45 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2021-12-30 15:26:45 +00:00
|
|
|
id="create-site-require-email-verification"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(
|
|
|
|
this.state.siteForm.require_email_verification
|
|
|
|
)}
|
2021-12-30 15:26:45 +00:00
|
|
|
onChange={linkEvent(
|
|
|
|
this,
|
|
|
|
this.handleSiteRequireEmailVerification
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-12-30 15:26:45 +00:00
|
|
|
htmlFor="create-site-require-email-verification"
|
|
|
|
>
|
|
|
|
{i18n.t("require_email_verification")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2021-12-30 15:26:45 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2021-12-30 15:26:45 +00:00
|
|
|
id="create-site-require-application"
|
|
|
|
type="checkbox"
|
2022-06-21 21:42:29 +00:00
|
|
|
checked={toUndefined(this.state.siteForm.require_application)}
|
2021-12-30 15:26:45 +00:00
|
|
|
onChange={linkEvent(this, this.handleSiteRequireApplication)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-12-30 15:26:45 +00:00
|
|
|
htmlFor="create-site-require-application"
|
|
|
|
>
|
|
|
|
{i18n.t("require_registration_application")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
2022-02-25 13:35:17 +00:00
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label mr-2"
|
2022-02-25 13:35:17 +00:00
|
|
|
htmlFor="create-site-default-theme"
|
|
|
|
>
|
|
|
|
{i18n.t("theme")}
|
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
id="create-site-default-theme"
|
2022-06-21 21:42:29 +00:00
|
|
|
value={toUndefined(this.state.siteForm.default_theme)}
|
2022-02-25 13:35:17 +00:00
|
|
|
onChange={linkEvent(this, this.handleSiteDefaultTheme)}
|
2022-09-22 15:03:35 +00:00
|
|
|
className="custom-select w-auto"
|
2022-02-25 13:35:17 +00:00
|
|
|
>
|
|
|
|
<option value="browser">{i18n.t("browser_default")}</option>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.state.themeList.unwrapOr([]).map(theme => (
|
2022-09-22 15:03:35 +00:00
|
|
|
<option key={theme} value={theme}>
|
|
|
|
{theme}
|
|
|
|
</option>
|
2022-02-25 13:35:17 +00:00
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-23 19:19:14 +00:00
|
|
|
{this.props.showLocal && (
|
|
|
|
<form className="form-group row">
|
2022-09-22 15:03:35 +00:00
|
|
|
<label className="col-sm-3">{i18n.t("listing_type")}</label>
|
|
|
|
<div className="col-sm-9">
|
2022-05-23 19:19:14 +00:00
|
|
|
<ListingTypeSelect
|
|
|
|
type_={
|
2022-06-21 21:42:29 +00:00
|
|
|
ListingType[
|
|
|
|
this.state.siteForm.default_post_listing_type.unwrapOr(
|
|
|
|
"Local"
|
|
|
|
)
|
|
|
|
]
|
2022-05-23 19:19:14 +00:00
|
|
|
}
|
|
|
|
showLocal
|
|
|
|
showSubscribed={false}
|
|
|
|
onChange={this.handleDefaultPostListingTypeChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
)}
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2021-12-30 15:26:45 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2021-12-30 15:26:45 +00:00
|
|
|
id="create-site-private-instance"
|
|
|
|
type="checkbox"
|
2022-09-21 14:05:54 +00:00
|
|
|
checked={toUndefined(this.state.siteForm.private_instance)}
|
2021-12-30 15:26:45 +00:00
|
|
|
onChange={linkEvent(this, this.handleSitePrivateInstance)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2021-12-30 15:26:45 +00:00
|
|
|
htmlFor="create-site-private-instance"
|
|
|
|
>
|
|
|
|
{i18n.t("private_instance")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
|
|
|
<div className="form-check">
|
2022-06-04 16:47:10 +00:00
|
|
|
<input
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-input"
|
2022-06-04 16:47:10 +00:00
|
|
|
id="create-site-hide-modlog-mod-names"
|
|
|
|
type="checkbox"
|
2022-08-17 23:28:40 +00:00
|
|
|
checked={toUndefined(
|
|
|
|
this.state.siteForm.hide_modlog_mod_names
|
|
|
|
)}
|
2022-06-04 16:47:10 +00:00
|
|
|
onChange={linkEvent(this, this.handleSiteHideModlogModNames)}
|
|
|
|
/>
|
|
|
|
<label
|
2022-09-22 15:03:35 +00:00
|
|
|
className="form-check-label"
|
2022-06-04 16:47:10 +00:00
|
|
|
htmlFor="create-site-hide-modlog-mod-names"
|
|
|
|
>
|
|
|
|
{i18n.t("hide_modlog_mod_names")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-12">
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary mr-2"
|
2020-09-06 16:15:25 +00:00
|
|
|
disabled={this.state.loading}
|
|
|
|
>
|
|
|
|
{this.state.loading ? (
|
2021-02-11 20:35:27 +00:00
|
|
|
<Spinner />
|
2022-06-21 21:42:29 +00:00
|
|
|
) : this.props.site.isSome() ? (
|
2021-02-22 02:39:04 +00:00
|
|
|
capitalizeFirstLetter(i18n.t("save"))
|
2020-09-06 16:15:25 +00:00
|
|
|
) : (
|
2021-02-22 02:39:04 +00:00
|
|
|
capitalizeFirstLetter(i18n.t("create"))
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
</button>
|
2022-06-21 21:42:29 +00:00
|
|
|
{this.props.site.isSome() && (
|
2020-09-06 16:15:25 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
2022-09-22 15:03:35 +00:00
|
|
|
className="btn btn-secondary"
|
2020-09-06 16:15:25 +00:00
|
|
|
onClick={linkEvent(this, this.handleCancel)}
|
|
|
|
>
|
2021-02-22 02:39:04 +00:00
|
|
|
{i18n.t("cancel")}
|
2020-09-06 16:15:25 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCreateSiteSubmit(i: SiteForm, event: any) {
|
|
|
|
event.preventDefault();
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ loading: true });
|
|
|
|
i.setState(s => ((s.siteForm.auth = auth().unwrap()), s));
|
2022-06-21 21:42:29 +00:00
|
|
|
|
|
|
|
if (i.props.site.isSome()) {
|
2020-12-24 22:05:57 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm));
|
2022-04-28 20:42:15 +00:00
|
|
|
i.props.onEdit();
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2022-06-21 21:42:29 +00:00
|
|
|
let sForm = i.state.siteForm;
|
|
|
|
let form = new CreateSite({
|
|
|
|
name: sForm.name.unwrapOr("My site"),
|
|
|
|
sidebar: sForm.sidebar,
|
|
|
|
description: sForm.description,
|
|
|
|
icon: sForm.icon,
|
|
|
|
banner: sForm.banner,
|
|
|
|
community_creation_admin_only: sForm.community_creation_admin_only,
|
|
|
|
enable_nsfw: sForm.enable_nsfw,
|
|
|
|
enable_downvotes: sForm.enable_downvotes,
|
|
|
|
require_application: sForm.require_application,
|
|
|
|
application_question: sForm.application_question,
|
|
|
|
open_registration: sForm.open_registration,
|
|
|
|
require_email_verification: sForm.require_email_verification,
|
|
|
|
private_instance: sForm.private_instance,
|
|
|
|
default_theme: sForm.default_theme,
|
|
|
|
default_post_listing_type: sForm.default_post_listing_type,
|
|
|
|
auth: auth().unwrap(),
|
2022-08-17 23:28:40 +00:00
|
|
|
hide_modlog_mod_names: sForm.hide_modlog_mod_names,
|
2022-06-21 21:42:29 +00:00
|
|
|
});
|
2021-04-23 21:48:31 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.createSite(form));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSiteNameChange(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.name = Some(event.target.value);
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-04-23 22:26:36 +00:00
|
|
|
handleSiteSidebarChange(val: string) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.sidebar = Some(val)), s));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 20:48:58 +00:00
|
|
|
handleSiteLegalInfoChange(val: string) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.legal_information = Some(val)), s));
|
2022-05-26 20:48:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
handleSiteApplicationQuestionChange(val: string) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.application_question = Some(val)), s));
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 22:26:36 +00:00
|
|
|
handleSiteDescChange(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.description = Some(event.target.value);
|
2021-04-23 22:26:36 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleSiteEnableNsfwChange(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.enable_nsfw = Some(event.target.checked);
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSiteOpenRegistrationChange(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.open_registration = Some(event.target.checked);
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-04-24 03:55:51 +00:00
|
|
|
handleSiteCommunityCreationAdminOnly(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.community_creation_admin_only = Some(event.target.checked);
|
2021-04-24 03:55:51 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleSiteEnableDownvotesChange(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.enable_downvotes = Some(event.target.checked);
|
2020-09-06 16:15:25 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
handleSiteRequireApplication(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.require_application = Some(event.target.checked);
|
2021-12-30 15:26:45 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSiteRequireEmailVerification(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.require_email_verification = Some(event.target.checked);
|
2021-12-30 15:26:45 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSitePrivateInstance(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.private_instance = Some(event.target.checked);
|
2021-12-30 15:26:45 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2022-06-04 16:47:10 +00:00
|
|
|
handleSiteHideModlogModNames(i: SiteForm, event: any) {
|
|
|
|
i.state.siteForm.hide_modlog_mod_names = Some(event.target.checked);
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2022-02-25 13:35:17 +00:00
|
|
|
handleSiteDefaultTheme(i: SiteForm, event: any) {
|
2022-06-21 21:42:29 +00:00
|
|
|
i.state.siteForm.default_theme = Some(event.target.value);
|
2022-02-25 13:35:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
handleCancel(i: SiteForm) {
|
|
|
|
i.props.onCancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleIconUpload(url: string) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.icon = Some(url)), s));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleIconRemove() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.icon = Some("")), s));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleBannerUpload(url: string) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.banner = Some(url)), s));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleBannerRemove() {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(s => ((s.siteForm.banner = Some("")), s));
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
2022-05-23 19:19:14 +00:00
|
|
|
|
|
|
|
handleDefaultPostListingTypeChange(val: ListingType) {
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState(
|
|
|
|
s => (
|
|
|
|
(s.siteForm.default_post_listing_type = Some(
|
|
|
|
ListingType[ListingType[val]]
|
|
|
|
)),
|
|
|
|
s
|
|
|
|
)
|
2022-06-21 21:42:29 +00:00
|
|
|
);
|
2022-05-23 19:19:14 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|