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;
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="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 isLoading={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 });