Multiple images can now be selected in file chooser and drag/drop
This commit is contained in:
parent
f69a0b45bf
commit
1e4b562922
4 changed files with 18 additions and 28 deletions
|
@ -561,11 +561,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"maxOneAttachmentToast": {
|
||||
"message": "The limit is one attachment per message.",
|
||||
"description":
|
||||
"An error popup when the user has attempted to add an attachment"
|
||||
},
|
||||
"oneNonImageAtATimeToast": {
|
||||
"message":
|
||||
"When including a non-image attachment, the limit is one attachment per message.",
|
||||
|
|
|
@ -132,7 +132,7 @@
|
|||
</div>
|
||||
<div class='choose-file'>
|
||||
<button class='paperclip thumbnail'></button>
|
||||
<input type='file' class='file-input'>
|
||||
<input type='file' class='file-input' multiple='multiple'>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -288,9 +288,15 @@
|
|||
},
|
||||
async onChoseAttachment() {
|
||||
const fileField = this.$('input.file-input');
|
||||
const file = fileField.prop('files')[0];
|
||||
await this.fileInput.maybeAddAttachment(file);
|
||||
this.toggleMicrophone();
|
||||
const files = fileField.prop('files');
|
||||
|
||||
for (let i = 0, max = files.length; i < max; i += 1) {
|
||||
const file = files[i];
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.fileInput.maybeAddAttachment(file);
|
||||
this.toggleMicrophone();
|
||||
}
|
||||
|
||||
fileField.val(null);
|
||||
},
|
||||
|
||||
|
|
|
@ -42,9 +42,6 @@
|
|||
Whisper.MaxAttachmentsToast = Whisper.ToastView.extend({
|
||||
template: i18n('maximumAttachments'),
|
||||
});
|
||||
Whisper.MaxOneAttachmentToast = Whisper.ToastView.extend({
|
||||
template: i18n('maxOneAttachmentToast'),
|
||||
});
|
||||
|
||||
Whisper.FileInputView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
@ -155,7 +152,7 @@
|
|||
this.$el.removeClass('dropoff');
|
||||
},
|
||||
|
||||
onDrop(e) {
|
||||
async onDrop(e) {
|
||||
if (e.originalEvent.dataTransfer.types[0] !== 'Files') {
|
||||
return;
|
||||
}
|
||||
|
@ -163,9 +160,13 @@
|
|||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
const file = e.originalEvent.dataTransfer.files[0];
|
||||
this.maybeAddAttachment(file);
|
||||
const { files } = e.originalEvent.dataTransfer;
|
||||
for (let i = 0, max = files.length; i < max; i += 1) {
|
||||
const file = files[i];
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await this.maybeAddAttachment(file);
|
||||
}
|
||||
|
||||
this.$el.removeClass('dropoff');
|
||||
},
|
||||
|
||||
|
@ -255,12 +256,6 @@
|
|||
toast.render();
|
||||
},
|
||||
|
||||
showMaxOneAttachmentError() {
|
||||
const toast = new Whisper.MaxOneAttachmentToast();
|
||||
toast.$el.insertAfter(this.$el);
|
||||
toast.render();
|
||||
},
|
||||
|
||||
// Housekeeping
|
||||
|
||||
addAttachment(attachment) {
|
||||
|
@ -280,12 +275,6 @@
|
|||
const fileName = file.name;
|
||||
const contentType = file.type;
|
||||
|
||||
// TODO: remove this when clients are ready to remove multiple image attachments
|
||||
// if (this.attachments.length > 0) {
|
||||
// this.showMaxOneAttachmentError();
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (window.Signal.Util.isFileDangerous(fileName)) {
|
||||
this.showDangerousError();
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue