From afcffce572b83275c00e9831b659d9c9b1b4c9c2 Mon Sep 17 00:00:00 2001 From: Jordan Enterkin Date: Fri, 16 Jun 2023 11:01:09 -0600 Subject: [PATCH 1/2] fix block community functionality in sidebar (#1316) Co-authored-by: Dessalines --- src/shared/components/community/community.tsx | 6 +++ src/shared/components/community/sidebar.tsx | 45 ++++++------------- src/shared/components/post/post.tsx | 17 +++---- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 7dc150f3..05fa55e1 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 63378a18..57400f48 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 9c68532b..51365803 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; + } + }); } } From 6e3ebbd085f0ec334984c4a16d2bbcb45c96f37e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 16 Jun 2023 14:31:21 -0400 Subject: [PATCH 2/2] Adding codeowners. --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6df17d57..76916e60 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @dessalines @SleeplessOne1917 +* @dessalines @SleeplessOne1917 @alectrocute