Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2022-03-30 14:17:55 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-03-30 14:20:35 +0300
commit2942e049c9af66b92effa5f193fca3147b919d34 (patch)
tree11e262248d79203e9a0f60ea16d1665cd028bf6b /src
parent63e64d2c36378022911100c6dd7e93846d4dab43 (diff)
use promises to handle multiple simultaneous uploads
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'src')
-rw-r--r--src/components/EditorWrapper.vue33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/components/EditorWrapper.vue b/src/components/EditorWrapper.vue
index e589b2219..3af227686 100644
--- a/src/components/EditorWrapper.vue
+++ b/src/components/EditorWrapper.vue
@@ -50,7 +50,7 @@
:is-public="isPublic"
:autohide="autohide"
:loaded.sync="menubarLoaded"
- :uploading-image="nbUploadingImages > 0"
+ :uploading-image="uploadingImages"
@show-help="showHelp"
@image-insert="insertImagePath"
@image-upload="uploadImageFiles">
@@ -108,7 +108,7 @@ import { Step } from 'prosemirror-transform'
const EDITOR_PUSH_DEBOUNCE = 200
-const imageMimes = [
+const IMAGE_MIMES = [
'image/png',
'image/jpeg',
'image/jpg',
@@ -200,7 +200,7 @@ export default {
readOnly: true,
forceRecreate: false,
menubarLoaded: false,
- nbUploadingImages: 0,
+ uploadingImages: false,
draggedOver: false,
saveStatusPolling: null,
@@ -571,37 +571,38 @@ export default {
this.draggedOver = false
},
uploadImageFiles(files) {
- if (files) {
- files.forEach((file) => {
- this.uploadImageFile(file)
- })
+ if (!files) {
+ return
}
+ this.uploadingImages = true
+ const uploadPromises = [...files].map((file) => {
+ return this.uploadImageFile(file)
+ })
+ Promise.all(uploadPromises).then((values) => {
+ this.uploadingImages = false
+ })
},
- uploadImageFile(file) {
- if (!imageMimes.includes(file.type)) {
+ async uploadImageFile(file) {
+ if (!IMAGE_MIMES.includes(file.type)) {
showError(t('text', 'Image file format not supported'))
- return
}
- this.nbUploadingImages++
- this.syncService.uploadImage(file).then((response) => {
+ return this.syncService.uploadImage(file).then((response) => {
this.insertAttachmentImage(response.data?.name, response.data?.id)
}).catch((error) => {
console.error(error)
showError(error?.response?.data?.error)
- }).then(() => {
- this.nbUploadingImages--
})
},
insertImagePath(imagePath) {
- this.nbUploadingImages++
+ this.uploadingImages = true
this.syncService.insertImageFile(imagePath).then((response) => {
this.insertAttachmentImage(response.data?.name, response.data?.id)
}).catch((error) => {
console.error(error)
showError(error?.response?.data?.error)
}).then(() => {
- this.nbUploadingImages--
+ this.uploadingImages = false
})
},
insertAttachmentImage(name, fileId) {