Update MessageInput.tsx
This commit is contained in:
@@ -15,6 +15,7 @@ import Animated, {
|
|||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import {GlassContainer} from 'expo-glass-effect'
|
import {GlassContainer} from 'expo-glass-effect'
|
||||||
|
import {type $Typed, type ChatBskyConvoDefs} from '@atproto/api'
|
||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
import {countGraphemes} from 'unicode-segmenter/grapheme'
|
import {countGraphemes} from 'unicode-segmenter/grapheme'
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ import {
|
|||||||
useSaveMessageDraft,
|
useSaveMessageDraft,
|
||||||
} from '#/state/messages/message-drafts'
|
} from '#/state/messages/message-drafts'
|
||||||
import {atoms as a, platform, tokens, useTheme} from '#/alf'
|
import {atoms as a, platform, tokens, useTheme} from '#/alf'
|
||||||
|
import {useMessageReplies} from '#/components/dms/MessageReplies'
|
||||||
import {GlassView} from '#/components/GlassView'
|
import {GlassView} from '#/components/GlassView'
|
||||||
import {PaperPlaneVertical_Filled_Stroke2_Corner1_Rounded as PaperPlaneIcon} from '#/components/icons/PaperPlane'
|
import {PaperPlaneVertical_Filled_Stroke2_Corner1_Rounded as PaperPlaneIcon} from '#/components/icons/PaperPlane'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
@@ -47,7 +49,10 @@ export function MessageInput({
|
|||||||
loading = false,
|
loading = false,
|
||||||
}: {
|
}: {
|
||||||
textInputId?: string
|
textInputId?: string
|
||||||
onSendMessage: (message: string) => Promise<void> | void
|
onSendMessage: (
|
||||||
|
message: string,
|
||||||
|
replyTo?: $Typed<ChatBskyConvoDefs.MessageView>,
|
||||||
|
) => Promise<void> | void
|
||||||
hasEmbed: boolean
|
hasEmbed: boolean
|
||||||
setEmbed: (embedUrl: string | undefined) => void
|
setEmbed: (embedUrl: string | undefined) => void
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
@@ -57,6 +62,7 @@ export function MessageInput({
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const playHaptic = useHaptics()
|
const playHaptic = useHaptics()
|
||||||
const {getDraft, clearDraft} = useMessageDraft()
|
const {getDraft, clearDraft} = useMessageDraft()
|
||||||
|
const {replyTo, clearReply} = useMessageReplies()
|
||||||
|
|
||||||
// Input layout
|
// Input layout
|
||||||
const {top: topInset} = useSafeAreaInsets()
|
const {top: topInset} = useSafeAreaInsets()
|
||||||
@@ -92,6 +98,9 @@ export function MessageInput({
|
|||||||
playHaptic()
|
playHaptic()
|
||||||
setEmbed(undefined)
|
setEmbed(undefined)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
|
// Capture the reply before clearing - the deferred send below reads it.
|
||||||
|
const reply = replyTo
|
||||||
|
clearReply()
|
||||||
if (IS_IOS) {
|
if (IS_IOS) {
|
||||||
setShouldEnforceClear(true)
|
setShouldEnforceClear(true)
|
||||||
}
|
}
|
||||||
@@ -104,7 +113,12 @@ export function MessageInput({
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
void onSendMessage(message)
|
void onSendMessage(
|
||||||
|
message,
|
||||||
|
reply
|
||||||
|
? {...reply, $type: 'chat.bsky.convo.defs#messageView'}
|
||||||
|
: undefined,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}, [
|
}, [
|
||||||
editable,
|
editable,
|
||||||
@@ -116,6 +130,8 @@ export function MessageInput({
|
|||||||
setEmbed,
|
setEmbed,
|
||||||
inputRef,
|
inputRef,
|
||||||
l,
|
l,
|
||||||
|
replyTo,
|
||||||
|
clearReply,
|
||||||
])
|
])
|
||||||
|
|
||||||
useFocusedInputHandler(
|
useFocusedInputHandler(
|
||||||
|
|||||||
Reference in New Issue
Block a user