Bluesky app fork with some witchin' additions 馃挮
at main 81 lines 2.4 kB view raw
1import {useCallback} from 'react' 2import {msg, Trans} from '@lingui/macro' 3import {useLingui} from '@lingui/react' 4 5import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification' 6import {logEvent} from '#/lib/statsig/statsig' 7import {logger} from '#/logger' 8import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members' 9import {FAB} from '#/view/com/util/fab/FAB' 10import * as Toast from '#/view/com/util/Toast' 11import {useTheme} from '#/alf' 12import * as Dialog from '#/components/Dialog' 13import {SearchablePeopleList} from '#/components/dialogs/SearchablePeopleList' 14import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' 15 16export function NewChat({ 17 control, 18 onNewChat, 19}: { 20 control: Dialog.DialogControlProps 21 onNewChat: (chatId: string) => void 22}) { 23 const t = useTheme() 24 const {_} = useLingui() 25 const requireEmailVerification = useRequireEmailVerification() 26 27 const {mutate: createChat} = useGetConvoForMembers({ 28 onSuccess: data => { 29 onNewChat(data.convo.id) 30 31 if (!data.convo.lastMessage) { 32 logEvent('chat:create', {logContext: 'NewChatDialog'}) 33 } 34 logEvent('chat:open', {logContext: 'NewChatDialog'}) 35 }, 36 onError: error => { 37 logger.error('Failed to create chat', {safeMessage: error}) 38 Toast.show(_(msg`An issue occurred starting the chat`), 'xmark') 39 }, 40 }) 41 42 const onCreateChat = useCallback( 43 (did: string) => { 44 control.close(() => createChat([did])) 45 }, 46 [control, createChat], 47 ) 48 49 const onPress = useCallback(() => { 50 control.open() 51 }, [control]) 52 const wrappedOnPress = requireEmailVerification(onPress, { 53 instructions: [ 54 <Trans key="new-chat"> 55 Before you can message another user, you must first verify your email. 56 </Trans>, 57 ], 58 }) 59 60 return ( 61 <> 62 <FAB 63 testID="newChatFAB" 64 onPress={wrappedOnPress} 65 icon={<Plus size="lg" fill={t.palette.white} />} 66 accessibilityRole="button" 67 accessibilityLabel={_(msg`New chat`)} 68 accessibilityHint="" 69 /> 70 71 <Dialog.Outer control={control} testID="newChatDialog"> 72 <Dialog.Handle /> 73 <SearchablePeopleList 74 title={_(msg`Start a new chat`)} 75 onSelectChat={onCreateChat} 76 sortByMessageDeclaration 77 /> 78 </Dialog.Outer> 79 </> 80 ) 81}