From da5a740fd44a116fa5a6696d41408321c6def7dc Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Tue, 14 May 2024 22:35:54 -0400 Subject: [PATCH] Fix Language not allowed infinite loading on failed post (#2457) * Fix language not allowed bug * Add translations --- lemmy-translations | 2 +- src/shared/components/post/create-post.tsx | 7 +++++-- src/shared/components/post/post-form.tsx | 9 ++++----- src/shared/components/post/post-listing.tsx | 16 +++++++++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index f0ab81de..ba69ae03 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit f0ab81deea347c433277a90ae752b10f68473719 +Subproject commit ba69ae03d856a9947c54a872dd6e7fb0ed92ea84 diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index 4dcaa6e2..26dda7c4 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -32,6 +32,7 @@ import { PostForm } from "./post-form"; import { getHttpBaseInternal } from "../../utils/env"; import { IRoutePropsWithFetch } from "../../routes"; import { simpleScrollMixin } from "../mixins/scroll-mixin"; +import { toast } from "../../toast"; export interface CreatePostProps { communityId?: number; @@ -164,7 +165,7 @@ export class CreatePost extends Component< } render() { - const { selectedCommunityChoice, siteRes } = this.state; + const { selectedCommunityChoice, siteRes, loading } = this.state; const locationState = this.props.history.location.state as | PostFormParams @@ -204,6 +205,7 @@ export class CreatePost extends Component< ? this.state.initialCommunitiesRes.data.communities : [] } + loading={loading} /> @@ -245,10 +247,11 @@ export class CreatePost extends Component< if (res.state === "success") { const postId = res.data.post_view.post.id; this.props.history.replace(`/post/${postId}`); - } else { + } else if (res.state === "failed") { this.setState({ loading: false, }); + toast(I18NextService.i18n.t(res.err.message), "danger"); } } diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 60c07116..771ff3b8 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -62,6 +62,7 @@ interface PostFormProps { selectedCommunityChoice?: Choice; onSelectCommunity?: (choice: Choice) => void; initialCommunities?: CommunityView[]; + loading: boolean; } interface PostFormState { @@ -76,7 +77,6 @@ interface PostFormState { custom_thumbnail?: string; alt_text?: string; }; - loading: boolean; suggestedPostsRes: RequestState; metadataRes: RequestState; imageLoading: boolean; @@ -93,7 +93,7 @@ function handlePostSubmit(i: PostForm, event: any) { if ((i.state.form.url ?? "") === "") { i.setState(s => ((s.form.url = undefined), s)); } - i.setState({ loading: true, submitted: true }); + i.setState({ submitted: true }); const pForm = i.state.form; const pv = i.props.post_view; @@ -240,7 +240,6 @@ export class PostForm extends Component { suggestedPostsRes: EMPTY_REQUEST, metadataRes: EMPTY_REQUEST, form: {}, - loading: false, imageLoading: false, imageDeleteUrl: "", communitySearchLoading: false, @@ -597,11 +596,11 @@ export class PostForm extends Component {
@@ -812,9 +816,15 @@ export class PostListing extends Component { } // The actual editing is done in the receive for post - handleEditPost(form: EditPost) { - this.setState({ showEdit: false }); - return this.props.onPostEdit(form); + async handleEditPost(form: EditPost) { + this.setState({ showEdit: false, loading: true }); + const res = await this.props.onPostEdit(form); + + if (res.state === "success") { + toast(I18NextService.i18n.t("edited_post")); + } else if (res.state === "failed") { + toast(I18NextService.i18n.t(res.err.message), "danger"); + } } handleShare(i: PostListing) {