1 import { Component } from "inferno";
2 import { CommunityView, SiteView } from "lemmy-js-client";
3 import { Subscription } from "rxjs";
4 import { i18n } from "../../i18next";
5 import { UserService } from "../../services";
6 import { isBrowser, setIsoData, toast, wsSubscribe } from "../../utils";
7 import { HtmlTags } from "../common/html-tags";
8 import { Spinner } from "../common/icon";
9 import { CommunityForm } from "./community-form";
11 interface CreateCommunityState {
16 export class CreateCommunity extends Component<any, CreateCommunityState> {
17 private isoData = setIsoData(this.context);
18 private subscription: Subscription;
19 private emptyState: CreateCommunityState = {
20 site_view: this.isoData.site_res.site_view,
23 constructor(props: any, context: any) {
24 super(props, context);
25 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
26 this.state = this.emptyState;
28 this.parseMessage = this.parseMessage.bind(this);
29 this.subscription = wsSubscribe(this.parseMessage);
31 if (!UserService.Instance.myUserInfo && isBrowser()) {
32 toast(i18n.t("not_logged_in"), "danger");
33 this.context.router.history.push(`/login`);
37 componentWillUnmount() {
39 this.subscription.unsubscribe();
43 get documentTitle(): string {
44 return `${i18n.t("create_community")} - ${this.state.site_view.site.name}`;
49 <div class="container">
51 title={this.documentTitle}
52 path={this.context.router.route.match.url}
54 {this.state.loading ? (
60 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
61 <h5>{i18n.t("create_community")}</h5>
63 onCreate={this.handleCommunityCreate}
64 enableNsfw={this.state.site_view.site.enable_nsfw}
73 handleCommunityCreate(cv: CommunityView) {
74 this.props.history.push(`/c/${cv.community.name}`);
77 parseMessage(msg: any) {
79 // Toast errors are already handled by community-form