From: SleeplessOne1917 Date: Mon, 29 May 2023 13:01:52 +0000 (+0000) Subject: Do not refresh when community is selected in create post (#1042) X-Git-Url: http://these/git/%22https:/www.exeterceilidhs.net/%22%7B%7D/%7Bthis.captchaPngSrc%28%29%7D?a=commitdiff_plain;h=7720e37a63618868d75143871e36a2a5fa3ac747;p=lemmy-ui.git Do not refresh when community is selected in create post (#1042) --- diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index d8a2cce..28418d1 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -20,7 +20,6 @@ import { enableNsfw, getIdFromString, getQueryParams, - getQueryString, isBrowser, myAuth, setIsoData, @@ -77,7 +76,7 @@ export class CreatePost extends Component< if (communityRes) { const communityChoice: Choice = { - label: communityRes.community_view.community.name, + label: communityRes.community_view.community.title, value: communityRes.community_view.community.id.toString(), }; @@ -176,18 +175,21 @@ export class CreatePost extends Component< updateUrl({ communityId }: Partial) { const { communityId: urlCommunityId } = getCreatePostQueryParams(); - const queryParams: QueryParams = { - communityId: (communityId ?? urlCommunityId)?.toString(), - }; - const locationState = this.props.history.location.state as | PostFormParams | undefined; - this.props.history.replace( - `/create_post${getQueryString(queryParams)}`, - locationState - ); + const url = new URL(location.href); + + const newId = (communityId ?? urlCommunityId)?.toString(); + + if (newId !== undefined) { + url.searchParams.set("communityId", newId); + } else { + url.searchParams.delete("communityId"); + } + + history.replaceState(locationState, "", url); this.fetchCommunity(); } @@ -234,12 +236,12 @@ export class CreatePost extends Component< if (op === UserOperation.GetCommunity) { const { community_view: { - community: { name, id }, + community: { title, id }, }, } = wsJsonToRes(msg); this.setState({ - selectedCommunityChoice: { label: name, value: id.toString() }, + selectedCommunityChoice: { label: title, value: id.toString() }, loading: false, }); } diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index ef16837..18fcee7 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -644,13 +644,7 @@ export class PostForm extends Component { handleCommunitySelect(choice: Choice) { if (this.props.onSelectCommunity) { - this.setState({ - loading: true, - }); - this.props.onSelectCommunity(choice); - - this.setState({ loading: false }); } }