2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
2022-06-21 21:42:29 +00:00
|
|
|
import {
|
2023-06-14 12:20:40 +00:00
|
|
|
CreateCommunity as CreateCommunityI,
|
|
|
|
GetSiteResponse,
|
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { HttpService } from "../../services/HttpService";
|
|
|
|
import { enableNsfw, setIsoData } from "../../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { CommunityForm } from "./community-form";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface CreateCommunityState {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2023-06-14 13:32:25 +00:00
|
|
|
loading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class CreateCommunity extends Component<any, CreateCommunityState> {
|
2020-09-07 22:24:48 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
state: CreateCommunityState = {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2023-06-14 13:32:25 +00:00
|
|
|
loading: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
return `${i18n.t("create_community")} - ${
|
|
|
|
this.state.siteRes.site_view.site.name
|
|
|
|
}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2023-06-14 12:20:40 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3 mb-4">
|
|
|
|
<h5>{i18n.t("create_community")}</h5>
|
|
|
|
<CommunityForm
|
|
|
|
onUpsertCommunity={this.handleCommunityCreate}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
communityLanguages={this.state.siteRes.discussion_languages}
|
2023-06-14 13:39:19 +00:00
|
|
|
loading={this.state.loading}
|
2023-06-14 12:20:40 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCommunityCreate(form: CreateCommunityI) {
|
2023-06-14 13:32:25 +00:00
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
const res = await HttpService.client.createCommunity(form);
|
2023-06-14 13:32:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
if (res.state === "success") {
|
|
|
|
const name = res.data.community_view.community.name;
|
|
|
|
this.props.history.replace(`/c/${name}`);
|
2023-06-14 13:32:25 +00:00
|
|
|
} else {
|
|
|
|
this.setState({ loading: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|