]> 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 bb39cdadbdab3dae9a162c0325997b43f25a34e0..046bc2de5e2c4dd0eeaccf15ae2388ffbde6c55c 100644 (file)
@@ -35,7 +35,7 @@ export interface CreatePostProps {
 }
 
 type CreatePostData = RouteDataResponse<{
-  communityResponse?: GetCommunityResponse;
+  communityResponse: GetCommunityResponse;
   initialCommunitiesRes: ListCommunitiesResponse;
 }>;
 
@@ -81,6 +81,13 @@ export class CreatePost extends Component<
       const { communityResponse: communityRes, initialCommunitiesRes } =
         this.isoData.routeData;
 
+      this.state = {
+        ...this.state,
+        loading: false,
+        initialCommunitiesRes,
+        isIsomorphic: true,
+      };
+
       if (communityRes?.state === "success") {
         const communityChoice: Choice = {
           label: communityRes.data.community_view.community.title,
@@ -92,13 +99,6 @@ export class CreatePost extends Component<
           selectedCommunityChoice: communityChoice,
         };
       }
-
-      this.state = {
-        ...this.state,
-        loading: false,
-        initialCommunitiesRes,
-        isIsomorphic: true,
-      };
     }
   }
 
@@ -232,6 +232,10 @@ export class CreatePost extends Component<
     if (res.state === "success") {
       const postId = res.data.post_view.post.id;
       this.props.history.replace(`/post/${postId}`);
+    } else {
+      this.setState({
+        loading: false,
+      });
     }
   }
 
@@ -244,6 +248,7 @@ export class CreatePost extends Component<
   >): Promise<CreatePostData> {
     const data: CreatePostData = {
       initialCommunitiesRes: await fetchCommunitiesForOptions(client),
+      communityResponse: { state: "empty" },
     };
 
     if (communityId) {