@@ -8,10 +8,10 @@ import { useFileContext } from '../context/UsersFiles';
88import CustomAlert from './Alert' ;
99import { CustomFile , alertState } from '../types' ;
1010import { chunkSize } from '../utils/Constants' ;
11- import { getFileFromLocal , url } from '../utils/Utils' ;
11+ import { url } from '../utils/Utils' ;
1212
1313const DropZone : FunctionComponent = ( ) => {
14- const { files , filesData, setFiles , setFilesData, model } = useFileContext ( ) ;
14+ const { filesData, setFilesData, model } = useFileContext ( ) ;
1515 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
1616 const [ isClicked , setIsClicked ] = useState < boolean > ( false ) ;
1717 const { userCredentials } = useCredentials ( ) ;
@@ -36,14 +36,13 @@ const DropZone: FunctionComponent = () => {
3636 type : 'PDF' ,
3737 model : model ,
3838 fileSource : 'local file' ,
39+ uploadprogess : 0 ,
3940 } ;
4041
4142 const copiedFilesData : CustomFile [ ] = [ ...filesData ] ;
42- const copiedFiles : ( File | null ) [ ] = [ ...files ] ;
4343
4444 f . forEach ( ( file ) => {
4545 const filedataIndex = copiedFilesData . findIndex ( ( filedataitem ) => filedataitem ?. name === file ?. name ) ;
46- const fileIndex = copiedFiles . findIndex ( ( filedataitem ) => filedataitem ?. name === file ?. name ) ;
4746 if ( filedataIndex == - 1 ) {
4847 copiedFilesData . unshift ( {
4948 name : file . name ,
@@ -64,17 +63,7 @@ const DropZone: FunctionComponent = () => {
6463 fileSource : defaultValues . fileSource ,
6564 } ) ;
6665 }
67- if ( fileIndex == - 1 ) {
68- copiedFiles . unshift ( file as File ) ;
69- } else {
70- const tempFile = copiedFiles [ filedataIndex ] ;
71- copiedFiles . splice ( fileIndex , 1 ) ;
72- if ( tempFile ) {
73- copiedFiles . unshift ( getFileFromLocal ( tempFile . name ) ) ;
74- }
75- }
7666 } ) ;
77- setFiles ( copiedFiles ) ;
7867 setFilesData ( copiedFilesData ) ;
7968 }
8069 } ;
@@ -105,7 +94,7 @@ const DropZone: FunctionComponent = () => {
10594 const uploadNextChunk = async ( ) => {
10695 if ( chunkNumber <= totalChunks ) {
10796 const chunk = file . slice ( start , end ) ;
108- console . log ( { chunkNumber } )
97+ console . log ( { chunkNumber } ) ;
10998 const formData = new FormData ( ) ;
11099 formData . append ( 'file' , chunk ) ;
111100 formData . append ( 'chunkNumber' , chunkNumber . toString ( ) ) ;
@@ -128,15 +117,11 @@ const DropZone: FunctionComponent = () => {
128117 } )
129118 ) ;
130119 try {
131- const apiResponse = await axios . post (
132- `${ url ( ) } /upload` ,
133- formData ,
134- {
135- headers : {
136- 'Content-Type' : 'multipart/form-data' ,
137- } ,
138- }
139- ) ;
120+ const apiResponse = await axios . post ( `${ url ( ) } /upload` , formData , {
121+ headers : {
122+ 'Content-Type' : 'multipart/form-data' ,
123+ } ,
124+ } ) ;
140125 console . log ( apiResponse . data ) ;
141126 if ( apiResponse ?. data . status === 'Failed' ) {
142127 throw new Error ( `message:${ apiResponse . data . message } ,fileName:${ apiResponse . data . file_name } ` ) ;
@@ -146,7 +131,7 @@ const DropZone: FunctionComponent = () => {
146131 if ( curfile . name == file . name ) {
147132 return {
148133 ...curfile ,
149- uploadprogess : ( chunkNumber ) * chunkProgressIncrement ,
134+ uploadprogess : chunkNumber * chunkProgressIncrement ,
150135 } ;
151136 }
152137 return curfile ;
@@ -155,14 +140,14 @@ const DropZone: FunctionComponent = () => {
155140 chunkNumber ++ ;
156141 start = end ;
157142 if ( start + chunkSize < file . size ) {
158- end = start + chunkSize
143+ end = start + chunkSize ;
159144 } else {
160145 end = file . size + 1 ;
161146 }
162147 uploadNextChunk ( ) ;
163148 }
164149 } catch ( error ) {
165- setIsLoading ( false )
150+ setIsLoading ( false ) ;
166151 setalertDetails ( {
167152 showAlert : true ,
168153 alertType : 'error' ,
@@ -187,7 +172,7 @@ const DropZone: FunctionComponent = () => {
187172 if ( curfile . name == file . name ) {
188173 return {
189174 ...curfile ,
190- status :" New" ,
175+ status : ' New' ,
191176 uploadprogess : 100 ,
192177 } ;
193178 }
@@ -239,4 +224,4 @@ const DropZone: FunctionComponent = () => {
239224 ) ;
240225} ;
241226
242- export default DropZone ;
227+ export default DropZone ;
0 commit comments