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

[WIP]: Improving the upload feature. ALlows delete, cancel and abort. However,...

[WIP]: Improving the upload feature. ALlows delete, cancel and abort. However, there are unecxpected result like sometime the uploading file is uploaded but the status remains in 'uploading' in 100%.
parent 040e31f7
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ import { ...@@ -24,6 +24,7 @@ import {
toUploadableExtFileList, toUploadableExtFileList,
cleanInput, cleanInput,
isUploadAbleExtFile, isUploadAbleExtFile,
sanitizeArrExtFile,
} from "../../../../core"; } from "../../../../core";
import { mergeProps } from "../../../overridable"; import { mergeProps } from "../../../overridable";
import InputHidden from "../../../input-hidden/InputHidden"; import InputHidden from "../../../input-hidden/InputHidden";
...@@ -223,7 +224,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -223,7 +224,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
dropzoneId, dropzoneId,
localFiles, localFiles,
validateFilesFlag as boolean, validateFilesFlag as boolean,
cleanOnUpload as boolean, cleanOnUpload as boolean
) || []; ) || [];
const newExtFileLocal: ExtFile[] = [...arrOfExtFilesInstances].map((x) => const newExtFileLocal: ExtFile[] = [...arrOfExtFilesInstances].map((x) =>
...@@ -252,20 +253,27 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -252,20 +253,27 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
//Uplad files one by one //Uplad files one by one
for (let i = 0; i < arrOfExtFilesInstances.length; i++) { for (let i = 0; i < arrOfExtFilesInstances.length; i++) {
const currentExtFileInstance: ExtFileInstance = arrOfExtFilesInstances[i]; const currentExtFileInstance: ExtFileInstance = arrOfExtFilesInstances[i];
console.log( console.log(
"FileManagerLog currentExtFileInstance " + i, "FileManagerLog currentExtFileInstance " + i,
currentExtFileInstance currentExtFileInstance
); );
if (currentExtFileInstance.uploadStatus === "preparing") { if (
currentExtFileInstance.uploadStatus === "preparing" &&
!currentExtFileInstance.extraData?.deleted
) {
//set stage to "uploading" in one file and notify change //set stage to "uploading" in one file and notify change
// PREPARING => UPLOADING // PREPARING => UPLOADING
await sleepTransition();
instantPreparingToUploadOne(currentExtFileInstance); instantPreparingToUploadOne(currentExtFileInstance);
setLocalMessage( setLocalMessage(
uploadingMessenger(`${++currentCountUpload}/${missingUpload}`) uploadingMessenger(`${++currentCountUpload}/${missingUpload}`)
); );
//CHANGE //CHANGE
handleFilesChange([...arrOfExtFilesInstances], true); handleFilesChange(sanitizeArrExtFile(arrOfExtFilesInstances), true);
//UPLOADING => UPLOAD() //UPLOADING => UPLOAD()
//upload one file and notify about change //upload one file and notify about change
...@@ -310,19 +318,20 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -310,19 +318,20 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
if (!(currentExtFileInstance.uploadStatus === "aborted")) if (!(currentExtFileInstance.uploadStatus === "aborted"))
await sleepTransition(); await sleepTransition();
const newExtFileList: ExtFile[] = arrOfExtFilesInstances.map( handleFilesChange(sanitizeArrExtFile(arrOfExtFilesInstances), true);
(x: ExtFileInstance) => x.toExtFile()
);
handleFilesChange(newExtFileList, true);
if (uploadedFile.uploadStatus === "error") { if (uploadedFile.uploadStatus === "error") {
totalRejected++; totalRejected++;
} }
serverResponses.push(uploadResponse); serverResponses.push(uploadResponse);
}else{
handleFilesChange(sanitizeArrExtFile(arrOfExtFilesInstances), true);
} }
} }
handleFilesChange(sanitizeArrExtFile(arrOfExtFilesInstances), true);
// upload group finished :D // upload group finished :D
onUploadFinish?.(serverResponses); onUploadFinish?.(serverResponses);
...@@ -335,15 +344,18 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => { ...@@ -335,15 +344,18 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
}; };
const handleAbortUpload = () => { const handleAbortUpload = () => {
const listExtFileLocal: ExtFileInstance[] | undefined = const listExtFileLocal: ExtFileInstance[] | undefined =
ExtFileManager.getExtFileInstanceList(dropzoneId); ExtFileManager.getExtFileInstanceList(dropzoneId);
console.log("Aborting", listExtFileLocal, dropzoneId); console.log("Aborting", listExtFileLocal, dropzoneId);
if (!listExtFileLocal) return; if (!listExtFileLocal) return;
listExtFileLocal.forEach((extFileInstance) => { listExtFileLocal.forEach((extFileInstance: ExtFileInstance) => {
console.log("Aborting extFileInstance",extFileInstance.xhr); if (extFileInstance.uploadStatus === "uploading") {
extFileInstance.xhr?.abort(); if (extFileInstance.xhr !== null && extFileInstance.xhr !== undefined)
extFileInstance.xhr.abort();
}
extFileInstance.uploadStatus = "aborted";
//console.log("Aborting extFileInstance", extFileInstance.xhr);
}); });
}; };
......
...@@ -19,7 +19,6 @@ import { ...@@ -19,7 +19,6 @@ import {
toUploadableExtFileList, toUploadableExtFileList,
UploadConfig, UploadConfig,
uploadExtFile, uploadExtFile,
//uploadOnePromiseXHR,
UploadResponse, UploadResponse,
validateExtFileList, validateExtFileList,
} from "../../core"; } from "../../core";
......
...@@ -42,8 +42,33 @@ const useDropzoneFileListUpdater = ( ...@@ -42,8 +42,33 @@ const useDropzoneFileListUpdater = (
} else { } else {
// when is uploading // when is uploading
if (arrOfExtFiles) { if (arrOfExtFiles) {
//lenght of the new arr can be equal or lower
//when lower, it means a file was deleted, it will be removed only if was not uploaded
//when same lenght it means that a file could be
if (arrOfExtFiles.length !== value.length || value.length === 0) { //no mather the size, it will search for the missing and the status that changed
arrOfExtFiles.forEach((extFileInstance: ExtFileInstance) => {
//if the current Ext file is not present anymore
//add deleted flag
const extFileIndex: number = value.findIndex((extFile: ExtFile) => extFile.id === extFileInstance.id)
if (extFileIndex === -1) {
extFileInstance.extraData = { deleted: true }
console.log("extFileUpdater not found", extFileInstance.id);
} else {
extFileInstance.uploadStatus = value[extFileIndex].uploadStatus;
extFileInstance.uploadMessage = value[extFileIndex].uploadMessage;
if (value[extFileIndex].uploadStatus === undefined) {
console.log("extFileUpdater canceled", extFileInstance.id);
} else if (value[extFileIndex].uploadStatus === "aborted") {
console.log("extFileUpdater aborted", extFileInstance.id);
}
}
})
/* if (arrOfExtFiles.length !== value.length || value.length === 0) {
return; return;
} }
for (let i = 0; i < arrOfExtFiles.length; i++) { for (let i = 0; i < arrOfExtFiles.length; i++) {
...@@ -55,7 +80,7 @@ const useDropzoneFileListUpdater = ( ...@@ -55,7 +80,7 @@ const useDropzoneFileListUpdater = (
console.log("useDropzoneFileListUpdater onCancel i", i); console.log("useDropzoneFileListUpdater onCancel i", i);
arrOfExtFiles[i].uploadStatus = undefined; arrOfExtFiles[i].uploadStatus = undefined;
} }
} } */
} }
} }
// eslint-disable-next-line // eslint-disable-next-line
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment