1 import { None } from "@sniptt/monads";
2 import { Component } from "inferno";
3 import { CommunityView, GetSiteResponse } from "lemmy-js-client";
4 import { Subscription } from "rxjs";
5 import { i18n } from "../../i18next";
6 import { UserService } from "../../services";
14 import { HtmlTags } from "../common/html-tags";
15 import { Spinner } from "../common/icon";
16 import { CommunityForm } from "./community-form";
18 interface CreateCommunityState {
19 siteRes: GetSiteResponse;
23 export class CreateCommunity extends Component<any, CreateCommunityState> {
24 private isoData = setIsoData(this.context);
25 private subscription: Subscription;
26 private emptyState: CreateCommunityState = {
27 siteRes: this.isoData.site_res,
30 constructor(props: any, context: any) {
31 super(props, context);
32 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
33 this.state = this.emptyState;
35 this.parseMessage = this.parseMessage.bind(this);
36 this.subscription = wsSubscribe(this.parseMessage);
38 if (UserService.Instance.myUserInfo.isNone() && isBrowser()) {
39 toast(i18n.t("not_logged_in"), "danger");
40 this.context.router.history.push(`/login`);
44 componentWillUnmount() {
46 this.subscription.unsubscribe();
50 get documentTitle(): string {
51 return this.state.siteRes.site_view.match({
52 some: siteView => `${i18n.t("create_community")} - ${siteView.site.name}`,
59 <div class="container">
61 title={this.documentTitle}
62 path={this.context.router.route.match.url}
66 {this.state.loading ? (
72 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
73 <h5>{i18n.t("create_community")}</h5>
76 onCreate={this.handleCommunityCreate}
77 enableNsfw={enableNsfw(this.state.siteRes)}
86 handleCommunityCreate(cv: CommunityView) {
87 this.props.history.push(`/c/${cv.community.name}`);
90 parseMessage(msg: any) {
92 toast(i18n.t(msg.error), "danger");