From 6b30671875eec559b631dab44b96723b7d9dbe9f Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Wed, 15 Mar 2023 14:53:17 -0400 Subject: [PATCH] Add Account entity and improve Block/Ban support for Groups --- app/soapbox/components/account.tsx | 5 +- .../dropdown-menu/dropdown-menu-item.tsx | 2 +- .../group/components/group-action-button.tsx | 5 + .../components/group-member-list-item.tsx | 78 ++++------- app/soapbox/features/group/group-members.tsx | 2 +- .../features/ui/components/action-button.tsx | 3 +- .../hooks/api/groups/useBlockGroupMember.ts | 15 +++ app/soapbox/hooks/useGroups.ts | 2 +- app/soapbox/locales/en.json | 6 +- app/soapbox/pages/group-page.tsx | 52 ++++++-- app/soapbox/schemas/account.ts | 124 ++++++++++++++++++ app/soapbox/schemas/group-member.ts | 4 +- app/soapbox/schemas/group-relationship.ts | 2 + app/soapbox/schemas/index.ts | 4 + app/soapbox/schemas/relationship.ts | 22 ++++ app/soapbox/utils/accounts.ts | 15 ++- app/soapbox/utils/features.ts | 5 + 17 files changed, 267 insertions(+), 79 deletions(-) create mode 100644 app/soapbox/hooks/api/groups/useBlockGroupMember.ts create mode 100644 app/soapbox/schemas/account.ts create mode 100644 app/soapbox/schemas/relationship.ts diff --git a/app/soapbox/components/account.tsx b/app/soapbox/components/account.tsx index 0a435f48f..f79366895 100644 --- a/app/soapbox/components/account.tsx +++ b/app/soapbox/components/account.tsx @@ -14,10 +14,11 @@ import RelativeTimestamp from './relative-timestamp'; import { Avatar, Emoji, HStack, Icon, IconButton, Stack, Text } from './ui'; import type { StatusApprovalStatus } from 'soapbox/normalizers/status'; +import type { Account as AccountSchema } from 'soapbox/schemas'; import type { Account as AccountEntity } from 'soapbox/types/entities'; interface IInstanceFavicon { - account: AccountEntity + account: AccountEntity | AccountSchema disabled?: boolean } @@ -67,7 +68,7 @@ const ProfilePopper: React.FC = ({ condition, wrapper, children }; export interface IAccount { - account: AccountEntity + account: AccountEntity | AccountSchema action?: React.ReactElement actionAlignment?: 'center' | 'top' actionIcon?: string diff --git a/app/soapbox/components/dropdown-menu/dropdown-menu-item.tsx b/app/soapbox/components/dropdown-menu/dropdown-menu-item.tsx index 3de906dc8..f34240d8a 100644 --- a/app/soapbox/components/dropdown-menu/dropdown-menu-item.tsx +++ b/app/soapbox/components/dropdown-menu/dropdown-menu-item.tsx @@ -73,7 +73,7 @@ const DropdownMenuItem = ({ index, item, onClick }: IDropdownMenuItem) => { } return ( -
  • +
  • { const isRequested = group.relationship?.requested; const isNonMember = !group.relationship?.member && !isRequested; const isAdmin = group.relationship?.role === 'admin'; + const isBlocked = group.relationship?.blocked_by; const onJoinGroup = () => joinGroup.mutate(group); @@ -41,6 +42,10 @@ const GroupActionButton = ({ group }: IGroupActionButton) => { const onCancelRequest = () => cancelRequest.mutate(group); + if (isBlocked) { + return null; + } + if (isNonMember) { return (