aboutsummaryrefslogtreecommitdiff
path: root/src/components/media_upload/media_upload.js
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-06-08 18:22:17 +0200
committerlain <lain@soykaf.club>2020-06-08 18:22:17 +0200
commite45f7fe8772f538c6824718ec26067849bde34c6 (patch)
tree1dc37abba52751e92d38b917c6b69ad48ba9c667 /src/components/media_upload/media_upload.js
parente6a27bcaca57c4c6351f7c41c2892c4e5222829e (diff)
MediaUpload: Correctly handle multiple uploads.
Diffstat (limited to 'src/components/media_upload/media_upload.js')
-rw-r--r--src/components/media_upload/media_upload.js33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js
index 4568224b..16e47ef7 100644
--- a/src/components/media_upload/media_upload.js
+++ b/src/components/media_upload/media_upload.js
@@ -5,10 +5,15 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for
const mediaUpload = {
data () {
return {
- uploading: false,
+ uploadCount: 0,
uploadReady: true
}
},
+ computed: {
+ uploading () {
+ return this.uploadCount > 0
+ }
+ },
methods: {
uploadFile (file) {
const self = this
@@ -23,23 +28,27 @@ const mediaUpload = {
formData.append('file', file)
self.$emit('uploading')
- self.uploading = true
+ self.uploadCount++
statusPosterService.uploadMedia({ store, formData })
.then((fileData) => {
self.$emit('uploaded', fileData)
- self.uploading = false
+ self.decreaseUploadCount()
}, (error) => { // eslint-disable-line handle-callback-err
self.$emit('upload-failed', 'default')
- self.uploading = false
+ self.decreaseUploadCount()
})
},
+ decreaseUploadCount() {
+ this.uploadCount--
+ if (this.uploadCount === 0) {
+ this.$emit('all-uploaded')
+ }
+ },
fileDrop (e) {
if (e.dataTransfer.files.length > 0) {
e.preventDefault() // allow dropping text like before
- for (const file of e.dataTransfer.files) {
- this.uploadFile(file)
- }
+ this.multiUpload(e.dataTransfer.files)
}
},
fileDrag (e) {
@@ -56,11 +65,13 @@ const mediaUpload = {
this.uploadReady = true
})
},
- change ({ target }) {
- for (var i = 0; i < target.files.length; i++) {
- let file = target.files[i]
+ multiUpload (files) {
+ for (const file of files) {
this.uploadFile(file)
}
+ },
+ change ({ target }) {
+ this.multiUpload(target.files)
}
},
props: [
@@ -69,7 +80,7 @@ const mediaUpload = {
watch: {
'dropFiles': function (fileInfos) {
if (!this.uploading) {
- this.uploadFile(fileInfos[0])
+ this.multiUpload(fileInfos)
}
}
}