Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move progress event handler to inline
  • Loading branch information
regalijan committed Mar 26, 2024
1 parent c06375e commit 65d03b6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/routes/report.tsx
Expand Up @@ -168,11 +168,6 @@ export default function () {

setUploading(true);

const increaseProgress = (e: ProgressEvent) => {
bytesRead += e.loaded;
setFileProgress(Math.floor((bytesRead / totalSize) * 100));
};

for (let i = 0; i < upload_urls.length; i++) {
await new Promise((resolve) => {
const xhr = new XMLHttpRequest();
Expand All @@ -186,7 +181,12 @@ export default function () {
fileTypes[files[i].name.split(".").at(-1) as string],
);

xhr.upload.addEventListener("progress", increaseProgress);
xhr.upload.onprogress = (e) => {
if (!e.lengthComputable) return;

bytesRead += e.loaded;
setFileProgress(Math.floor((bytesRead / totalSize) * 100));
};
xhr.upload.onabort = () => {
shouldRecall = true;
setUploading(false);
Expand Down

0 comments on commit 65d03b6

Please sign in to comment.