]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/community/community.tsx
Merge branch 'main' into route-data-refactor
[lemmy-ui.git] / src / shared / components / community / community.tsx
index e8412e76842f9481a8b07654642b799f11ac716d..6f3c9112f782231e9af853b199414b2174541a10 100644 (file)
@@ -102,9 +102,9 @@ import { PostListings } from "../post/post-listings";
 import { CommunityLink } from "./community-link";
 
 type CommunityData = RouteDataResponse<{
-  communityResponse: GetCommunityResponse;
-  postsResponse?: GetPostsResponse;
-  commentsResponse?: GetCommentsResponse;
+  communityRes: GetCommunityResponse;
+  postsRes: GetPostsResponse;
+  commentsRes: GetCommentsResponse;
 }>;
 
 interface State {
@@ -201,37 +201,15 @@ export class Community extends Component<
 
     // Only fetch the data if coming from another route
     if (FirstLoadService.isFirstLoad) {
-      const {
-        communityResponse: communityRes,
-        commentsResponse: commentsRes,
-        postsResponse: postsRes,
-      } = this.isoData.routeData;
+      const { communityRes, commentsRes, postsRes } = this.isoData.routeData;
 
       this.state = {
         ...this.state,
         isIsomorphic: true,
+        commentsRes,
+        communityRes,
+        postsRes,
       };
-
-      if (communityRes.state === "success") {
-        this.state = {
-          ...this.state,
-          communityRes,
-        };
-      }
-
-      if (postsRes?.state === "success") {
-        this.state = {
-          ...this.state,
-          postsRes,
-        };
-      }
-
-      if (commentsRes?.state === "success") {
-        this.state = {
-          ...this.state,
-          commentsRes,
-        };
-      }
     }
   }
 
@@ -279,9 +257,10 @@ export class Community extends Component<
 
     const page = getPageFromString(urlPage);
 
-    let postsResponse: RequestState<GetPostsResponse> | undefined = undefined;
-    let commentsResponse: RequestState<GetCommentsResponse> | undefined =
-      undefined;
+    let postsResponse: RequestState<GetPostsResponse> = { state: "empty" };
+    let commentsResponse: RequestState<GetCommentsResponse> = {
+      state: "empty",
+    };
 
     if (dataType === DataType.Post) {
       const getPostsForm: GetPosts = {
@@ -310,9 +289,9 @@ export class Community extends Component<
     }
 
     return {
-      communityResponse: await client.getCommunity(communityForm),
-      commentsResponse,
-      postsResponse,
+      communityRes: await client.getCommunity(communityForm),
+      commentsRes: commentsResponse,
+      postsRes: postsResponse,
     };
   }
 
@@ -396,7 +375,6 @@ export class Community extends Component<
           community_view={res.community_view}
           moderators={res.moderators}
           admins={site_res.admins}
-          online={res.online}
           enableNsfw={enableNsfw(site_res)}
           editable
           allLanguages={site_res.all_languages}
@@ -683,6 +661,12 @@ export class Community extends Component<
     const blockCommunityRes = await HttpService.client.blockCommunity(form);
     if (blockCommunityRes.state == "success") {
       updateCommunityBlock(blockCommunityRes.data);
+      this.setState(s => {
+        if (s.communityRes.state == "success") {
+          s.communityRes.data.community_view.blocked =
+            blockCommunityRes.data.blocked;
+        }
+      });
     }
   }