From 91496e544c2521a0e409de2709506271d7f91927 Mon Sep 17 00:00:00 2001 From: James Acklin Date: Mon, 7 Oct 2024 19:19:13 -0400 Subject: [PATCH] GroupMembersScreen, ProfileSheet: wire up navigate to DM --- .../features/groups/GroupMembersScreen.tsx | 31 ++++++++++++++++--- .../src/components/GroupMembersScreenView.tsx | 3 ++ packages/ui/src/components/ProfileBlock.tsx | 7 +---- packages/ui/src/components/ProfileSheet.tsx | 20 +++++------- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/packages/app/features/groups/GroupMembersScreen.tsx b/packages/app/features/groups/GroupMembersScreen.tsx index cda6db9464..e63aecab14 100644 --- a/packages/app/features/groups/GroupMembersScreen.tsx +++ b/packages/app/features/groups/GroupMembersScreen.tsx @@ -1,18 +1,20 @@ +import { CommonActions } from '@react-navigation/native'; +import { NativeStackScreenProps } from '@react-navigation/native-stack'; +import * as store from '@tloncorp/shared/dist/store'; import { GroupMembersScreenView } from '@tloncorp/ui'; +import { useCallback } from 'react'; import { useCurrentUserId } from '../../hooks/useCurrentUser'; import { useGroupContext } from '../../hooks/useGroupContext'; -import { NativeStackScreenProps } from '@react-navigation/native-stack'; import { GroupSettingsStackParamList } from '../../navigation/types'; - type Props = NativeStackScreenProps< GroupSettingsStackParamList, 'GroupMembers' >; -export function GroupMembersScreen(props: Props) { - const { groupId } = props.route.params; +export function GroupMembersScreen({ route, navigation }: Props) { + const { groupId } = route.params; const { groupMembers, groupRoles, @@ -30,9 +32,28 @@ export function GroupMembersScreen(props: Props) { const currentUserId = useCurrentUserId(); + const handleGoToDm = useCallback( + async (participants: string[]) => { + const dmChannel = await store.upsertDmChannel({ + participants, + }); + navigation.dispatch( + CommonActions.reset({ + index: 1, + routes: [ + { name: 'ChatList' }, + { name: 'Channel', params: { channel: dmChannel } }, + ], + }) + ); + }, + [navigation] + ); + return ( navigation.goBack()} + onPressGoToDm={(contactId: string) => handleGoToDm([contactId])} members={groupMembers} roles={groupRoles} currentUserId={currentUserId} diff --git a/packages/ui/src/components/GroupMembersScreenView.tsx b/packages/ui/src/components/GroupMembersScreenView.tsx index 33986a7382..bbee14dc92 100644 --- a/packages/ui/src/components/GroupMembersScreenView.tsx +++ b/packages/ui/src/components/GroupMembersScreenView.tsx @@ -24,6 +24,7 @@ export function GroupMembersScreenView({ onPressUnban, onPressAcceptJoinRequest, onPressRejectJoinRequest, + onPressGoToDm, }: { goBack: () => void; members: db.ChatMember[]; @@ -37,6 +38,7 @@ export function GroupMembersScreenView({ onPressUnban: (contactId: string) => void; onPressAcceptJoinRequest: (contactId: string) => void; onPressRejectJoinRequest: (contactId: string) => void; + onPressGoToDm: (contactId: string) => void; }) { const { bottom } = useSafeAreaInsets(); const [selectedContact, setSelectedContact] = useState(null); @@ -207,6 +209,7 @@ export function GroupMembersScreenView({ onPressKick={() => onPressKick(selectedContact)} onPressBan={() => onPressBan(selectedContact)} onPressUnban={() => onPressUnban(selectedContact)} + onPressGoToDm={() => onPressGoToDm(selectedContact)} /> )} {selectedContact !== null && selectedIsRequest && ( diff --git a/packages/ui/src/components/ProfileBlock.tsx b/packages/ui/src/components/ProfileBlock.tsx index 087787a026..3ea37082fc 100644 --- a/packages/ui/src/components/ProfileBlock.tsx +++ b/packages/ui/src/components/ProfileBlock.tsx @@ -14,12 +14,7 @@ export const ProfileBlock = ({ >) => { const contact = useContact(contactId); return contact?.coverImage ? ( - + void; onPressBan?: () => void; onPressUnban?: () => void; + onPressGoToDm?: () => void; }) { const currentUserId = useCurrentUserId(); - const { onPressGoToDm } = useNavigation(); - const handleBlock = useCallback(() => { if (contact && contact.isBlocked) { store.unblockUser(contactId); @@ -63,11 +61,6 @@ export function ProfileSheet({ onOpenChange(false); }, [contact, contactId, onOpenChange]); - const handleGoToDm = useCallback(async () => { - onPressGoToDm?.([contactId]); - onOpenChange(false); - }, [contactId, onPressGoToDm, onOpenChange]); - const isAdminnable = currentUserIsAdmin && currentUserId !== contactId; const actions: ActionGroup[] = createActionGroups( @@ -75,7 +68,10 @@ export function ProfileSheet({ 'neutral', { title: 'Send message', - action: () => handleGoToDm, + action: () => { + onPressGoToDm?.(); + onOpenChange(false); + }, endIcon: 'ChevronRight', }, { @@ -119,8 +115,8 @@ export function ProfileSheet({