From e68babe38bb1face0ea8866972eb550d769bc3f7 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 29 Jul 2022 23:38:37 -0400 Subject: [PATCH] Adding block from community sidebar. Fixes #690 (#716) * Adding block from community sidebar. Fixes #690 * Fixing lint --- src/shared/components/community/community.tsx | 13 ++++ src/shared/components/community/sidebar.tsx | 62 +++++++++++++++---- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 72728110..c5afe0ef 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -3,6 +3,7 @@ import { Component, linkEvent } from "inferno"; import { AddModToCommunityResponse, BanFromCommunityResponse, + BlockCommunityResponse, BlockPersonResponse, CommentReportResponse, CommentResponse, @@ -53,6 +54,7 @@ import { setupTippy, showLocal, toast, + updateCommunityBlock, updatePersonBlock, wsClient, wsSubscribe, @@ -663,6 +665,17 @@ export class Community extends Component { toast(i18n.t("purge_success")); this.context.router.history.push(`/`); } + } else if (op == UserOperation.BlockCommunity) { + let data = wsJsonToRes( + msg, + BlockCommunityResponse + ); + this.state.communityRes.match({ + some: res => (res.community_view.blocked = data.blocked), + none: void 0, + }); + updateCommunityBlock(data); + this.setState(this.state); } } } diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 109b629b..775fd636 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -3,6 +3,7 @@ import { Component, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { AddModToCommunity, + BlockCommunity, CommunityModeratorView, CommunityView, DeleteCommunity, @@ -120,23 +121,21 @@ export class Sidebar extends Component { )} {community.title} {subscribed == SubscribedType.Subscribed && ( - {i18n.t("joined")} - + )} {subscribed == SubscribedType.Pending && ( - {i18n.t("subscribe_pending")} - + )} {community.removed && ( @@ -289,16 +288,33 @@ export class Sidebar extends Component { subscribe() { let community_view = this.props.community_view; + let blocked = this.props.community_view.blocked; return (
{community_view.subscribed == SubscribedType.NotSubscribed && ( - - {i18n.t("subscribe")} - + <> + + {blocked ? ( + + ) : ( + + )} + )}
); @@ -641,4 +657,24 @@ export class Sidebar extends Component { i.state.purgeLoading = true; i.setState(i.state); } + + handleBlock(i: Sidebar, event: any) { + event.preventDefault(); + let blockCommunityForm = new BlockCommunity({ + community_id: i.props.community_view.community.id, + block: true, + auth: auth().unwrap(), + }); + WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm)); + } + + handleUnblock(i: Sidebar, event: any) { + event.preventDefault(); + let blockCommunityForm = new BlockCommunity({ + community_id: i.props.community_view.community.id, + block: false, + auth: auth().unwrap(), + }); + WebSocketService.Instance.send(wsClient.blockCommunity(blockCommunityForm)); + } }