2023-06-21 22:28:24 +00:00
|
|
|
import { enableNsfw, setIsoData } from "@utils/app";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
2022-06-21 21:42:29 +00:00
|
|
|
import {
|
2023-06-14 12:20:40 +00:00
|
|
|
CreateCommunity as CreateCommunityI,
|
|
|
|
GetSiteResponse,
|
|
|
|
} from "lemmy-js-client";
|
2023-06-23 19:41:10 +00:00
|
|
|
import { HttpService, I18NextService } from "../../services";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { HtmlTags } from "../common/html-tags";
|
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;
|
2023-06-14 13:32:25 +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
|
|
|
state: CreateCommunityState = {
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2023-06-14 13:32:25 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2023-06-22 00:54:35 +00:00
|
|
|
return `${I18NextService.i18n.t("create_community")} - ${
|
2022-11-09 19:53:07 +00:00
|
|
|
this.state.siteRes.site_view.site.name
|
|
|
|
}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2023-06-20 18:46:16 +00:00
|
|
|
<div className="create-community container-lg">
|
2020-09-11 18:09:21 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2023-06-14 12:20:40 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3 mb-4">
|
2023-06-22 00:54:35 +00:00
|
|
|
<h5>{I18NextService.i18n.t("create_community")}</h5>
|
2023-06-14 12:20:40 +00:00
|
|
|
<CommunityForm
|
|
|
|
onUpsertCommunity={this.handleCommunityCreate}
|
|
|
|
enableNsfw={enableNsfw(this.state.siteRes)}
|
|
|
|
allLanguages={this.state.siteRes.all_languages}
|
|
|
|
siteLanguages={this.state.siteRes.discussion_languages}
|
|
|
|
communityLanguages={this.state.siteRes.discussion_languages}
|
2023-06-14 13:39:19 +00:00
|
|
|
loading={this.state.loading}
|
2023-06-14 12:20:40 +00:00
|
|
|
/>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
2023-06-14 12:20:40 +00:00
|
|
|
</div>
|
2020-09-06 16:15:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
async handleCommunityCreate(form: CreateCommunityI) {
|
2023-06-14 13:32:25 +00:00
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
const res = await HttpService.client.createCommunity(form);
|
2023-06-14 13:32:25 +00:00
|
|
|
|
2023-06-14 12:20:40 +00:00
|
|
|
if (res.state === "success") {
|
|
|
|
const name = res.data.community_view.community.name;
|
|
|
|
this.props.history.replace(`/c/${name}`);
|
2023-06-14 13:32:25 +00:00
|
|
|
} else {
|
|
|
|
this.setState({ loading: false });
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|