From a763ead3ece10e09b4e4cbe2ed886bd2b4482c89 Mon Sep 17 00:00:00 2001 From: alexsparkes Date: Sat, 24 Jan 2026 22:41:00 +0000 Subject: [PATCH] feat: enhance drag-and-drop functionality in CustomSettings component --- src/features/background/options/Custom.jsx | 46 +++++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/features/background/options/Custom.jsx b/src/features/background/options/Custom.jsx index 7326ceea..8b7f8012 100644 --- a/src/features/background/options/Custom.jsx +++ b/src/features/background/options/Custom.jsx @@ -33,7 +33,9 @@ const CustomSettings = memo(() => { const [urlError, setUrlError] = useState(''); const [currentBackgroundIndex, setCurrentBackgroundIndex] = useState(0); const [isLoading, setIsLoading] = useState(true); + const [isDragging, setIsDragging] = useState(false); const customDnd = useRef(null); + const dragCounter = useRef(0); // Load backgrounds from IndexedDB on mount useEffect(() => { @@ -157,10 +159,35 @@ const CustomSettings = memo(() => { const handleDragOver = (e) => { e.preventDefault(); + e.stopPropagation(); + }; + + const handleDragEnter = (e) => { + e.preventDefault(); + e.stopPropagation(); + dragCounter.current++; + console.log('Drag enter, counter:', dragCounter.current); + if (e.dataTransfer.items && e.dataTransfer.items.length > 0) { + setIsDragging(true); + console.log('Setting isDragging to true'); + } + }; + + const handleDragLeave = (e) => { + e.preventDefault(); + e.stopPropagation(); + dragCounter.current--; + if (dragCounter.current === 0) { + setIsDragging(false); + } }; const handleDrop = (e) => { e.preventDefault(); + e.stopPropagation(); + setIsDragging(false); + dragCounter.current = 0; + const files = Array.from(e.dataTransfer.files); const settings = {}; @@ -213,13 +240,15 @@ const CustomSettings = memo(() => { }; dnd.ondragover = handleDragOver; - dnd.ondragenter = handleDragOver; + dnd.ondragenter = handleDragEnter; + dnd.ondragleave = handleDragLeave; dnd.ondrop = handleDrop; return () => { if (dnd) { dnd.ondragover = null; dnd.ondragenter = null; + dnd.ondragleave = null; dnd.ondrop = null; } }; @@ -237,7 +266,20 @@ const CustomSettings = memo(() => { return ( <> -
+