import { None, Some } from "@sniptt/monads"; import { Component } from "inferno"; import { CommunityView, GetSiteResponse } from "lemmy-js-client"; import { Subscription } from "rxjs"; import { i18n } from "../../i18next"; import { UserService } from "../../services"; import { enableNsfw, isBrowser, setIsoData, toast, wsSubscribe, } from "../../utils"; import { HtmlTags } from "../common/html-tags"; import { Spinner } from "../common/icon"; import { CommunityForm } from "./community-form"; interface CreateCommunityState { siteRes: GetSiteResponse; loading: boolean; } export class CreateCommunity extends Component { private isoData = setIsoData(this.context); private subscription: Subscription; private emptyState: CreateCommunityState = { siteRes: this.isoData.site_res, loading: false, }; constructor(props: any, context: any) { super(props, context); this.handleCommunityCreate = this.handleCommunityCreate.bind(this); this.state = this.emptyState; this.parseMessage = this.parseMessage.bind(this); this.subscription = wsSubscribe(this.parseMessage); if (UserService.Instance.myUserInfo.isNone() && isBrowser()) { toast(i18n.t("not_logged_in"), "danger"); this.context.router.history.push(`/login`); } } componentWillUnmount() { if (isBrowser()) { this.subscription.unsubscribe(); } } get documentTitle(): string { return `${i18n.t("create_community")} - ${ this.state.siteRes.site_view.site.name }`; } render() { return (
{this.state.loading ? (
) : (
{i18n.t("create_community")}
)}
); } handleCommunityCreate(cv: CommunityView) { this.props.history.push(`/c/${cv.community.name}`); } parseMessage(msg: any) { if (msg.error) { toast(i18n.t(msg.error), "danger"); } } }