Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
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 Toast from '#/view/com/util/Toast'
8import * as Dialog from '#/components/Dialog'
9import {SearchablePeopleList} from '#/components/dialogs/SearchablePeopleList'
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 control={control} testID="sendViaChatChatDialog">
21 <Dialog.Handle />
22 <SendViaChatDialogInner control={control} onSelectChat={onSelectChat} />
23 </Dialog.Outer>
24 )
25}
26
27function SendViaChatDialogInner({
28 control,
29 onSelectChat,
30}: {
31 control: Dialog.DialogControlProps
32 onSelectChat: (chatId: string) => void
33}) {
34 const {_} = useLingui()
35 const ax = useAnalytics()
36 const {mutate: createChat} = useGetConvoForMembers({
37 onSuccess: data => {
38 onSelectChat(data.convo.id)
39
40 if (!data.convo.lastMessage) {
41 ax.metric('chat:create', {logContext: 'SendViaChatDialog'})
42 }
43 ax.metric('chat:open', {logContext: 'SendViaChatDialog'})
44 },
45 onError: error => {
46 logger.error('Failed to share post to chat', {message: error})
47 Toast.show(
48 _(msg`An issue occurred while trying to open the chat`),
49 'xmark',
50 )
51 },
52 })
53
54 const onCreateChat = useCallback(
55 (did: string) => {
56 control.close(() => createChat([did]))
57 },
58 [control, createChat],
59 )
60
61 return (
62 <SearchablePeopleList
63 title={_(msg`Send post to...`)}
64 onSelectChat={onCreateChat}
65 showRecentConvos
66 sortByMessageDeclaration
67 />
68 )
69}