]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/community/community.tsx
component classes v2
[lemmy-ui.git] / src / shared / components / community / community.tsx
index e8412e76842f9481a8b07654642b799f11ac716d..b833ca9a3cfb7a5ca5dadcf7381424b31a6b2a07 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,
     };
   }
 
@@ -349,7 +328,7 @@ export class Community extends Component<
                 {this.communityInfo(res)}
                 <div className="d-block d-md-none">
                   <button
-                    className="btn btn-secondary d-inline-block mb-2 mr-3"
+                    className="btn btn-secondary d-inline-block mb-2 me-3"
                     onClick={linkEvent(this, this.handleShowSidebarMobile)}
                   >
                     {i18n.t("sidebar")}{" "}
@@ -379,7 +358,9 @@ export class Community extends Component<
   }
 
   render() {
-    return <div className="container-lg">{this.renderCommunity()}</div>;
+    return (
+      <div className="community container-lg">{this.renderCommunity()}</div>
+    );
   }
 
   sidebar(res: GetCommunityResponse) {
@@ -396,7 +377,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}
@@ -533,13 +513,13 @@ export class Community extends Component<
 
     return (
       <div className="mb-3">
-        <span className="mr-3">
+        <span className="me-3">
           <DataTypeSelect
             type_={dataType}
             onChange={this.handleDataTypeChange}
           />
         </span>
-        <span className="mr-2">
+        <span className="me-2">
           <SortSelect sort={sort} onChange={this.handleSortChange} />
         </span>
         {communityRss && (
@@ -683,6 +663,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;
+        }
+      });
     }
   }