@@ -16,10 +16,21 @@ import {
1616 INVALID_FILE_STATUS ,
1717 UPLOADED_UPLOAD_FILE_STATUS ,
1818} from "constants/uploadFile" ;
19- import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
19+ import pLimit from "p-limit" ;
20+ import {
21+ CSSProperties ,
22+ useCallback ,
23+ useEffect ,
24+ useMemo ,
25+ useRef ,
26+ useState ,
27+ } from "react" ;
2028import { useDropzone } from "react-dropzone" ;
2129import { useDispatch , useSelector } from "react-redux" ;
2230import { toast } from "react-toastify" ;
31+ import { AutoSizer } from "react-virtualized" ;
32+ import { FixedSizeList as List } from "react-window" ;
33+
2334import { selectorIsAlbumSelectMode } from "reduxes/album/selector" ;
2435import {
2536 selectorIsGenerateImagesAugmenting ,
@@ -131,6 +142,8 @@ const UploadFile = function (props: UploadFileProps) {
131142 selectorCurrentProjectTotalOriginalImage
132143 ) ;
133144 const [ isOpenUploadGuideDialog , setIsOpenUploadGuideDialog ] = useState ( false ) ;
145+ const [ resolutionChecking , setResolutionChecking ] = useState ( false ) ;
146+
134147 const isDisabledUpload = useMemo (
135148 ( ) =>
136149 isUploadChecking ||
@@ -194,51 +207,59 @@ const UploadFile = function (props: UploadFileProps) {
194207 const formatedFiles = convertArrayToObjectKeyFile ( acceptedFiles ) ;
195208 const files = { ...uploadFiles , ...formatedFiles } ;
196209 dispatch ( addFile ( { files : formatedFiles } ) ) ;
197-
210+ setResolutionChecking ( true ) ;
211+ const limit = pLimit ( 3 ) ;
198212 if ( files && Object . keys ( files ) . length > 0 ) {
199213 const filesNeedCheck : Array < string > = [ ] ;
200- const listPromiseLoadImages : Promise < LoadImageResult > [ ] = [ ] ;
214+ const listPromiseLoadImage : Promise < LoadImageResult > [ ] = [ ] ;
201215 Object . keys ( files ) . forEach ( ( fileName : string ) => {
202216 if ( files [ fileName ] . status !== UPLOADED_UPLOAD_FILE_STATUS ) {
203217 filesNeedCheck . push ( fileName ) ;
204218 if ( isImageFile ( fileName ) ) {
205- listPromiseLoadImages . push (
206- loadImage ( files [ fileName ] . file , fileName )
219+ listPromiseLoadImage . push (
220+ limit ( ( ) => loadImage ( files [ fileName ] . file , fileName ) )
207221 ) ;
208222 }
209223 }
210224 } ) ;
211- Promise . all ( listPromiseLoadImages ) . then ( ( values ) => {
212- values . forEach ( ( { image, fileName } ) => {
213- if (
214- image . width > LIMIT_IMAGE_WIDTH ||
215- image . height > LIMIT_IMAGE_HEIGHT
216- ) {
217- dispatch (
218- updateFile ( {
219- fileName,
220- updateInfo : {
221- error : `The image resolution (${ image . width } x ${ image . height } ) exceeds the limit allowed ${ LIMIT_IMAGE_WIDTH } x ${ LIMIT_IMAGE_HEIGHT } . Please remove it` ,
222- status : INVALID_FILE_STATUS ,
223- } ,
224- } )
225- ) ;
226-
227- const indexOf = filesNeedCheck . indexOf ( fileName ) ;
228- if ( indexOf !== - 1 ) {
229- filesNeedCheck . splice ( indexOf , 1 ) ;
225+ Promise . all ( listPromiseLoadImage )
226+ . then ( ( values ) => {
227+ values . forEach ( ( { image, fileName } ) => {
228+ if (
229+ image . width > LIMIT_IMAGE_WIDTH ||
230+ image . height > LIMIT_IMAGE_HEIGHT
231+ ) {
232+ dispatch (
233+ updateFile ( {
234+ fileName,
235+ updateInfo : {
236+ error : `The image resolution (${ image . width } x ${ image . height } ) exceeds the limit allowed ${ LIMIT_IMAGE_WIDTH } x ${ LIMIT_IMAGE_HEIGHT } . Please remove it` ,
237+ status : INVALID_FILE_STATUS ,
238+ } ,
239+ } )
240+ ) ;
241+
242+ const indexOf = filesNeedCheck . indexOf ( fileName ) ;
243+ if ( indexOf !== - 1 ) {
244+ filesNeedCheck . splice ( indexOf , 1 ) ;
245+ }
230246 }
231- }
247+ } ) ;
248+ setResolutionChecking ( false ) ;
249+
250+ dispatch (
251+ checkFileUpload ( {
252+ idToken : getLocalStorage ( ID_TOKEN_NAME ) || "" ,
253+ projectId,
254+ projectName,
255+ listFileName : filesNeedCheck ,
256+ } )
257+ ) ;
258+ } )
259+ . catch ( ( ) => {
260+ toast . error ( "The resolution checking process fails." ) ;
261+ setResolutionChecking ( false ) ;
232262 } ) ;
233- dispatch (
234- checkFileUpload ( {
235- idToken : getLocalStorage ( ID_TOKEN_NAME ) || "" ,
236- projectId,
237- projectName,
238- listFileName : filesNeedCheck ,
239- } )
240- ) ;
241- } ) ;
242263 }
243264 }
244265 } , [ ] ) ;
@@ -352,23 +373,41 @@ const UploadFile = function (props: UploadFileProps) {
352373 </ Typography >
353374 </ Box >
354375 ) ;
376+ const listFileName = useMemo (
377+ ( ) => Object . keys ( uploadFiles ) . sort ( ) ,
378+ [ uploadFiles ]
379+ ) ;
380+
381+ // eslint-disable-next-line react/no-unstable-nested-components
382+ function Row ( { index, style } : { index : number ; style : CSSProperties } ) {
383+ return (
384+ < UploadFileItem
385+ fileName = { listFileName [ index ] }
386+ onClickDelete = { onDeleteFile }
387+ onClickReplaceUpload = { onReplaceUpload }
388+ isUploading = { isUploading }
389+ style = { style }
390+ />
391+ ) ;
392+ }
355393
356394 const renderUploadFileContent = ( ) => {
357395 if ( uploadFiles && Object . keys ( uploadFiles ) . length > 0 ) {
358396 return (
359- < Box sx = { { overflowY : "auto" } } maxHeight = { 400 } >
360- { Object . keys ( uploadFiles ) . map ( ( fileName : string ) => (
361- < UploadFileItem
362- key = { `upload-file-item-${ uploadFiles [ fileName ] . name } ` }
363- file = { uploadFiles [ fileName ] . file }
364- status = { uploadFiles [ fileName ] . status }
365- error = { uploadFiles [ fileName ] . error }
366- uploadProgress = { uploadFiles [ fileName ] . uploadProgress }
367- onClickDelete = { onDeleteFile }
368- onClickReplaceUpload = { onReplaceUpload }
369- isUploading = { isUploading }
370- />
371- ) ) }
397+ < Box sx = { { overflowY : "auto" } } height = { 400 } >
398+ < AutoSizer >
399+ { ( { height, width } ) => (
400+ < List
401+ className = "List"
402+ height = { height }
403+ width = { width }
404+ itemCount = { Object . keys ( uploadFiles ) . length }
405+ itemSize = { 70 }
406+ >
407+ { Row }
408+ </ List >
409+ ) }
410+ </ AutoSizer >
372411 </ Box >
373412 ) ;
374413 }
@@ -486,6 +525,16 @@ const UploadFile = function (props: UploadFileProps) {
486525 </ Typography >
487526 </ Box >
488527 ) }
528+ { resolutionChecking === true && (
529+ < Box display = "flex" alignItems = "center" >
530+ < Box sx = { { width : "calc(100% - 35px)" } } mr = { 1 } my = { 1 } >
531+ < Box minWidth = { 35 } >
532+ < Typography variant = "body2" > Resolution checking</ Typography >
533+ </ Box >
534+ < LinearProgress />
535+ </ Box >
536+ </ Box >
537+ ) }
489538 { ! ! uploadingFileCount &&
490539 uploadingProgress >= 0 &&
491540 uploadingProgress < 100 && (
0 commit comments