0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Attempted fix of portal background flash going from nobody->anybody/invite

no issue

- dropped use of `@guid` tracked param in favour of adding query param to URL in `updatePortalPreview()` and making sure we only update it when necessary
This commit is contained in:
Kevin Ansfield 2021-05-24 19:29:18 +01:00
parent 28de12c7eb
commit 2bd118eef9
2 changed files with 21 additions and 15 deletions

View file

@ -36,7 +36,8 @@ export default class MembersAccessController extends Controller {
@tracked stripePlanError = ''; @tracked stripePlanError = '';
@tracked portalPreviewUrl = ''; @tracked portalPreviewUrl = '';
@tracked portalPreviewGuid = Date.now().valueOf();
portalPreviewGuid = Date.now().valueOf();
queryParams = ['showPortalSettings']; queryParams = ['showPortalSettings'];
@ -110,9 +111,7 @@ export default class MembersAccessController extends Controller {
// when saved value is 'none' the server won't inject the portal script // when saved value is 'none' the server won't inject the portal script
// to work around that and show the expected portal preview we save and // to work around that and show the expected portal preview we save and
// force a refresh // force a refresh
await this.saveSettingsTask.perform(); await this.saveSettingsTask.perform({forceRefresh: true});
this.updatePortalPreview();
this.portalPreviewGuid = Date.now().valueOf();
} else { } else {
this.updatePortalPreview(); this.updatePortalPreview();
} }
@ -145,7 +144,7 @@ export default class MembersAccessController extends Controller {
} }
@action @action
validateStripePlans() { validateStripePlans({updatePortalPreview = true} = {}) {
this.stripePlanError = undefined; this.stripePlanError = undefined;
try { try {
@ -156,7 +155,9 @@ export default class MembersAccessController extends Controller {
throw new TypeError(`Subscription amount must be at least ${symbol}1.00`); throw new TypeError(`Subscription amount must be at least ${symbol}1.00`);
} }
this.updatePortalPreview(); if (updatePortalPreview) {
this.updatePortalPreview();
}
} catch (err) { } catch (err) {
this.stripePlanError = err.message; this.stripePlanError = err.message;
} }
@ -171,8 +172,7 @@ export default class MembersAccessController extends Controller {
@action @action
async closeStripeConnect() { async closeStripeConnect() {
if (this.stripeEnabledOnOpen !== this.membersUtils.isStripeEnabled) { if (this.stripeEnabledOnOpen !== this.membersUtils.isStripeEnabled) {
await this.saveSettingsTask.perform(); await this.saveSettingsTask.perform({forceRefresh: true});
this.portalPreviewGuid = Date.now().valueOf();
} }
this.showStripeConnect = false; this.showStripeConnect = false;
} }
@ -208,7 +208,7 @@ export default class MembersAccessController extends Controller {
} }
@action @action
updatePortalPreview() { updatePortalPreview({forceRefresh} = {}) {
// TODO: can these be worked out from settings in membersUtils? // TODO: can these be worked out from settings in membersUtils?
const monthlyPrice = this.stripeMonthlyAmount * 100; const monthlyPrice = this.stripeMonthlyAmount * 100;
const yearlyPrice = this.stripeYearlyAmount * 100; const yearlyPrice = this.stripeYearlyAmount * 100;
@ -225,7 +225,7 @@ export default class MembersAccessController extends Controller {
isYearlyChecked = true; isYearlyChecked = true;
} }
this.portalPreviewUrl = this.membersUtils.getPortalPreviewUrl({ const newUrl = new URL(this.membersUtils.getPortalPreviewUrl({
button: false, button: false,
monthlyPrice, monthlyPrice,
yearlyPrice, yearlyPrice,
@ -233,7 +233,14 @@ export default class MembersAccessController extends Controller {
isMonthlyChecked, isMonthlyChecked,
isYearlyChecked, isYearlyChecked,
portalPlans: null portalPlans: null
}); }));
if (forceRefresh) {
this.portalPreviewGuid = Date.now().valueOf();
}
newUrl.searchParams.set('v', this.portalPreviewGuid);
this.portalPreviewUrl = newUrl;
this.resizePortalPreviewTask.perform(); this.resizePortalPreviewTask.perform();
} }
@ -393,8 +400,8 @@ export default class MembersAccessController extends Controller {
} }
@task({drop: true}) @task({drop: true})
*saveSettingsTask() { *saveSettingsTask(options) {
yield this.validateStripePlans(); yield this.validateStripePlans({updatePortalPreview: false});
if (this.stripePlanError) { if (this.stripePlanError) {
return; return;
@ -407,7 +414,7 @@ export default class MembersAccessController extends Controller {
yield this.saveProduct(); yield this.saveProduct();
const result = yield this.settings.save(); const result = yield this.settings.save();
this.updatePortalPreview(); this.updatePortalPreview(options);
return result; return result;
} }

View file

@ -58,7 +58,6 @@
<GhSiteIframe <GhSiteIframe
scrolling="no" scrolling="no"
@src={{this.portalPreviewUrl}} @src={{this.portalPreviewUrl}}
@guid={{this.portalPreviewGuid}}
@invisibleUntilLoaded="portal-ready" @invisibleUntilLoaded="portal-ready"
@onLoad={{this.portalPreviewLoaded}} @onLoad={{this.portalPreviewLoaded}}
@onDestroyed={{this.portalPreviewDestroyed}} /> @onDestroyed={{this.portalPreviewDestroyed}} />