Skip to content

Commit

Permalink
Fix duplicates in thread composer (#6068)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Nov 1, 2024
1 parent d33ce1d commit 46004fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ let ComposerPost = React.memo(function ComposerPost({
placeholder={selectTextInputPlaceholder}
autoFocus
webForceMinHeight={forceMinHeight}
isActive={isActive}
setRichText={rt => {
dispatchPost({type: 'update_richtext', richtext: rt})
}}
Expand Down
1 change: 1 addition & 0 deletions src/view/com/composer/text-input/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface TextInputProps extends ComponentProps<typeof RNTextInput> {
richtext: RichText
placeholder: string
webForceMinHeight: boolean
isActive: boolean
setRichText: (v: RichText) => void
onPhotoPasted: (uri: string) => void
onPressPublish: (richtext: RichText) => void
Expand Down
24 changes: 20 additions & 4 deletions src/view/com/composer/text-input/TextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface TextInputProps {
placeholder: string
suggestedLinks: Set<string>
webForceMinHeight: boolean
isActive: boolean
setRichText: (v: RichText | ((v: RichText) => RichText)) => void
onPhotoPasted: (uri: string) => void
onPressPublish: (richtext: RichText) => void
Expand All @@ -55,6 +56,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
richtext,
placeholder,
webForceMinHeight,
isActive,
setRichText,
onPhotoPasted,
onPressPublish,
Expand Down Expand Up @@ -94,19 +96,30 @@ export const TextInput = React.forwardRef(function TextInputImpl(
)

React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('publish', onPressPublish)
return () => {
textInputWebEmitter.removeListener('publish', onPressPublish)
}
}, [onPressPublish])
}, [onPressPublish, isActive])

React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('media-pasted', onPhotoPasted)
return () => {
textInputWebEmitter.removeListener('media-pasted', onPhotoPasted)
}
}, [onPhotoPasted])
}, [isActive, onPhotoPasted])

React.useEffect(() => {
if (!isActive) {
return
}

const handleDrop = (event: DragEvent) => {
const transfer = event.dataTransfer
if (transfer) {
Expand Down Expand Up @@ -144,7 +157,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
document.body.removeEventListener('dragover', handleDragEnter)
document.body.removeEventListener('dragleave', handleDragLeave)
}
}, [setIsDropping])
}, [setIsDropping, isActive])

const pastSuggestedUris = useRef(new Set<string>())
const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>())
Expand Down Expand Up @@ -242,11 +255,14 @@ export const TextInput = React.forwardRef(function TextInputImpl(
[editor],
)
React.useEffect(() => {
if (!isActive) {
return
}
textInputWebEmitter.addListener('emoji-inserted', onEmojiInserted)
return () => {
textInputWebEmitter.removeListener('emoji-inserted', onEmojiInserted)
}
}, [onEmojiInserted])
}, [onEmojiInserted, isActive])

React.useImperativeHandle(ref, () => ({
focus: () => {
Expand Down

0 comments on commit 46004fb

Please sign in to comment.