import { Component } from "inferno"; import { CreateCommunity as CreateCommunityI, GetSiteResponse, } from "lemmy-js-client"; import { i18n } from "../../i18next"; import { HttpService } from "../../services/HttpService"; import { enableNsfw, setIsoData } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { CommunityForm } from "./community-form"; interface CreateCommunityState { siteRes: GetSiteResponse; loading: boolean; } export class CreateCommunity extends Component { private isoData = setIsoData(this.context); state: CreateCommunityState = { siteRes: this.isoData.site_res, loading: false, }; constructor(props: any, context: any) { super(props, context); this.handleCommunityCreate = this.handleCommunityCreate.bind(this); } get documentTitle(): string { return `${i18n.t("create_community")} - ${ this.state.siteRes.site_view.site.name }`; } render() { return (
{i18n.t("create_community")}
); } async handleCommunityCreate(form: CreateCommunityI) { this.setState({ loading: true }); const res = await HttpService.client.createCommunity(form); if (res.state === "success") { const name = res.data.community_view.community.name; this.props.history.replace(`/c/${name}`); } else { this.setState({ loading: false }); } } }