Skip to content

Commit

Permalink
fix: early return file dnd if not dragging files (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Apr 26, 2022
1 parent 50d047a commit 63fcd3d
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const removeDragOverlay = () => {
document.getElementById('drag-overlay')?.remove()
}

const isHandlingFileDrag = (event: DragEvent) =>
event.dataTransfer?.items &&
Array.from(event.dataTransfer.items).some((item) => item.kind === 'file')

export const AttachedFilesButton: FunctionComponent<Props> = observer(
({ application, appState, onClickPreprocessing }) => {
const premiumModal = usePremiumModal()
Expand Down Expand Up @@ -223,17 +227,18 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
const dragCounter = useRef(0)

const handleDrag = (event: DragEvent) => {
if (
event.dataTransfer?.items &&
Array.from(event.dataTransfer.items).some((item) => item.kind === 'file')
) {
if (isHandlingFileDrag(event)) {
event.preventDefault()
event.stopPropagation()
}
}

const handleDragIn = useCallback(
(event: DragEvent) => {
if (!isHandlingFileDrag(event)) {
return
}

event.preventDefault()
event.stopPropagation()

Expand All @@ -251,6 +256,10 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
)

const handleDragOut = (event: DragEvent) => {
if (!isHandlingFileDrag(event)) {
return
}

event.preventDefault()
event.stopPropagation()

Expand All @@ -267,6 +276,10 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(

const handleDrop = useCallback(
(event: DragEvent) => {
if (!isHandlingFileDrag(event)) {
return
}

event.preventDefault()
event.stopPropagation()

Expand Down

0 comments on commit 63fcd3d

Please sign in to comment.