Skip to content

Commit

Permalink
fix(init-flow): fix sync initFlow calls right after upload collecti…
Browse files Browse the repository at this point in the history
…on (#532)
  • Loading branch information
nd0ut authored Oct 6, 2023
1 parent c4a3c0c commit f4f4dea
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class ActivityBlock extends Block {
this.$['*currentActivity'] = nextActivity;
this.$['*history'] = history;
if (!nextActivity) {
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', false);
this.setOrAddState('*modalActive', false);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions abstract/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ export class Block extends BaseComponent {
}

/**
* @param {String} consumerScope
* @param {String} prop
* @param {any} newVal
*/
setForCtxTarget(consumerScope, prop, newVal) {
if (this.hasBlockInCtx((b) => /** @type {typeof Block} */ (b.constructor).StateConsumerScope === consumerScope)) {
this.$[prop] = newVal;
}
setOrAddState(prop, newVal) {
this.add$(
{
[prop]: newVal,
},
true
);
}

/** @param {String} activityType */
Expand Down
12 changes: 6 additions & 6 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class UploaderBlock extends ActivityBlock {
[...this.fileInput['files']].forEach((file) => this.addFileFromObject(file, { source: UploadSource.LOCAL }));
// To call uploadTrigger UploadList should draw file items first:
this.$['*currentActivity'] = ActivityBlock.activities.UPLOAD_LIST;
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', true);
this.setOrAddState('*modalActive', true);
// @ts-ignore TODO: fix this
this.fileInput['value'] = '';
this.fileInput = null;
Expand All @@ -249,11 +249,11 @@ export class UploaderBlock extends ActivityBlock {

/** @param {Boolean} [force] */
initFlow(force = false) {
if (this.$['*uploadList']?.length && !force) {
if (this.uploadCollection.size > 0 && !force) {
this.set$({
'*currentActivity': ActivityBlock.activities.UPLOAD_LIST,
});
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', true);
this.setOrAddState('*modalActive', true);
} else {
if (this.sourceList?.length === 1) {
let srcKey = this.sourceList[0];
Expand All @@ -272,14 +272,14 @@ export class UploaderBlock extends ActivityBlock {
} else {
this.$['*currentActivity'] = srcKey;
}
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', true);
this.setOrAddState('*modalActive', true);
}
} else {
// Multiple sources case:
this.set$({
'*currentActivity': ActivityBlock.activities.START_FROM,
});
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', true);
this.setOrAddState('*modalActive', true);
}
}
EventManager.emit(
Expand All @@ -298,7 +298,7 @@ export class UploaderBlock extends ActivityBlock {
'*history': this.doneActivity ? [this.doneActivity] : [],
});
if (!this.$['*currentActivity']) {
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', false);
this.setOrAddState('*modalActive', false);
}
EventManager.emit(
new EventData({
Expand Down
2 changes: 1 addition & 1 deletion blocks/DropArea/DropArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class DropArea extends UploaderBlock {
this.set$({
'*currentActivity': ActivityBlock.activities.UPLOAD_LIST,
});
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', true);
this.setOrAddState('*modalActive', true);
}
},
});
Expand Down
2 changes: 1 addition & 1 deletion blocks/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Modal extends Block {
};

_closeDialog = () => {
this.setForCtxTarget(Modal.StateConsumerScope, '*modalActive', false);
this.setOrAddState('*modalActive', false);
};

_handleDialogClose = () => {
Expand Down
12 changes: 8 additions & 4 deletions blocks/UploadList/UploadList.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ export class UploadList extends UploaderBlock {
}
this._updateUploadsState();
this._updateCountLimitMessage();

if (
this.$['*uploadList']?.length === 0 &&
!this.cfg.showEmptyList &&
this.$['*currentActivity'] === this.activityType
) {
this.historyBack();
}
}, 0);

/**
Expand Down Expand Up @@ -223,10 +231,6 @@ export class UploadList extends UploaderBlock {
hasFiles: list.length > 0,
});

if (list?.length === 0 && !this.cfg.showEmptyList) {
this.historyBack();
}

if (!this.cfg.confirmUpload) {
this.add$(
{
Expand Down

0 comments on commit f4f4dea

Please sign in to comment.