1 import { enableNsfw, setIsoData } from "@utils/app";
2 import { Component } from "inferno";
4 CreateCommunity as CreateCommunityI,
6 } from "lemmy-js-client";
7 import { FirstLoadService, 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);
26 FirstLoadService.isFirstLoad;
29 get documentTitle(): string {
30 return `${I18NextService.i18n.t("create_community")} - ${
31 this.state.siteRes.site_view.site.name
37 <div className="create-community container-lg">
39 title={this.documentTitle}
40 path={this.context.router.route.match.url}
43 <div className="col-12 col-lg-6 offset-lg-3 mb-4">
44 <h5>{I18NextService.i18n.t("create_community")}</h5>
46 onUpsertCommunity={this.handleCommunityCreate}
47 enableNsfw={enableNsfw(this.state.siteRes)}
48 allLanguages={this.state.siteRes.all_languages}
49 siteLanguages={this.state.siteRes.discussion_languages}
50 communityLanguages={this.state.siteRes.discussion_languages}
51 loading={this.state.loading}
59 async handleCommunityCreate(form: CreateCommunityI) {
60 this.setState({ loading: true });
62 const res = await HttpService.client.createCommunity(form);
64 if (res.state === "success") {
65 const name = res.data.community_view.community.name;
66 this.props.history.replace(`/c/${name}`);
68 this.setState({ loading: false });