@@ -47,6 +47,11 @@ const Controller = () => {
4747 const [ scriptRunning , setScriptRunning ] = useState < boolean > ( false ) ;
4848 const [ dirStructure , setDirStructure ] = useState < FileStructure [ ] > ( ) ;
4949 const [ latestVersion , setLatestVersion ] = useState < ILatestVersions > ( ) ;
50+
51+ // Upload progress state for file manager
52+ const [ uploadStatus , setUploadStatus ] = useState < string > ( "" ) ;
53+ const [ isUploading , setIsUploading ] = useState < boolean > ( false ) ;
54+ const [ currentUploadFileName , setCurrentUploadFileName ] = useState < string > ( "" ) ;
5055
5156 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
5257 const firmwareFileInputRef = useRef < HTMLInputElement > ( null ) ;
@@ -88,23 +93,41 @@ const Controller = () => {
8893 const onFileChange = ( event : ChangeEvent < HTMLInputElement > , path : string ) => {
8994 const fileList = event . target . files ;
9095 if ( ! fileList ) return ;
91-
96+
9297 let file = fileList [ 0 ] ;
98+ setCurrentUploadFileName ( file . name ) ;
99+ setIsUploading ( true ) ;
100+ // Don't set initial status - let uploadFile handle all status updates
101+
93102 let reader = new FileReader ( ) ;
94-
103+
95104 reader . onloadend = async ( ) => {
96105 const arrayBuffer = reader . result ;
97106 if ( arrayBuffer instanceof ArrayBuffer ) {
98107 let bytes = new Uint8Array ( arrayBuffer ) ;
99- // ToDo: This should possibly be some sort of callback
100- await uploadFile ( path + file . name , bytes , setUpdateStatus ) ;
108+
109+ // uploadFile will handle all status updates through setUploadStatus
110+ await uploadFile ( path + file . name , bytes , setUploadStatus ) ;
111+
112+ // Wait a bit after upload completes before closing modal
113+ setTimeout ( ( ) => {
114+ setIsUploading ( false ) ;
115+ setUploadStatus ( "" ) ;
116+ setCurrentUploadFileName ( "" ) ;
117+ } , 5000 ) ;
101118 }
102119 } ;
103-
120+
104121 reader . onerror = ( ) => {
105122 console . error ( "A problem occurred while reading the file." ) ;
123+ setUploadStatus ( "❌ Error: Failed to read file" ) ;
124+ setTimeout ( ( ) => {
125+ setIsUploading ( false ) ;
126+ setUploadStatus ( "" ) ;
127+ setCurrentUploadFileName ( "" ) ;
128+ } , 3000 ) ;
106129 } ;
107-
130+
108131 if ( file ) {
109132 reader . readAsArrayBuffer ( file ) ;
110133 }
@@ -466,8 +489,35 @@ const Controller = () => {
466489 handleUpdateUiHide = { handleUpdateUiHide }
467490 toggleLiveScreen = { toggleLiveScreen }
468491 />
492+ { /* Upload Progress Modal for File Manager */ }
493+ < Modal
494+ title = { `Uploading: ${ currentUploadFileName } ` }
495+ isModalOpen = { isUploading }
496+ closeModal = { ( ) => {
497+ // Allow closing when upload is complete
498+ if ( ! uploadStatus . includes ( "Complete!" ) ) return ;
499+ setIsUploading ( false ) ;
500+ setUploadStatus ( "" ) ;
501+ } }
502+ className = "w-96"
503+ >
504+ < div className = "space-y-2" >
505+ { uploadStatus . includes ( "Progress" ) && (
506+ < div className = "w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700" >
507+ < div
508+ className = "bg-blue-400 h-2.5 rounded-full transition-all duration-300"
509+ style = { {
510+ width : `${ uploadStatus . split ( 'Progress: ' ) [ 1 ] ?. split ( '%' ) [ 0 ] || 0 } %`
511+ } }
512+ />
513+ </ div >
514+ ) }
515+ < p className = "whitespace-pre-wrap text-sm" > { uploadStatus } </ p >
516+ </ div >
517+ </ Modal >
469518 </ >
470519 ) ;
471520} ;
472521
473522export default Controller ;
523+
0 commit comments