@@ -15,7 +15,8 @@ export enum UploadStatus {
1515 REQUESTING_PERMISSION = 'requesting_permission' ,
1616 UPLOADING = 'uploading' ,
1717 SUCCESS = 'success' ,
18- ERROR = 'error'
18+ ERROR = 'error' ,
19+ CANCELLED = 'cancelled'
1920}
2021
2122interface UseFileUploadOptions {
@@ -72,7 +73,7 @@ export const useFileUpload = ({ onUploadComplete }: UseFileUploadOptions = {}):
7273 }
7374
7475 if ( status === UploadStatus . UPLOADING || status === UploadStatus . REQUESTING_PERMISSION ) {
75- setStatus ( UploadStatus . IDLE ) ;
76+ setStatus ( UploadStatus . CANCELLED ) ;
7677 setProgress ( 0 ) ;
7778 } else {
7879 reset ( ) ;
@@ -119,10 +120,17 @@ export const useFileUpload = ({ onUploadComplete }: UseFileUploadOptions = {}):
119120 } , [ ] ) ;
120121
121122 const uploadFile = useCallback ( async ( ) => {
123+ // Don't proceed if there's no file or if the status is CANCELLED
122124 if ( ! file ) {
123125 setError ( t ( 'upload.error.noFile' ) ) ;
124126 return ;
125127 }
128+
129+ // If currently in CANCELLED state, we need to reset first
130+ if ( status === UploadStatus . CANCELLED ) {
131+ reset ( ) ;
132+ return ;
133+ }
126134
127135 // Reset cancel flag
128136 cancelRef . current = false ;
@@ -145,7 +153,7 @@ export const useFileUpload = ({ onUploadComplete }: UseFileUploadOptions = {}):
145153
146154 // Check if canceled during permission check
147155 if ( isUploadCanceled ( signal ) ) {
148- setStatus ( UploadStatus . IDLE ) ;
156+ setStatus ( UploadStatus . CANCELLED ) ;
149157 return ;
150158 }
151159
@@ -160,7 +168,7 @@ export const useFileUpload = ({ onUploadComplete }: UseFileUploadOptions = {}):
160168
161169 // Check if canceled during upload
162170 if ( isUploadCanceled ( signal ) ) {
163- setStatus ( UploadStatus . IDLE ) ;
171+ setStatus ( UploadStatus . CANCELLED ) ;
164172 return ;
165173 }
166174
@@ -176,7 +184,7 @@ export const useFileUpload = ({ onUploadComplete }: UseFileUploadOptions = {}):
176184 } finally {
177185 cleanupAbortController ( signal ) ;
178186 }
179- } , [ file , onUploadComplete , t , createProgressCallback , isUploadCanceled ] ) ;
187+ } , [ file , status , onUploadComplete , t , createProgressCallback , isUploadCanceled , reset ] ) ;
180188
181189 // Helper to handle file permissions
182190 const checkPermissions = useCallback ( async ( ) : Promise < boolean > => {
0 commit comments