1 import { enableNsfw, setIsoData } from "@utils/app";
2 import { Component } from "inferno";
4 CreateCommunity as CreateCommunityI,
6 } from "lemmy-js-client";
7 import { HttpService, I18NextService } from "../../services";
8 import { HtmlTags } from "../common/html-tags";
9 import { CommunityForm } from "./community-form";
11 interface CreateCommunityState {
12 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,
22 constructor(props: any, context: any) {
23 super(props, context);
24 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
27 get documentTitle(): string {
28 return `${I18NextService.i18n.t("create_community")} - ${
29 this.state.siteRes.site_view.site.name
35 <div className="create-community container-lg">
37 title={this.documentTitle}
38 path={this.context.router.route.match.url}
41 <div className="col-12 col-lg-6 offset-lg-3 mb-4">
42 <h5>{I18NextService.i18n.t("create_community")}</h5>
44 onUpsertCommunity={this.handleCommunityCreate}
45 enableNsfw={enableNsfw(this.state.siteRes)}
46 allLanguages={this.state.siteRes.all_languages}
47 siteLanguages={this.state.siteRes.discussion_languages}
48 communityLanguages={this.state.siteRes.discussion_languages}
49 loading={this.state.loading}
57 async handleCommunityCreate(form: CreateCommunityI) {
58 this.setState({ loading: true });
60 const res = await HttpService.client.createCommunity(form);
62 if (res.state === "success") {
63 const name = res.data.community_view.community.name;
64 this.props.history.replace(`/c/${name}`);
66 this.setState({ loading: false });