Skip to content

Commit

Permalink
feat: cancel promo timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
iapolya committed Jun 9, 2024
1 parent 1e0fb44 commit 1cf980b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/promo-manager/core/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,7 @@ export class Controller {
finishPromo = (slug: PromoSlug, updateProgressInfo = false, closeActiveTimeout = 0) => {
this.assertProgressLoaded();

if (this.isActive(slug)) {
if (closeActiveTimeout) {
setTimeout(() => {
this.clearActive();
}, closeActiveTimeout);
} else {
this.clearActive();
}
}
this.closeActivePromo(slug, closeActiveTimeout);

if (this.state.progress.finishedPromos.includes(slug)) {
return;
Expand All @@ -154,10 +146,8 @@ export class Controller {
this.triggerNextPromo();
};

cancelPromo = (slug: PromoSlug, updateProgressInfo = false) => {
if (this.isActive(slug)) {
this.clearActive();
}
cancelPromo = (slug: PromoSlug, updateProgressInfo = false, closeActiveTimeout = 0) => {
this.closeActivePromo(slug, closeActiveTimeout);

if (updateProgressInfo) {
this.updateProgressInfo(slug);
Expand Down Expand Up @@ -435,4 +425,16 @@ export class Controller {
listener();
}
};

private closeActivePromo = (slug: PromoSlug, timeout = 0) => {
if (this.isActive(slug)) {
if (timeout) {
setTimeout(() => {
this.clearActive();
}, timeout);
} else {
this.clearActive();
}
}
};
}

0 comments on commit 1cf980b

Please sign in to comment.