1 import { enableNsfw, setIsoData } from "@utils/app";
2 import { Component } from "inferno";
4 CreateCommunity as CreateCommunityI,
6 } from "lemmy-js-client";
7 import { i18n } from "../../i18next";
8 import { HttpService } from "../../services/HttpService";
9 import { HtmlTags } from "../common/html-tags";
10 import { CommunityForm } from "./community-form";
12 interface CreateCommunityState {
13 siteRes: GetSiteResponse;
17 export class CreateCommunity extends Component<any, CreateCommunityState> {
18 private isoData = setIsoData(this.context);
19 state: CreateCommunityState = {
20 siteRes: this.isoData.site_res,
23 constructor(props: any, context: any) {
24 super(props, context);
25 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
28 get documentTitle(): string {
29 return `${i18n.t("create_community")} - ${
30 this.state.siteRes.site_view.site.name
36 <div className="create-community container-lg">
38 title={this.documentTitle}
39 path={this.context.router.route.match.url}
42 <div className="col-12 col-lg-6 offset-lg-3 mb-4">
43 <h5>{i18n.t("create_community")}</h5>
45 onUpsertCommunity={this.handleCommunityCreate}
46 enableNsfw={enableNsfw(this.state.siteRes)}
47 allLanguages={this.state.siteRes.all_languages}
48 siteLanguages={this.state.siteRes.discussion_languages}
49 communityLanguages={this.state.siteRes.discussion_languages}
50 loading={this.state.loading}
58 async handleCommunityCreate(form: CreateCommunityI) {
59 this.setState({ loading: true });
61 const res = await HttpService.client.createCommunity(form);
63 if (res.state === "success") {
64 const name = res.data.community_view.community.name;
65 this.props.history.replace(`/c/${name}`);
67 this.setState({ loading: false });