Skip to content
Snippets Groups Projects
Commit 4a9630d4 authored by Jose Manuel Serrano Amaut's avatar Jose Manuel Serrano Amaut
Browse files

[FIX]: prevent infinite bucle when value is unddefined. CHanged to default empty array []

parent bb23e98b
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -67,7 +67,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
style, style,
textColor, textColor,
validator, validator,
value, value = [],
uploadConfig, uploadConfig,
backgroundColor, backgroundColor,
disableRipple, disableRipple,
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
fakeFuiUpload, fakeFuiUpload,
fileListToExtFileArray, fileListToExtFileArray,
FileValidatorProps, FileValidatorProps,
FunctionLabel, //FunctionLabel,
handleClickInput, handleClickInput,
instantPreparingToUploadOne, instantPreparingToUploadOne,
isValidateActive, isValidateActive,
...@@ -18,7 +18,8 @@ import { ...@@ -18,7 +18,8 @@ import {
sleepTransition, sleepTransition,
toUploadableExtFileList, toUploadableExtFileList,
UploadConfig, UploadConfig,
uploadOnePromiseXHR, uploadExtFile,
//uploadOnePromiseXHR,
UploadResponse, UploadResponse,
validateExtFileList, validateExtFileList,
} from "../../core"; } from "../../core";
...@@ -42,7 +43,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( ...@@ -42,7 +43,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
uploadConfig, uploadConfig,
onChange, onChange,
behaviour, behaviour,
value, value = [],
localization, localization,
disabled, disabled,
onUploadFinish, onUploadFinish,
...@@ -88,6 +89,17 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( ...@@ -88,6 +89,17 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
//state for managing the number of valid files //state for managing the number of valid files
//state for managing the files locally //state for managing the files locally
console.table({
inputButtonId,
value,
isUploading,
maxFileSize,
accept,
maxFiles,
validator,
localization,
validateFilesFlag,
});
const [localFiles, numberOfValidFiles, setLocalFiles]: [ const [localFiles, numberOfValidFiles, setLocalFiles]: [
ExtFile[], ExtFile[],
number, number,
...@@ -210,20 +222,43 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( ...@@ -210,20 +222,43 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
//UPLOADING => UPLOAD() //UPLOADING => UPLOAD()
//upload one file and notify about change //upload one file and notify about change
const uploadResponse: UploadResponse = fakeUpload let uploadResponse: UploadResponse;
try {
uploadResponse = fakeUpload
? await fakeFuiUpload(currentExtFileInstance, DropzoneLocalizer) ? await fakeFuiUpload(currentExtFileInstance, DropzoneLocalizer)
: await uploadOnePromiseXHR( : await uploadExtFile(
currentExtFileInstance, currentExtFileInstance,
url, url,
method, method,
headers, headers,
uploadLabel uploadLabel
); );
} catch (error) {
uploadResponse = {
id: currentExtFileInstance.id,
serverResponse: {
success: false,
message: "Error on upload: unexpected error " + error,
payload: {},
},
uploadedFile: { ...currentExtFileInstance },
};
}
const { uploadedFile } = uploadResponse; const { uploadedFile } = uploadResponse;
//update instances //update instances
currentExtFileInstance.uploadStatus = uploadedFile.uploadStatus; currentExtFileInstance.uploadStatus = uploadedFile.uploadStatus;
currentExtFileInstance.uploadMessage = uploadedFile.uploadMessage; currentExtFileInstance.uploadMessage = uploadedFile.uploadMessage;
//add fake progress only on fakeupload
if (fakeUpload) {
console.log(
"Adding fake progress",
fakeUpload,
uploadedFile.progress
);
currentExtFileInstance.progress = uploadedFile.progress;
}
//CHANGE //CHANGE
if (!(currentExtFileInstance.uploadStatus === "aborted")) if (!(currentExtFileInstance.uploadStatus === "aborted"))
await sleepTransition(); await sleepTransition();
...@@ -244,10 +279,10 @@ const FileInputButton: React.FC<FileInputButtonProps> = ( ...@@ -244,10 +279,10 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
// upload group finished :D // upload group finished :D
onUploadFinish?.(serverResponses); onUploadFinish?.(serverResponses);
const finishUploadMessenger: FunctionLabel = /* const finishUploadMessenger: FunctionLabel =
DropzoneLocalizer.uploadFinished as FunctionLabel; DropzoneLocalizer.uploadFinished as FunctionLabel;
/* setLocalMessage( setLocalMessage(
finishUploadMessenger(missingUpload - totalRejected, totalRejected) finishUploadMessenger(missingUpload - totalRejected, totalRejected)
); */ ); */
setIsUploading(false); setIsUploading(false);
......
...@@ -35,7 +35,7 @@ const useDropzoneFileListUpdater = ( ...@@ -35,7 +35,7 @@ const useDropzoneFileListUpdater = (
React.useEffect(() => { React.useEffect(() => {
let arrOfExtFiles: ExtFileInstance[] | undefined = let arrOfExtFiles: ExtFileInstance[] | undefined =
ExtFileManager.getExtFileInstanceList(dropzoneId); ExtFileManager.getExtFileInstanceList(dropzoneId);
console.log("value changed", isUploading, value.map(F => F.uploadStatus)); console.log("value changed", isUploading, value.map(F => F.uploadStatus),dropzoneId);
// console.log("value changed", value.map(F => F.uploadStatus)); // console.log("value changed", value.map(F => F.uploadStatus));
if (!isUploading) { if (!isUploading) {
setLocalFiles(value); setLocalFiles(value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment