Skip to content

Commit 6d5cad0

Browse files
Address comments, fix hover state
1 parent 63f6925 commit 6d5cad0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-drag-drop.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
252252
if (!isDragging) {
253253
isDraggingRef.current = true
254254
setIsDragging(true)
255+
} else if (scrollAnimationRef.current === null) {
256+
scrollAnimationRef.current = requestAnimationFrame(handleAutoScroll)
255257
}
256258

257259
return true
258260
},
259-
[isDragging]
261+
[isDragging, handleAutoScroll]
260262
)
261263

262264
const getSiblingItems = useCallback(
@@ -622,10 +624,23 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
622624
if (!container) return
623625
const onLeave = (e: DragEvent) => {
624626
const related = e.relatedTarget as Node | null
625-
if (!related || !container.contains(related)) handleDragEnd()
627+
if (related && container.contains(related)) return
628+
if (scrollAnimationRef.current !== null) {
629+
cancelAnimationFrame(scrollAnimationRef.current)
630+
scrollAnimationRef.current = null
631+
}
632+
dropIndicatorRef.current = null
633+
setDropIndicator(null)
634+
setHoverFolderId(null)
626635
}
627636
container.addEventListener('dragleave', onLeave)
628-
return () => container.removeEventListener('dragleave', onLeave)
637+
window.addEventListener('drop', handleDragEnd, true)
638+
window.addEventListener('dragend', handleDragEnd, true)
639+
return () => {
640+
container.removeEventListener('dragleave', onLeave)
641+
window.removeEventListener('drop', handleDragEnd, true)
642+
window.removeEventListener('dragend', handleDragEnd, true)
643+
}
629644
}, [isDragging, handleDragEnd])
630645

631646
const setScrollContainer = useCallback((element: HTMLDivElement | null) => {

0 commit comments

Comments
 (0)