Skip to content

Commit

Permalink
fix(external-source): disallow to select multiple files when multiple…
Browse files Browse the repository at this point in the history
… mode is off (#589)

Co-authored-by: nd0ut <[email protected]>
  • Loading branch information
nd0ut and nd0ut authored Jan 18, 2024
1 parent 503eaae commit d5c43cd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion blocks/ExternalSource/ExternalSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ExternalSource extends UploaderBlock {
activityCaption: '',
selectedList: [],
counter: 0,
multiple: false,
onDone: () => {
for (const message of this.$.selectedList) {
const url = this.extractUrlFromMessage(message);
Expand Down Expand Up @@ -87,6 +88,9 @@ export class ExternalSource extends UploaderBlock {
this.sub('selectedList', (list) => {
this.$.counter = list.length;
});
this.subConfigValue('multiple', (multiple) => {
this.$.multiple = multiple;
});
}

/**
Expand Down Expand Up @@ -122,7 +126,15 @@ export class ExternalSource extends UploaderBlock {
* @param {SelectedFileMessage} message
*/
async handleFileSelected(message) {
if (!this.$.multiple && this.$.selectedList.length) {
return;
}

this.$.selectedList = [...this.$.selectedList, message];

if (!this.$.multiple) {
this.$.onDone();
}
}

/** @private */
Expand Down Expand Up @@ -235,7 +247,7 @@ ExternalSource.template = /* HTML */ `
<div class="toolbar">
<button type="button" class="cancel-btn secondary-btn" set="onclick: onCancel" l10n="cancel"></button>
<div></div>
<div class="selected-counter"><span l10n="selected-count"></span>{{counter}}</div>
<div set="@hidden: !multiple" class="selected-counter"><span l10n="selected-count"></span>{{counter}}</div>
<button type="button" class="done-btn primary-btn" set="onclick: onDone; @disabled: !counter">
<lr-icon name="check"></lr-icon>
</button>
Expand Down

0 comments on commit d5c43cd

Please sign in to comment.