Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 103 lines 3.0 kB view raw
1import {useCallback} from 'react' 2import {Trans, useLingui} from '@lingui/react/macro' 3 4import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification' 5import {logger} from '#/logger' 6import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members' 7import {FAB} from '#/view/com/util/fab/FAB' 8import {useTheme} from '#/alf' 9import * as Dialog from '#/components/Dialog' 10import {SearchablePeopleList} from '#/components/dialogs/SearchablePeopleList' 11import {InitiateChatFlow} from '#/components/dms/InitiateChatFlow' 12import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' 13import * as Toast from '#/components/Toast' 14import {useAnalytics} from '#/analytics' 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 {t: l} = useLingui() 25 const ax = useAnalytics() 26 const requireEmailVerification = useRequireEmailVerification() 27 28 const isGroupChatEnabled = ax.features.enabled(ax.features.GroupChatsEnable) 29 30 const {mutate: createChat} = useGetConvoForMembers({ 31 onSuccess: data => { 32 onNewChat(data.convo.id) 33 34 if (!data.convo.lastMessage) { 35 ax.metric('chat:create', {logContext: 'NewChatDialog'}) 36 } 37 ax.metric('chat:open', {logContext: 'NewChatDialog'}) 38 }, 39 onError: error => { 40 logger.error('Failed to create chat', {safeMessage: error}) 41 Toast.show(l`An issue occurred starting the chat`, { 42 type: 'error', 43 }) 44 }, 45 }) 46 47 const onCreateChat = useCallback( 48 (did: string) => { 49 control.close(() => createChat([did])) 50 }, 51 [control, createChat], 52 ) 53 54 const onCreateGroupChat = useCallback( 55 (_dids: string[], _groupName: string) => { 56 control.close() 57 }, 58 [control], 59 ) 60 61 const onPress = useCallback(() => { 62 control.open() 63 }, [control]) 64 const wrappedOnPress = requireEmailVerification(onPress, { 65 instructions: [ 66 <Trans key="new-chat"> 67 Before you can message another user, you must first verify your email. 68 </Trans>, 69 ], 70 }) 71 72 return ( 73 <> 74 <FAB 75 testID="newChatFAB" 76 onPress={wrappedOnPress} 77 icon={<Plus size="lg" fill={t.palette.white} />} 78 accessibilityRole="button" 79 accessibilityLabel={l`New chat`} 80 accessibilityHint="" 81 /> 82 <Dialog.Outer 83 control={control} 84 testID="newChatDialog" 85 nativeOptions={{fullHeight: true}}> 86 <Dialog.Handle /> 87 {isGroupChatEnabled ? ( 88 <InitiateChatFlow 89 title={l`New chat`} 90 onSelectChat={onCreateChat} 91 onSelectGroupChat={onCreateGroupChat} 92 /> 93 ) : ( 94 <SearchablePeopleList 95 title={l`Start a new chat`} 96 onSelectChat={onCreateChat} 97 sortByMessageDeclaration 98 /> 99 )} 100 </Dialog.Outer> 101 </> 102 ) 103}