]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/post/create-post.tsx
Merge branch 'main' into route-data-refactor
[lemmy-ui.git] / src / shared / components / post / create-post.tsx
index f43cbb0739761e25a7043f9df0e4c19307364e1f..684dda2fc3b1a194a8bf67c1e9abc7c62be4dea3 100644 (file)
@@ -21,7 +21,6 @@ import {
   enableNsfw,
   getIdFromString,
   getQueryParams,
-  getQueryString,
   isBrowser,
   myAuth,
   setIsoData,
@@ -80,7 +79,7 @@ export class CreatePost extends Component<
 
       if (communityResponse) {
         const communityChoice: Choice = {
-          label: communityResponse.community_view.community.name,
+          label: communityResponse.community_view.community.title,
           value: communityResponse.community_view.community.id.toString(),
         };
 
@@ -179,18 +178,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();
   }
@@ -237,12 +239,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,
       });
     }