2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
2023-05-03 16:09:47 +00:00
|
|
|
import { Redirect } from "inferno-router";
|
2022-06-21 21:42:29 +00:00
|
|
|
import { CommunityView, GetSiteResponse } from "lemmy-js-client";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Subscription } from "rxjs";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { i18n } from "../../i18next";
|
2023-05-03 16:09:47 +00:00
|
|
|
import { UserService } from "../../services/UserService";
|
2022-06-21 21:42:29 +00:00
|
|
|
import {
|
|
|
|
enableNsfw,
|
|
|
|
isBrowser,
|
|
|
|
setIsoData,
|
|
|
|
toast,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Spinner } from "../common/icon";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { CommunityForm } from "./community-form";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface CreateCommunityState {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2020-09-07 22:24:48 +00:00
|
|
|
loading: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class CreateCommunity extends Component<any, CreateCommunityState> {
|
2020-09-07 22:24:48 +00:00
|
|
|
private isoData = setIsoData(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
private subscription?: Subscription;
|
|
|
|
state: CreateCommunityState = {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-03-04 03:42:11 +00:00
|
|
|
loading: false,
|
2020-09-06 16:15:25 +00:00
|
|
|
};
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleCommunityCreate = this.handleCommunityCreate.bind(this);
|
|
|
|
|
2020-09-07 22:24:48 +00:00
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-09-07 22:24:48 +00:00
|
|
|
if (isBrowser()) {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.subscription?.unsubscribe();
|
2020-09-07 22:24:48 +00:00
|
|
|
}
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
return `${i18n.t("create_community")} - ${
|
|
|
|
this.state.siteRes.site_view.site.name
|
|
|
|
}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2023-05-03 16:09:47 +00:00
|
|
|
{!UserService.Instance.myUserInfo && <Redirect to="/login" />}
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2020-09-07 22:24:48 +00:00
|
|
|
{this.state.loading ? (
|
|
|
|
<h5>
|
2021-07-17 20:21:31 +00:00
|
|
|
<Spinner large />
|
2020-09-07 22:24:48 +00:00
|
|
|
</h5>
|
|
|
|
) : (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3 mb-4">
|
2021-02-22 02:39:04 +00:00
|
|
|
<h5>{i18n.t("create_community")}</h5>
|
2020-09-07 22:24:48 +00:00
|
|
|
<CommunityForm
|
|
|
|
onCreate={this.handleCommunityCreate}
|
2022-06-21 21:42:29 +00:00
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
2022-12-19 15:57:29 +00:00
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
2023-01-04 16:56:24 +00:00
|
|
|
communityLanguages={this.state.siteRes.discussion_languages}
|
2020-09-07 22:24:48 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
2020-09-07 22:24:48 +00:00
|
|
|
)}
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
handleCommunityCreate(cv: CommunityView) {
|
|
|
|
this.props.history.push(`/c/${cv.community.name}`);
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 01:58:27 +00:00
|
|
|
parseMessage(msg: any) {
|
2020-09-06 16:15:25 +00:00
|
|
|
if (msg.error) {
|
2022-05-23 19:22:15 +00:00
|
|
|
toast(i18n.t(msg.error), "danger");
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|