1 import { Component } from "inferno";
3 CreateCommunity as CreateCommunityI,
5 } from "lemmy-js-client";
6 import { i18n } from "../../i18next";
7 import { HttpService } from "../../services/HttpService";
8 import { enableNsfw, setIsoData } from "../../utils";
9 import { HtmlTags } from "../common/html-tags";
10 import { CommunityForm } from "./community-form";
12 interface CreateCommunityState {
13 siteRes: GetSiteResponse;
16 export class CreateCommunity extends Component<any, CreateCommunityState> {
17 private isoData = setIsoData(this.context);
18 state: CreateCommunityState = {
19 siteRes: this.isoData.site_res,
21 constructor(props: any, context: any) {
22 super(props, context);
23 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
26 get documentTitle(): string {
27 return `${i18n.t("create_community")} - ${
28 this.state.siteRes.site_view.site.name
34 <div className="container-lg">
36 title={this.documentTitle}
37 path={this.context.router.route.match.url}
40 <div className="col-12 col-lg-6 offset-lg-3 mb-4">
41 <h5>{i18n.t("create_community")}</h5>
43 onUpsertCommunity={this.handleCommunityCreate}
44 enableNsfw={enableNsfw(this.state.siteRes)}
45 allLanguages={this.state.siteRes.all_languages}
46 siteLanguages={this.state.siteRes.discussion_languages}
47 communityLanguages={this.state.siteRes.discussion_languages}
55 async handleCommunityCreate(form: CreateCommunityI) {
56 const res = await HttpService.client.createCommunity(form);
57 if (res.state === "success") {
58 const name = res.data.community_view.community.name;
59 this.props.history.replace(`/c/${name}`);