mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 15:39:25 +00:00
Fix Language not allowed infinite loading on failed post (#2457)
* Fix language not allowed bug * Add translations
This commit is contained in:
parent
b793697f68
commit
da5a740fd4
|
@ -1 +1 @@
|
||||||
Subproject commit f0ab81deea347c433277a90ae752b10f68473719
|
Subproject commit ba69ae03d856a9947c54a872dd6e7fb0ed92ea84
|
|
@ -32,6 +32,7 @@ import { PostForm } from "./post-form";
|
||||||
import { getHttpBaseInternal } from "../../utils/env";
|
import { getHttpBaseInternal } from "../../utils/env";
|
||||||
import { IRoutePropsWithFetch } from "../../routes";
|
import { IRoutePropsWithFetch } from "../../routes";
|
||||||
import { simpleScrollMixin } from "../mixins/scroll-mixin";
|
import { simpleScrollMixin } from "../mixins/scroll-mixin";
|
||||||
|
import { toast } from "../../toast";
|
||||||
|
|
||||||
export interface CreatePostProps {
|
export interface CreatePostProps {
|
||||||
communityId?: number;
|
communityId?: number;
|
||||||
|
@ -164,7 +165,7 @@ export class CreatePost extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedCommunityChoice, siteRes } = this.state;
|
const { selectedCommunityChoice, siteRes, loading } = this.state;
|
||||||
|
|
||||||
const locationState = this.props.history.location.state as
|
const locationState = this.props.history.location.state as
|
||||||
| PostFormParams
|
| PostFormParams
|
||||||
|
@ -204,6 +205,7 @@ export class CreatePost extends Component<
|
||||||
? this.state.initialCommunitiesRes.data.communities
|
? this.state.initialCommunitiesRes.data.communities
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
loading={loading}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -245,10 +247,11 @@ export class CreatePost extends Component<
|
||||||
if (res.state === "success") {
|
if (res.state === "success") {
|
||||||
const postId = res.data.post_view.post.id;
|
const postId = res.data.post_view.post.id;
|
||||||
this.props.history.replace(`/post/${postId}`);
|
this.props.history.replace(`/post/${postId}`);
|
||||||
} else {
|
} else if (res.state === "failed") {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
|
toast(I18NextService.i18n.t(res.err.message), "danger");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ interface PostFormProps {
|
||||||
selectedCommunityChoice?: Choice;
|
selectedCommunityChoice?: Choice;
|
||||||
onSelectCommunity?: (choice: Choice) => void;
|
onSelectCommunity?: (choice: Choice) => void;
|
||||||
initialCommunities?: CommunityView[];
|
initialCommunities?: CommunityView[];
|
||||||
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PostFormState {
|
interface PostFormState {
|
||||||
|
@ -76,7 +77,6 @@ interface PostFormState {
|
||||||
custom_thumbnail?: string;
|
custom_thumbnail?: string;
|
||||||
alt_text?: string;
|
alt_text?: string;
|
||||||
};
|
};
|
||||||
loading: boolean;
|
|
||||||
suggestedPostsRes: RequestState<SearchResponse>;
|
suggestedPostsRes: RequestState<SearchResponse>;
|
||||||
metadataRes: RequestState<GetSiteMetadataResponse>;
|
metadataRes: RequestState<GetSiteMetadataResponse>;
|
||||||
imageLoading: boolean;
|
imageLoading: boolean;
|
||||||
|
@ -93,7 +93,7 @@ function handlePostSubmit(i: PostForm, event: any) {
|
||||||
if ((i.state.form.url ?? "") === "") {
|
if ((i.state.form.url ?? "") === "") {
|
||||||
i.setState(s => ((s.form.url = undefined), s));
|
i.setState(s => ((s.form.url = undefined), s));
|
||||||
}
|
}
|
||||||
i.setState({ loading: true, submitted: true });
|
i.setState({ submitted: true });
|
||||||
|
|
||||||
const pForm = i.state.form;
|
const pForm = i.state.form;
|
||||||
const pv = i.props.post_view;
|
const pv = i.props.post_view;
|
||||||
|
@ -240,7 +240,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
suggestedPostsRes: EMPTY_REQUEST,
|
suggestedPostsRes: EMPTY_REQUEST,
|
||||||
metadataRes: EMPTY_REQUEST,
|
metadataRes: EMPTY_REQUEST,
|
||||||
form: {},
|
form: {},
|
||||||
loading: false,
|
|
||||||
imageLoading: false,
|
imageLoading: false,
|
||||||
imageDeleteUrl: "",
|
imageDeleteUrl: "",
|
||||||
communitySearchLoading: false,
|
communitySearchLoading: false,
|
||||||
|
@ -597,11 +596,11 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
<div className="mb-3 row">
|
<div className="mb-3 row">
|
||||||
<div className="col-sm-10">
|
<div className="col-sm-10">
|
||||||
<button
|
<button
|
||||||
disabled={!this.state.form.community_id || this.state.loading}
|
disabled={!this.state.form.community_id || this.props.loading}
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-secondary me-2"
|
className="btn btn-secondary me-2"
|
||||||
>
|
>
|
||||||
{this.state.loading ? (
|
{this.props.loading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : this.props.post_view ? (
|
) : this.props.post_view ? (
|
||||||
capitalizeFirstLetter(I18NextService.i18n.t("save"))
|
capitalizeFirstLetter(I18NextService.i18n.t("save"))
|
||||||
|
|
|
@ -51,6 +51,7 @@ import { BanUpdateForm } from "../common/mod-action-form-modal";
|
||||||
import PostActionDropdown from "../common/content-actions/post-action-dropdown";
|
import PostActionDropdown from "../common/content-actions/post-action-dropdown";
|
||||||
import { CrossPostParams } from "@utils/types";
|
import { CrossPostParams } from "@utils/types";
|
||||||
import { RequestState } from "../../services/HttpService";
|
import { RequestState } from "../../services/HttpService";
|
||||||
|
import { toast } from "../../toast";
|
||||||
|
|
||||||
type PostListingState = {
|
type PostListingState = {
|
||||||
showEdit: boolean;
|
showEdit: boolean;
|
||||||
|
@ -58,6 +59,7 @@ type PostListingState = {
|
||||||
viewSource: boolean;
|
viewSource: boolean;
|
||||||
showAdvanced: boolean;
|
showAdvanced: boolean;
|
||||||
showBody: boolean;
|
showBody: boolean;
|
||||||
|
loading: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PostListingProps {
|
interface PostListingProps {
|
||||||
|
@ -107,6 +109,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
viewSource: false,
|
viewSource: false,
|
||||||
showAdvanced: false,
|
showAdvanced: false,
|
||||||
showBody: false,
|
showBody: false,
|
||||||
|
loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
|
@ -176,6 +179,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
voteDisplayMode={this.props.voteDisplayMode}
|
voteDisplayMode={this.props.voteDisplayMode}
|
||||||
allLanguages={this.props.allLanguages}
|
allLanguages={this.props.allLanguages}
|
||||||
siteLanguages={this.props.siteLanguages}
|
siteLanguages={this.props.siteLanguages}
|
||||||
|
loading={this.state.loading}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -812,9 +816,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The actual editing is done in the receive for post
|
// The actual editing is done in the receive for post
|
||||||
handleEditPost(form: EditPost) {
|
async handleEditPost(form: EditPost) {
|
||||||
this.setState({ showEdit: false });
|
this.setState({ showEdit: false, loading: true });
|
||||||
return this.props.onPostEdit(form);
|
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) {
|
handleShare(i: PostListing) {
|
||||||
|
|
Loading…
Reference in a new issue