uppy icon indicating copy to clipboard operation
uppy copied to clipboard

fix for totalProgress when files kept in state

Open mok419 opened this issue 11 months ago • 4 comments

Mentioned in my FR https://github.com/transloadit/uppy/issues/4992

This allows not being uploaded files kept in state to not affect the total progress!

mok419 avatar Mar 13 '24 20:03 mok419

Diff output files
diff --git a/packages/@uppy/core/lib/Uppy.js b/packages/@uppy/core/lib/Uppy.js
index c87d245..c72486d 100644
--- a/packages/@uppy/core/lib/Uppy.js
+++ b/packages/@uppy/core/lib/Uppy.js
@@ -727,7 +727,7 @@ export class Uppy {
   calculateTotalProgress() {
     const files = this.getFiles();
     const inProgress = files.filter(file => {
-      return file.progress.uploadStarted || file.progress.preprocess || file.progress.postprocess;
+      return !file.progress.uploadComplete || file.progress.preprocess || file.progress.postprocess;
     });
     if (inProgress.length === 0) {
       this.emit("progress", 0);

github-actions[bot] avatar Mar 13 '24 20:03 github-actions[bot]

I don't think this is something we want to do. It's a bit of an XY problem, this is feedback on the attempted solution rather than the problem. What I think you want is actually some sort of media library, which has been requested often, to browse already uploaded files and upload new files to it. That's a problem which can be solved in many ways, and certainly involves rethinking the UX and the logic we have, not a single line of code.

Furthermore this small change has the potential to break a lot of edge cases.

If that's true, it's better to take a step back and solve this properly. What do you think?

Murderlon avatar Mar 14 '24 08:03 Murderlon

I totally agree, I wanted feedback from the team on what I was trying to achieve and how it fits into the current state of the package!

I created this PR as Uppy is suggesting we can keep files in state by setting uploadStarted and uploadCompleted, and this PR fits into that suggestion - as people who use this solution will need to alter the package to keep track of the TotalProgress of a current upload! So it wasn't purely for my use case but also for anyone using the package and keeping files not currently uploading in state!

mok419 avatar Mar 14 '24 16:03 mok419

I just had an idea, don't have the chance to test right now, but what if In addition to setting uploadStarted and uploadCompleted true, I set the progress as 100 too? Then totalProgress would think those "in-state" uploads are definitely completed.

Will test when I have a chance!

mok419 avatar Mar 18 '24 18:03 mok419