1 import { Component } from "inferno";
2 import { Subscription } from "rxjs";
3 import { CommunityForm } from "./community-form";
4 import { HtmlTags } from "./html-tags";
5 import { Spinner } from "./icon";
9 } from "lemmy-js-client";
16 import { UserService } from "../services";
17 import { i18n } from "../i18next";
19 interface CreateCommunityState {
24 export class CreateCommunity extends Component<any, CreateCommunityState> {
25 private isoData = setIsoData(this.context);
26 private subscription: Subscription;
27 private emptyState: CreateCommunityState = {
28 site_view: this.isoData.site_res.site_view,
31 constructor(props: any, context: any) {
32 super(props, context);
33 this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
34 this.state = this.emptyState;
36 this.parseMessage = this.parseMessage.bind(this);
37 this.subscription = wsSubscribe(this.parseMessage);
39 if (!UserService.Instance.user && isBrowser()) {
40 toast(i18n.t("not_logged_in"), "danger");
41 this.context.router.history.push(`/login`);
44 // Only fetch the data if coming from another route
45 if (this.isoData.path == this.context.router.route.match.url) {
46 this.state.loading = false;
50 componentWillUnmount() {
52 this.subscription.unsubscribe();
56 get documentTitle(): string {
57 return `${i18n.t("create_community")} - ${this.state.site_view.site.name}`;
62 <div class="container">
64 title={this.documentTitle}
65 path={this.context.router.route.match.url}
67 {this.state.loading ? (
73 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
74 <h5>{i18n.t("create_community")}</h5>
76 onCreate={this.handleCommunityCreate}
77 enableNsfw={this.state.site_view.site.enable_nsfw}
86 handleCommunityCreate(cv: CommunityView) {
87 this.props.history.push(`/c/${cv.community.name}`);
90 parseMessage(msg: any) {
92 // Toast errors are already handled by community-form