this repo has no description
1import {useCallback} from 'react'
2import {msg} from '@lingui/core/macro'
3import {useLingui} from '@lingui/react'
4
5import {logger} from '#/logger'
6import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members'
7import * as Dialog from '#/components/Dialog'
8import {SearchablePeopleList} from '#/components/dialogs/SearchablePeopleList'
9import * as Toast from '#/components/Toast'
10import {useAnalytics} from '#/analytics'
11
12export function SendViaChatDialog({
13 control,
14 onSelectChat,
15}: {
16 control: Dialog.DialogControlProps
17 onSelectChat: (chatId: string) => void
18}) {
19 return (
20 <Dialog.Outer
21 control={control}
22 testID="sendViaChatChatDialog"
23 nativeOptions={{fullHeight: true}}>
24 <Dialog.Handle />
25 <SendViaChatDialogInner control={control} onSelectChat={onSelectChat} />
26 </Dialog.Outer>
27 )
28}
29
30function SendViaChatDialogInner({
31 control,
32 onSelectChat,
33}: {
34 control: Dialog.DialogControlProps
35 onSelectChat: (chatId: string) => void
36}) {
37 const {_} = useLingui()
38 const ax = useAnalytics()
39 const {mutate: createChat} = useGetConvoForMembers({
40 onSuccess: data => {
41 onSelectChat(data.convo.id)
42
43 if (!data.convo.lastMessage) {
44 ax.metric('chat:create', {logContext: 'SendViaChatDialog'})
45 }
46 ax.metric('chat:open', {logContext: 'SendViaChatDialog'})
47 },
48 onError: error => {
49 logger.error('Failed to share post to chat', {message: error})
50 Toast.show(_(msg`An issue occurred while trying to open the chat`), {
51 type: 'error',
52 })
53 },
54 })
55
56 const onCreateChat = useCallback(
57 (did: string) => {
58 control.close(() => createChat([did]))
59 },
60 [control, createChat],
61 )
62
63 return (
64 <SearchablePeopleList
65 title={_(msg`Send post to...`)}
66 onSelectChat={onCreateChat}
67 showRecentConvos
68 sortByMessageDeclaration
69 />
70 )
71}