Fix duplicates in thread composer (#6068)

This commit is contained in:
dan
2024-11-01 21:55:37 +00:00
committed by GitHub
parent d33ce1dea1
commit 46004fb2d0
3 changed files with 22 additions and 4 deletions
+1
View File
@@ -743,6 +743,7 @@ let ComposerPost = React.memo(function ComposerPost({
placeholder={selectTextInputPlaceholder} placeholder={selectTextInputPlaceholder}
autoFocus autoFocus
webForceMinHeight={forceMinHeight} webForceMinHeight={forceMinHeight}
isActive={isActive}
setRichText={rt => { setRichText={rt => {
dispatchPost({type: 'update_richtext', richtext: rt}) dispatchPost({type: 'update_richtext', richtext: rt})
}} }}
@@ -44,6 +44,7 @@ interface TextInputProps extends ComponentProps<typeof RNTextInput> {
richtext: RichText richtext: RichText
placeholder: string placeholder: string
webForceMinHeight: boolean webForceMinHeight: boolean
isActive: boolean
setRichText: (v: RichText) => void setRichText: (v: RichText) => void
onPhotoPasted: (uri: string) => void onPhotoPasted: (uri: string) => void
onPressPublish: (richtext: RichText) => void onPressPublish: (richtext: RichText) => void
@@ -42,6 +42,7 @@ interface TextInputProps {
placeholder: string placeholder: string
suggestedLinks: Set<string> suggestedLinks: Set<string>
webForceMinHeight: boolean webForceMinHeight: boolean
isActive: boolean
setRichText: (v: RichText | ((v: RichText) => RichText)) => void setRichText: (v: RichText | ((v: RichText) => RichText)) => void
onPhotoPasted: (uri: string) => void onPhotoPasted: (uri: string) => void
onPressPublish: (richtext: RichText) => void onPressPublish: (richtext: RichText) => void
@@ -55,6 +56,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
richtext, richtext,
placeholder, placeholder,
webForceMinHeight, webForceMinHeight,
isActive,
setRichText, setRichText,
onPhotoPasted, onPhotoPasted,
onPressPublish, onPressPublish,
@@ -94,19 +96,30 @@ export const TextInput = React.forwardRef(function TextInputImpl(
) )
React.useEffect(() => { React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('publish', onPressPublish) textInputWebEmitter.addListener('publish', onPressPublish)
return () => { return () => {
textInputWebEmitter.removeListener('publish', onPressPublish) textInputWebEmitter.removeListener('publish', onPressPublish)
} }
}, [onPressPublish]) }, [onPressPublish, isActive])
React.useEffect(() => { React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('media-pasted', onPhotoPasted) textInputWebEmitter.addListener('media-pasted', onPhotoPasted)
return () => { return () => {
textInputWebEmitter.removeListener('media-pasted', onPhotoPasted) textInputWebEmitter.removeListener('media-pasted', onPhotoPasted)
} }
}, [onPhotoPasted]) }, [isActive, onPhotoPasted])
React.useEffect(() => { React.useEffect(() => {
if (!isActive) {
return
}
const handleDrop = (event: DragEvent) => { const handleDrop = (event: DragEvent) => {
const transfer = event.dataTransfer const transfer = event.dataTransfer
if (transfer) { if (transfer) {
@@ -144,7 +157,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
document.body.removeEventListener('dragover', handleDragEnter) document.body.removeEventListener('dragover', handleDragEnter)
document.body.removeEventListener('dragleave', handleDragLeave) document.body.removeEventListener('dragleave', handleDragLeave)
} }
}, [setIsDropping]) }, [setIsDropping, isActive])
const pastSuggestedUris = useRef(new Set<string>()) const pastSuggestedUris = useRef(new Set<string>())
const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>()) const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>())
@@ -242,11 +255,14 @@ export const TextInput = React.forwardRef(function TextInputImpl(
[editor], [editor],
) )
React.useEffect(() => { React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('emoji-inserted', onEmojiInserted) textInputWebEmitter.addListener('emoji-inserted', onEmojiInserted)
return () => { return () => {
textInputWebEmitter.removeListener('emoji-inserted', onEmojiInserted) textInputWebEmitter.removeListener('emoji-inserted', onEmojiInserted)
} }
}, [onEmojiInserted]) }, [onEmojiInserted, isActive])
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
focus: () => { focus: () => {