From b076427e8dcd4d93fd56c1bb2cc005055e661216 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Wed, 14 Jun 2023 09:32:25 -0400 Subject: [PATCH 1/2] handle loading state on community-form.tsx --- src/shared/components/community/community-form.tsx | 12 +++++------- src/shared/components/community/create-community.tsx | 8 ++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index f317c983..1d32f6f7 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -21,6 +21,7 @@ interface CommunityFormProps { onCancel?(): any; onUpsertCommunity(form: CreateCommunity | EditCommunity): void; enableNsfw?: boolean; + isLoading?: boolean; } interface CommunityFormState { @@ -34,7 +35,6 @@ interface CommunityFormState { posting_restricted_to_mods?: boolean; discussion_languages?: number[]; }; - loading: boolean; submitted: boolean; } @@ -46,7 +46,6 @@ export class CommunityForm extends Component< state: CommunityFormState = { form: {}, - loading: false, submitted: false, }; @@ -80,7 +79,6 @@ export class CommunityForm extends Component< posting_restricted_to_mods: cv.community.posting_restricted_to_mods, discussion_languages: this.props.communityLanguages, }, - loading: false, }; } } @@ -90,7 +88,7 @@ export class CommunityForm extends Component<
- {this.state.loading ? ( + {this.props.isLoading ? ( ) : this.props.community_view ? ( capitalizeFirstLetter(i18n.t("save")) @@ -270,7 +268,7 @@ export class CommunityForm extends Component< handleCreateCommunitySubmit(i: CommunityForm, event: any) { event.preventDefault(); - i.setState({ loading: true, submitted: true }); + i.setState({ submitted: true }); const cForm = i.state.form; const auth = myAuthRequired(); diff --git a/src/shared/components/community/create-community.tsx b/src/shared/components/community/create-community.tsx index f75c4fbb..ecadd3a1 100644 --- a/src/shared/components/community/create-community.tsx +++ b/src/shared/components/community/create-community.tsx @@ -11,12 +11,14 @@ import { CommunityForm } from "./community-form"; interface CreateCommunityState { siteRes: GetSiteResponse; + loading: boolean; } export class CreateCommunity extends Component { private isoData = setIsoData(this.context); state: CreateCommunityState = { siteRes: this.isoData.site_res, + loading: false, }; constructor(props: any, context: any) { super(props, context); @@ -45,6 +47,7 @@ export class CreateCommunity extends Component { allLanguages={this.state.siteRes.all_languages} siteLanguages={this.state.siteRes.discussion_languages} communityLanguages={this.state.siteRes.discussion_languages} + isLoading={this.state.loading} /> @@ -53,10 +56,15 @@ export class CreateCommunity extends Component { } async handleCommunityCreate(form: CreateCommunityI) { + this.setState({ loading: true }); + const res = await HttpService.client.createCommunity(form); + if (res.state === "success") { const name = res.data.community_view.community.name; this.props.history.replace(`/c/${name}`); + } else { + this.setState({ loading: false }); } } } From cd9de0b2e0964e5279c03d6e2e5383ba6f07d35a Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Wed, 14 Jun 2023 09:39:19 -0400 Subject: [PATCH 2/2] update prop name --- src/shared/components/community/community-form.tsx | 8 ++++---- src/shared/components/community/create-community.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index 1d32f6f7..4eed4645 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -21,7 +21,7 @@ interface CommunityFormProps { onCancel?(): any; onUpsertCommunity(form: CreateCommunity | EditCommunity): void; enableNsfw?: boolean; - isLoading?: boolean; + loading?: boolean; } interface CommunityFormState { @@ -88,7 +88,7 @@ export class CommunityForm extends Component< - {this.props.isLoading ? ( + {this.props.loading ? ( ) : this.props.community_view ? ( capitalizeFirstLetter(i18n.t("save")) diff --git a/src/shared/components/community/create-community.tsx b/src/shared/components/community/create-community.tsx index ecadd3a1..ff31b839 100644 --- a/src/shared/components/community/create-community.tsx +++ b/src/shared/components/community/create-community.tsx @@ -47,7 +47,7 @@ export class CreateCommunity extends Component { allLanguages={this.state.siteRes.all_languages} siteLanguages={this.state.siteRes.discussion_languages} communityLanguages={this.state.siteRes.discussion_languages} - isLoading={this.state.loading} + loading={this.state.loading} />