From 4c7e1bc2bf7ed97d93649e40351b048a06b5d0fd Mon Sep 17 00:00:00 2001
From: sowgro <tpoke.ferrari@gmail.com>
Date: Fri, 6 Dec 2024 18:36:12 -0500
Subject: improve drag n drop and refactor

---
 extension/src/components/DropTargets.tsx | 52 ++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 extension/src/components/DropTargets.tsx

(limited to 'extension/src/components/DropTargets.tsx')

diff --git a/extension/src/components/DropTargets.tsx b/extension/src/components/DropTargets.tsx
new file mode 100644
index 0000000..297f366
--- /dev/null
+++ b/extension/src/components/DropTargets.tsx
@@ -0,0 +1,52 @@
+import React, {useEffect} from "react";
+import {ActiveDrag} from "./Body.tsx";
+import CreateFolderIcon from "../assets/create_folder.svg?react"
+
+function DropTarget(props: {children: React.ReactNode, className: string, onDrop: () => void}) {
+    let [drop, setDrop] = React.useState(false);
+    let [activeDrag, _] = React.useContext(ActiveDrag);
+
+    useEffect(() => {
+        setDrop(false);
+    }, [activeDrag]);
+
+    function handleDragOver(e: React.DragEvent<HTMLDivElement>) {
+        e.preventDefault()
+        setDrop(true)
+    }
+
+    function handleDragLeave(e: React.DragEvent<HTMLDivElement>) {
+        setDrop(false)
+    }
+
+    function handleDrop(e: React.DragEvent<HTMLDivElement>) {
+        e.preventDefault();
+        props.onDrop();
+    }
+
+    return (
+        <div className={props.className} style={drop ? undefined : {opacity: 0}}
+            onDragOver={handleDragOver} onDragLeave={handleDragLeave} onDrop={handleDrop}>
+            {props.children}
+        </div>
+    );
+}
+
+function DropTargets(props: { onDropLeft: () => void, onDropRight: () => void, onDropCenter: () => void }) {
+
+    return (
+        <div className={"drop-targets"}>
+            <DropTarget className={"left"} onDrop={props.onDropLeft}>
+                <div/>
+            </DropTarget>
+            <DropTarget className={"right"} onDrop={props.onDropRight}>
+                <div/>
+            </DropTarget>
+            <DropTarget className={"center"} onDrop={props.onDropCenter}>
+                <CreateFolderIcon/>
+            </DropTarget>
+        </div>
+    );
+}
+
+export default DropTargets;
\ No newline at end of file
-- 
cgit v1.2.3

