Merge pull request #4702 from Vito0912/feat/uploadProgress
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Run Component Tests / Run Component Tests (push) Has been cancelled
Build and Push Docker Image / build (push) Has been cancelled
Integration Test / build and test (push) Has been cancelled
Run Unit Tests / Run Unit Tests (push) Has been cancelled

feat: Added progress indicator to upload
This commit is contained in:
advplyr 2025-11-24 17:08:03 -06:00 committed by GitHub
commit 8758c62ae2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 76 additions and 5 deletions

View file

@ -297,6 +297,15 @@ export default {
ref.setUploadStatus(status)
}
},
updateItemCardProgress(index, progress) {
var ref = this.$refs[`itemCard-${index}`]
if (ref && ref.length) ref = ref[0]
if (!ref) {
console.error('Book card ref not found', index, this.$refs)
} else {
ref.setUploadProgress(progress)
}
},
async uploadItem(item) {
var form = new FormData()
form.set('title', item.title)
@ -312,8 +321,20 @@ export default {
form.set(`${index++}`, file)
})
const config = {
onUploadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const progress = {
loaded: progressEvent.loaded,
total: progressEvent.total
}
this.updateItemCardProgress(item.index, progress)
}
}
}
return this.$axios
.$post('/api/upload', form)
.$post('/api/upload', form, config)
.then(() => true)
.catch((error) => {
console.error('Failed to upload item', error)