]> Untitled Git - lemmy-ui.git/commitdiff
Do not refresh when community is selected in create post (#1042)
authorSleeplessOne1917 <abias1122@gmail.com>
Mon, 29 May 2023 13:01:52 +0000 (13:01 +0000)
committerGitHub <noreply@github.com>
Mon, 29 May 2023 13:01:52 +0000 (09:01 -0400)
src/shared/components/post/create-post.tsx
src/shared/components/post/post-form.tsx

index d8a2ccefb312266b41843a7d412abbeee2989aa3..28418d10ff9d7492c02632e5716810a86e8d19da 100644 (file)
@@ -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<CreatePostProps>) {
     const { communityId: urlCommunityId } = getCreatePostQueryParams();
 
-    const queryParams: QueryParams<CreatePostProps> = {
-      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<GetCommunityResponse>(msg);
 
       this.setState({
-        selectedCommunityChoice: { label: name, value: id.toString() },
+        selectedCommunityChoice: { label: title, value: id.toString() },
         loading: false,
       });
     }
index ef168374a7b1e87e3cab9f631334bf55cac8e0fc..18fcee774c4a31c647925493c21aa11abedcf64d 100644 (file)
@@ -644,13 +644,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
 
   handleCommunitySelect(choice: Choice) {
     if (this.props.onSelectCommunity) {
-      this.setState({
-        loading: true,
-      });
-
       this.props.onSelectCommunity(choice);
-
-      this.setState({ loading: false });
     }
   }