Skip to content

Commit 25cb2c3

Browse files
committed
OpenConceptLab/ocl_issues#2269 | removed httpbin and using setinterval to show progress bar
1 parent a9907db commit 25cb2c3

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

src/components/common/FileUploader.jsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,21 @@ const FileUploader = ({ maxFiles, accept, uploadButton, onUpload, onLoading, max
1515

1616
const onDrop = acceptedFiles => {
1717
setCanUpload(false);
18-
if(onLoading)
19-
onLoading()
18+
if (onLoading) onLoading();
2019

21-
const formData = new FormData();
22-
for (const file of acceptedFiles) formData.append('file', file);
20+
// Fake progress animation (0 → 100)
21+
let pct = 0;
22+
const interval = setInterval(() => {
23+
pct += 10;
24+
setProgress(pct);
2325

24-
const xhr = new XMLHttpRequest();
25-
xhr.upload.onprogress = event => {
26-
const percentage = parseInt((event.loaded / event.total) * 100);
27-
setProgress(percentage)
28-
if(percentage === 100)
29-
onUpload(acceptedFiles[0])
30-
};
31-
xhr.onreadystatechange = () => {
32-
if (xhr.readyState !== 4) return;
33-
if (xhr.status === 200) {
26+
if (pct >= 100) {
27+
clearInterval(interval);
3428
setCanUpload(true);
29+
onUpload(acceptedFiles[0]);
3530
}
36-
};
37-
xhr.open('POST', 'https://httpbin.org/post', true);
38-
xhr.send(formData);
39-
}
31+
}, 80);
32+
};
4033

4134
const {
4235
acceptedFiles, fileRejections, getRootProps, getInputProps

0 commit comments

Comments
 (0)