11// src/components/DatasetOrganizer/DropZone.tsx
22import { processFile , processFolder , processZip } from "./utils/fileProcessors" ;
3- import { CloudUpload , Add } from "@mui/icons-material" ;
4- import { Box , Typography , Paper , Button , TextField } from "@mui/material" ;
3+ import { CloudUpload , Add , CheckCircle } from "@mui/icons-material" ;
4+ import {
5+ Box ,
6+ Typography ,
7+ Paper ,
8+ Button ,
9+ TextField ,
10+ CircularProgress ,
11+ } from "@mui/material" ;
512import { Colors } from "design/theme" ;
613import React , { useState , useRef } from "react" ;
714import { FileItem } from "redux/projects/types/projects.interface" ;
@@ -28,6 +35,7 @@ const DropZone: React.FC<DropZoneProps> = ({
2835 setExpandedIds,
2936} ) => {
3037 const [ isDragging , setIsDragging ] = useState ( false ) ;
38+ const [ isProcessing , setIsProcessing ] = useState ( false ) ; // ← add
3139 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
3240 // const [basePath, setBasePath] = useState<string>(""); // change
3341
@@ -44,6 +52,7 @@ const DropZone: React.FC<DropZoneProps> = ({
4452 const handleDrop = async ( e : React . DragEvent ) => {
4553 e . preventDefault ( ) ;
4654 setIsDragging ( false ) ;
55+ setIsProcessing ( true ) ; // ← add
4756
4857 const items = Array . from ( e . dataTransfer . items ) ; // detect if it is a folder
4958 const droppedFiles = Array . from ( e . dataTransfer . files ) ; // only gives file objects, can't detect folders
@@ -60,49 +69,51 @@ const DropZone: React.FC<DropZoneProps> = ({
6069 fileItems . push ( droppedFiles [ i ] ) ;
6170 }
6271 }
72+ try {
73+ // Process folders
74+ for ( const folderEntry of folderEntries ) {
75+ const folderFiles = await processFolder (
76+ folderEntry ,
77+ null ,
78+ baseDirectoryPath
79+ ) ;
80+ setFiles ( ( prev ) => [ ...prev , ...folderFiles ] ) ;
81+ }
6382
64- // Process folders
65- for ( const folderEntry of folderEntries ) {
66- // const folderFiles = await processFolder(folderEntry, null, basePath);// change
67- const folderFiles = await processFolder (
68- folderEntry ,
69- null ,
70- baseDirectoryPath
71- ) ; // add
72- setFiles ( ( prev ) => [ ...prev , ...folderFiles ] ) ;
73- }
74-
75- // Process files
76- for ( const file of fileItems ) {
77- if ( file . name . toLowerCase ( ) . endsWith ( ".zip" ) ) {
78- // const zipFiles = await processZip(file, basePath);//change
79- const zipFiles = await processZip ( file , baseDirectoryPath ) ; //add
80- setFiles ( ( prev ) => [ ...prev , ...zipFiles ] ) ;
81- } else {
82- // const fileItem = await processFile(file, basePath);//change
83- const fileItem = await processFile ( file , baseDirectoryPath ) ; //add
84- setFiles ( ( prev ) => [ ...prev , fileItem ] ) ;
83+ // Process files
84+ for ( const file of fileItems ) {
85+ if ( file . name . toLowerCase ( ) . endsWith ( ".zip" ) ) {
86+ const zipFiles = await processZip ( file , baseDirectoryPath ) ;
87+ setFiles ( ( prev ) => [ ...prev , ...zipFiles ] ) ;
88+ } else {
89+ const fileItem = await processFile ( file , baseDirectoryPath ) ;
90+ setFiles ( ( prev ) => [ ...prev , fileItem ] ) ;
91+ }
8592 }
93+ } finally {
94+ setIsProcessing ( false ) ;
8695 }
8796 } ;
8897
8998 const handleFileSelect = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
9099 const selectedFiles = Array . from ( e . target . files || [ ] ) ;
91-
92- for ( const file of selectedFiles ) {
93- if ( file . name . toLowerCase ( ) . endsWith ( ".zip" ) ) {
94- // const zipFiles = await processZip(file, basePath);//change
95- const zipFiles = await processZip ( file , baseDirectoryPath ) ; //add
96- setFiles ( ( prev ) => [ ...prev , ...zipFiles ] ) ;
97- } else {
98- // const fileItem = await processFile(file, basePath); //change
99- const fileItem = await processFile ( file , baseDirectoryPath ) ; //add
100- setFiles ( ( prev ) => [ ...prev , fileItem ] ) ;
100+ setIsProcessing ( true ) ;
101+
102+ try {
103+ for ( const file of selectedFiles ) {
104+ if ( file . name . toLowerCase ( ) . endsWith ( ".zip" ) ) {
105+ const zipFiles = await processZip ( file , baseDirectoryPath ) ;
106+ setFiles ( ( prev ) => [ ...prev , ...zipFiles ] ) ;
107+ } else {
108+ const fileItem = await processFile ( file , baseDirectoryPath ) ;
109+ setFiles ( ( prev ) => [ ...prev , fileItem ] ) ;
110+ }
101111 }
112+ } finally {
113+ setIsProcessing ( false ) ;
114+ // Reset input
115+ e . target . value = "" ;
102116 }
103-
104- // Reset input
105- e . target . value = "" ;
106117 } ;
107118
108119 return (
@@ -141,20 +152,38 @@ const DropZone: React.FC<DropZoneProps> = ({
141152 } ,
142153 } }
143154 >
144- < CloudUpload
155+ { /* <CloudUpload
145156 sx={{
146157 fontSize: files.length > 0 ? 40 : 64, // ← Smaller icon when files exist
147158 color: Colors.purple,
148159 mb: 1,
149160 }}
150- />
161+ /> */ }
162+ { isProcessing ? (
163+ < CircularProgress size = { 48 } sx = { { color : Colors . purple , mb : 1 } } />
164+ ) : (
165+ < CloudUpload
166+ sx = { {
167+ fontSize : files . length > 0 ? 40 : 64 ,
168+ color : Colors . purple ,
169+ mb : 1 ,
170+ } }
171+ />
172+ ) }
173+
151174 < Typography variant = { files . length > 0 ? "body1" : "h6" } gutterBottom >
152- { files . length > 0
175+ { /* {files.length > 0
176+ ? "Drop more files here"
177+ : "Drop your neuroimaging files here"} */ }
178+ { isProcessing
179+ ? "Processing files..."
180+ : files . length > 0
153181 ? "Drop more files here"
154182 : "Drop your neuroimaging files here" }
155183 </ Typography >
156184 < Typography variant = "body2" color = "text.secondary" sx = { { mb : 1 } } >
157- Supports NIfTI, SNIRF, HDF5, NeuroJSON, folders, and ZIP archives
185+ Supports NIfTI, DICOM, SNIRF, MATLAB, Homer3, HDF5, NeuroJSON,
186+ folders, and ZIP archives
158187 </ Typography >
159188
160189 { files . length === 0 && (
@@ -183,7 +212,7 @@ const DropZone: React.FC<DropZoneProps> = ({
183212 multiple
184213 hidden
185214 onChange = { handleFileSelect }
186- accept = ".nii,.nii.gz,.snirf,.h5,.hdf5,.jnii,.jmsh,.json,.txt,.md,.zip,.docx,.pdf,.xlsx,.xls"
215+ accept = ".nii,.nii.gz,.snirf,.h5,.hdf5,.jnii,.jmsh,.json,.txt,.md,.zip,.docx,.pdf,.xlsx,.xls,.mat,.dcm,.nirs "
187216 />
188217 </ Paper >
189218 < TextField
0 commit comments