From 8e2b117321a56f9cf647ce67fe43ad2feaef28ca Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 15 Nov 2023 14:28:54 +0000 Subject: [PATCH] make subscription update happen asynchronously on FE --- .../components/wizard-subscription-badge.hbs | 1 + .../components/wizard-subscription-badge.js | 31 ++++++------------- .../discourse/services/subscription.js | 22 ++++++------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-subscription-badge.hbs b/assets/javascripts/discourse/components/wizard-subscription-badge.hbs index fb5becfa..6ef0c754 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-badge.hbs +++ b/assets/javascripts/discourse/components/wizard-subscription-badge.hbs @@ -2,6 +2,7 @@ @action={{this.click}} class="wizard-subscription-badge {{this.subscription.subscriptionType}}" @title={{this.title}} + {{did-insert this.update}} > { - // if (this.subscription.subscribed) { - // this.updateIcon = "check"; - // } else { - // this.updateIcon = "times"; - // } - // }) - // .catch(popupAjaxError) - // .finally(() => { - // this.updating = false; - // setTimeout(() => { - // this.updateIcon = null; - // }, 7000); - // }); + this.updating = true; + this.updateIcon = "check"; + this.subscription.retrieveSubscriptionStatus().finally(() => { + this.updating = false; + setTimeout(() => { + this.updateIcon = null; + }, 5000); + }) } -} +} \ No newline at end of file diff --git a/assets/javascripts/discourse/services/subscription.js b/assets/javascripts/discourse/services/subscription.js index b939210e..42f2afca 100644 --- a/assets/javascripts/discourse/services/subscription.js +++ b/assets/javascripts/discourse/services/subscription.js @@ -23,19 +23,15 @@ export default class SubscriptionService extends Service { this.retrieveSubscriptionStatus(); } - retrieveSubscriptionStatus() { - debugger; - ajax("/admin/wizards/subscription") - .then((result) => { - debugger; - this.subscribed = result.subscribed; - this.subscriptionType = result.subscription_type; - this.subscriptionAttributes = result.subscription_attributes; - this.businessSubscription = this.subscriptionType === "business"; - this.communitySubscription = this.subscriptionType === "community"; - this.standardSubscription = this.subscriptionType === "standard"; - }) - .catch(popupAjaxError); + async retrieveSubscriptionStatus() { + let result = await ajax("/admin/wizards/subscription").catch(popupAjaxError); + + this.subscribed = result.subscribed; + this.subscriptionType = result.subscription_type; + this.subscriptionAttributes = result.subscription_attributes; + this.businessSubscription = this.subscriptionType === "business"; + this.communitySubscription = this.subscriptionType === "community"; + this.standardSubscription = this.subscriptionType === "standard"; } get subscriptionLink() {