Skip to content

Commit

Permalink
Fix file upload progress update
Browse files Browse the repository at this point in the history
  • Loading branch information
minpeter committed Mar 30, 2024
1 parent dec10ab commit c243a64
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function MainPage() {

const UpLoad = async () => {
if (fileProps.files[0].filename !== '') {
setProgressValue(0);
setUploading(true);

const formdata = new FormData();
fileProps.files.map((file) => {
formdata.append('file', file.fileData);
Expand All @@ -94,24 +97,21 @@ export function MainPage() {
'X-Time-Limit': expireTimeBoolean ? expireTime : 180,
'X-Hidden': hideBoolean,
},
onUploadProgress(progress) {
setUploading(false);
onUploadProgress: (progress) => {
setProgressValue(Math.floor((progress.loaded / progress.total) * 100));
if (Math.floor((progress.loaded / progress.total) * 100) === 100) {
setProgressStateText('๋ฐฑ์—”๋“œ ์ฒ˜๋ฆฌ์ค‘');
}
},
})
.then(async (res) => {
setUploading(true);
toast.success('์—…๋กœ๋“œ ์„ฑ๊ณต!', {
duration: 3000,
icon: '๐ŸŽ‰',
});
navigate(`/dl/${res.data.folderId}`);
})
.catch((err) => {
setUploading(true);
if (err.response.status === 413) {
toast.error('ํŒŒ์ผ ์šฉ๋Ÿ‰์ด ๋„ˆ๋ฌด ํฝ๋‹ˆ๋‹ค.', {
duration: 3000,
Expand All @@ -130,6 +130,8 @@ export function MainPage() {
icon: '๐Ÿ”ฅ',
});
}

setUploading(false);
};

useEffect(() => {
Expand Down

0 comments on commit c243a64

Please sign in to comment.