From: Jordan Enterkin Date: Fri, 16 Jun 2023 17:01:09 +0000 (-0600) Subject: fix block community functionality in sidebar (#1316) X-Git-Url: http://these/git/%24%7BgetStaticDir%28%29%7D/js/static/%24%7B%60data:application/manifest%20json;base64%2C%24%7Bawait?a=commitdiff_plain;h=afcffce572b83275c00e9831b659d9c9b1b4c9c2;p=lemmy-ui.git fix block community functionality in sidebar (#1316) Co-authored-by: Dessalines --- diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 7dc150f..05fa55e 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -647,6 +647,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; + } + }); } } diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 63378a1..57400f4 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -64,7 +64,6 @@ interface SidebarState { removeCommunityLoading: boolean; leaveModTeamLoading: boolean; followCommunityLoading: boolean; - blockCommunityLoading: boolean; purgeCommunityLoading: boolean; } @@ -78,7 +77,6 @@ export class Sidebar extends Component { removeCommunityLoading: false, leaveModTeamLoading: false, followCommunityLoading: false, - blockCommunityLoading: false, purgeCommunityLoading: false, }; @@ -105,7 +103,6 @@ export class Sidebar extends Component { removeCommunityLoading: false, leaveModTeamLoading: false, followCommunityLoading: false, - blockCommunityLoading: false, purgeCommunityLoading: false, }); } @@ -376,35 +373,18 @@ export class Sidebar extends Component { } blockCommunity() { - const community_view = this.props.community_view; - const blocked = this.props.community_view.blocked; + const { subscribed, blocked } = this.props.community_view; return (
- {community_view.subscribed == "NotSubscribed" && - (blocked ? ( - - ) : ( - - ))} + {subscribed == "NotSubscribed" && ( + + )}
); } @@ -668,10 +648,11 @@ export class Sidebar extends Component { } handleBlockCommunity(i: Sidebar) { - i.setState({ blockCommunityLoading: true }); + const { community, blocked } = i.props.community_view; + i.props.onBlockCommunity({ - community_id: 0, - block: !i.props.community_view.blocked, + community_id: community.id, + block: !blocked, auth: myAuthRequired(), }); } diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 9c68532..5136580 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -729,19 +729,14 @@ export class Post extends Component { async handleBlockCommunity(form: BlockCommunity) { const blockCommunityRes = await HttpService.client.blockCommunity(form); - // TODO Probably isn't necessary - this.setState(s => { - if ( - s.postRes.state == "success" && - blockCommunityRes.state == "success" - ) { - s.postRes.data.community_view = blockCommunityRes.data.community_view; - } - return s; - }); - if (blockCommunityRes.state == "success") { updateCommunityBlock(blockCommunityRes.data); + this.setState(s => { + if (s.postRes.state == "success") { + s.postRes.data.community_view.blocked = + blockCommunityRes.data.blocked; + } + }); } }