onCancel?(): any;
onUpsertCommunity(form: CreateCommunity | EditCommunity): void;
enableNsfw?: boolean;
+ loading?: boolean;
}
interface CommunityFormState {
posting_restricted_to_mods?: boolean;
discussion_languages?: number[];
};
- loading: boolean;
submitted: boolean;
}
state: CommunityFormState = {
form: {},
- loading: false,
submitted: false,
};
posting_restricted_to_mods: cv.community.posting_restricted_to_mods,
discussion_languages: this.props.communityLanguages,
},
- loading: false,
};
}
}
<form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
<NavigationPrompt
when={
- !this.state.loading &&
+ !this.props.loading &&
!!(
this.state.form.name ||
this.state.form.title ||
<button
type="submit"
className="btn btn-secondary mr-2"
- disabled={this.state.loading}
+ disabled={this.props.loading}
>
- {this.state.loading ? (
+ {this.props.loading ? (
<Spinner />
) : this.props.community_view ? (
capitalizeFirstLetter(i18n.t("save"))
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();
interface CreateCommunityState {
siteRes: GetSiteResponse;
+ loading: boolean;
}
export class CreateCommunity extends Component<any, CreateCommunityState> {
private isoData = setIsoData(this.context);
state: CreateCommunityState = {
siteRes: this.isoData.site_res,
+ loading: false,
};
constructor(props: any, context: any) {
super(props, context);
allLanguages={this.state.siteRes.all_languages}
siteLanguages={this.state.siteRes.discussion_languages}
communityLanguages={this.state.siteRes.discussion_languages}
+ loading={this.state.loading}
/>
</div>
</div>
}
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 });
}
}
}