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) => {
style,
textColor,
validator,
value,
value = [],
uploadConfig,
backgroundColor,
disableRipple,
......
......@@ -9,7 +9,7 @@ import {
fakeFuiUpload,
fileListToExtFileArray,
FileValidatorProps,
FunctionLabel,
//FunctionLabel,
handleClickInput,
instantPreparingToUploadOne,
isValidateActive,
......@@ -18,7 +18,8 @@ import {
sleepTransition,
toUploadableExtFileList,
UploadConfig,
uploadOnePromiseXHR,
uploadExtFile,
//uploadOnePromiseXHR,
UploadResponse,
validateExtFileList,
} from "../../core";
......@@ -42,7 +43,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
uploadConfig,
onChange,
behaviour,
value,
value = [],
localization,
disabled,
onUploadFinish,
......@@ -88,6 +89,17 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
//state for managing the number of valid files
//state for managing the files locally
console.table({
inputButtonId,
value,
isUploading,
maxFileSize,
accept,
maxFiles,
validator,
localization,
validateFilesFlag,
});
const [localFiles, numberOfValidFiles, setLocalFiles]: [
ExtFile[],
number,
......@@ -183,7 +195,7 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
// workaround for preventing getting the uploadStatus as undefined
/* arrOfExtFilesInstances.forEach((F) => {
F.uploadStatus = "preparing";
}); */
}); */
//variable for storing responses
//console.log("uploadfiles after sleep response",response);
console.log("FileManagerLog after sleep", arrOfExtFilesInstances);
......@@ -210,20 +222,43 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
//UPLOADING => UPLOAD()
//upload one file and notify about change
const uploadResponse: UploadResponse = fakeUpload
? await fakeFuiUpload(currentExtFileInstance, DropzoneLocalizer)
: await uploadOnePromiseXHR(
currentExtFileInstance,
url,
method,
headers,
uploadLabel
);
let uploadResponse: UploadResponse;
try {
uploadResponse = fakeUpload
? await fakeFuiUpload(currentExtFileInstance, DropzoneLocalizer)
: await uploadExtFile(
currentExtFileInstance,
url,
method,
headers,
uploadLabel
);
} catch (error) {
uploadResponse = {
id: currentExtFileInstance.id,
serverResponse: {
success: false,
message: "Error on upload: unexpected error " + error,
payload: {},
},
uploadedFile: { ...currentExtFileInstance },
};
}
const { uploadedFile } = uploadResponse;
//update instances
currentExtFileInstance.uploadStatus = uploadedFile.uploadStatus;
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
if (!(currentExtFileInstance.uploadStatus === "aborted"))
await sleepTransition();
......@@ -244,10 +279,10 @@ const FileInputButton: React.FC<FileInputButtonProps> = (
// upload group finished :D
onUploadFinish?.(serverResponses);
const finishUploadMessenger: FunctionLabel =
/* const finishUploadMessenger: FunctionLabel =
DropzoneLocalizer.uploadFinished as FunctionLabel;
/* setLocalMessage(
setLocalMessage(
finishUploadMessenger(missingUpload - totalRejected, totalRejected)
); */
setIsUploading(false);
......
......@@ -35,7 +35,7 @@ const useDropzoneFileListUpdater = (
React.useEffect(() => {
let arrOfExtFiles: ExtFileInstance[] | undefined =
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));
if (!isUploading) {
setLocalFiles(value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment