1
1
import React , { useEffect , useState } from 'react' ;
2
-
2
+ import { cn } from "lib/utils" ;
3
3
4
4
import { ScrollArea } from '@/components/ui/scroll-area' ;
5
5
@@ -13,6 +13,7 @@ import TaskList from '@/components/TaskList';
13
13
import TaskConfigForm from '@/components/TaskConfigForm' ;
14
14
import TaskListControl from '@/components/TaskListControl' ;
15
15
import { getStaticPaths , makeStaticProperties } from '../../lib/get-static'
16
+ import { filterSupportedFiles } from 'lib/utils' ;
16
17
17
18
18
19
@@ -37,6 +38,36 @@ export default function Component() {
37
38
window . ipc . send ( 'setTasks' , files ) ;
38
39
} , [ files ] ) ;
39
40
41
+ const [ isDragging , setIsDragging ] = useState ( false ) ;
42
+
43
+ const handleDragOver = ( e : React . DragEvent ) => {
44
+ e . preventDefault ( ) ;
45
+ setIsDragging ( true ) ;
46
+ } ;
47
+
48
+ const handleDragLeave = ( e : React . DragEvent ) => {
49
+ e . preventDefault ( ) ;
50
+ setIsDragging ( false ) ;
51
+ } ;
52
+
53
+ const handleDrop = ( e : React . DragEvent ) => {
54
+ e . preventDefault ( ) ;
55
+ setIsDragging ( false ) ;
56
+
57
+ const droppedFiles = filterSupportedFiles ( Array . from ( e . dataTransfer . files ) ) ;
58
+
59
+ if ( droppedFiles . length > 0 ) {
60
+ const fileList = droppedFiles . map ( file => file . path ) ;
61
+ window ?. ipc ?. invoke ( 'getDroppedFiles' , fileList ) . then ( ( filePaths ) => {
62
+ const newFiles = filePaths . map ( filePath => ( {
63
+ uuid : Math . random ( ) . toString ( 36 ) . substring ( 2 ) ,
64
+ filePath
65
+ } ) ) ;
66
+ setFiles ( prevFiles => [ ...prevFiles , ...newFiles ] ) ;
67
+ } ) ;
68
+ }
69
+ } ;
70
+
40
71
return (
41
72
< div className = "grid flex-1 gap-4 overflow-auto p-4 md:grid-cols-2 lg:grid-cols-3" >
42
73
< div className = "relative hidden flex-col items-start gap-8 md:flex" >
@@ -48,7 +79,15 @@ export default function Component() {
48
79
isInstalledModel = { isInstalledModel }
49
80
/>
50
81
</ div >
51
- < div className = "relative flex h-full min-h-[50vh] border flex-col rounded-xl p-4 lg:col-span-2" >
82
+ < div
83
+ className = { cn (
84
+ "relative flex h-full min-h-[50vh] border flex-col rounded-xl p-4 lg:col-span-2" ,
85
+ isDragging && "border-2 border-dashed border-primary bg-muted/50"
86
+ ) }
87
+ onDrop = { handleDrop }
88
+ onDragOver = { handleDragOver }
89
+ onDragLeave = { handleDragLeave }
90
+ >
52
91
< TaskListControl setFiles = { setFiles } />
53
92
< ScrollArea className = "max-h-[780px]" >
54
93
< TaskList files = { files } formData = { formData } />
0 commit comments