X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fcommunity%2Fcommunity-form.tsx;h=e44675c91c608256aad56729ef91fb0de0f118cf;hb=9f2289d46600385354d3673b0ef2ba921a1fbe49;hp=372e66a641b947f83bc9b7d0213fba00d6050640;hpb=21a290a9409ccdf4eb4f6c50b8702bca55c2f38d;p=lemmy-ui.git diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index 372e66a..e44675c 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -1,25 +1,14 @@ +import { myAuthRequired } from "@utils/app"; +import { capitalizeFirstLetter, randomStr } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; import { Prompt } from "inferno-router"; import { - CommunityResponse, CommunityView, CreateCommunity, EditCommunity, Language, - UserOperation, - wsJsonToRes, - wsUserOp, } from "lemmy-js-client"; -import { Subscription } from "rxjs"; -import { i18n } from "../../i18next"; -import { UserService, WebSocketService } from "../../services"; -import { - capitalizeFirstLetter, - myAuth, - randomStr, - wsClient, - wsSubscribe, -} from "../../utils"; +import { I18NextService } from "../../services"; import { Icon, Spinner } from "../common/icon"; import { ImageUploadForm } from "../common/image-upload-form"; import { LanguageSelect } from "../common/language-select"; @@ -31,9 +20,9 @@ interface CommunityFormProps { siteLanguages: number[]; communityLanguages?: number[]; onCancel?(): any; - onCreate?(community: CommunityView): any; - onEdit?(community: CommunityView): any; + onUpsertCommunity(form: CreateCommunity | EditCommunity): void; enableNsfw?: boolean; + loading?: boolean; } interface CommunityFormState { @@ -47,7 +36,7 @@ interface CommunityFormState { posting_restricted_to_mods?: boolean; discussion_languages?: number[]; }; - loading: boolean; + submitted: boolean; } export class CommunityForm extends Component< @@ -55,11 +44,10 @@ export class CommunityForm extends Component< CommunityFormState > { private id = `community-form-${randomStr()}`; - private subscription?: Subscription; state: CommunityFormState = { form: {}, - loading: false, + submitted: false, }; constructor(props: any, context: any) { @@ -77,12 +65,11 @@ export class CommunityForm extends Component< this.handleDiscussionLanguageChange = this.handleDiscussionLanguageChange.bind(this); - this.parseMessage = this.parseMessage.bind(this); - this.subscription = wsSubscribe(this.parseMessage); const cv = this.props.community_view; if (cv) { this.state = { + ...this.state, form: { name: cv.community.name, title: cv.community.title, @@ -93,80 +80,38 @@ export class CommunityForm extends Component< posting_restricted_to_mods: cv.community.posting_restricted_to_mods, discussion_languages: this.props.communityLanguages, }, - loading: false, }; } } - componentDidUpdate() { - if ( - !this.state.loading && - (this.state.form.name || - this.state.form.title || - this.state.form.description) - ) { - window.onbeforeunload = () => true; - } else { - window.onbeforeunload = null; - } - } - - componentWillUnmount() { - this.subscription?.unsubscribe(); - window.onbeforeunload = null; - } - render() { return ( - <> +