From 08c40f00de99f2e49f07106c241110f7afa71f6c Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Wed, 9 Jan 2019 15:39:45 +0100 Subject: [PATCH] fix(App): Fix app delay for Premium Supporters --- src/containers/settings/AccountScreen.js | 8 ++++++++ src/features/delayApp/index.js | 26 ++++++++++-------------- src/stores/FeaturesStore.js | 9 +++++++- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/containers/settings/AccountScreen.js b/src/containers/settings/AccountScreen.js index 019b3d7d6..d681d5226 100644 --- a/src/containers/settings/AccountScreen.js +++ b/src/containers/settings/AccountScreen.js @@ -14,6 +14,14 @@ import ErrorBoundary from '../../components/util/ErrorBoundary'; const { BrowserWindow } = remote; export default @inject('stores', 'actions') @observer class AccountScreen extends Component { + componentWillMount() { + const { + user, + } = this.props.stores; + + user.getUserInfoRequest.invalidate({ immediately: true }); + } + componentDidMount() { gaPage('Settings/Account Dashboard'); } diff --git a/src/features/delayApp/index.js b/src/features/delayApp/index.js index d7e8252f3..28aa50eb2 100644 --- a/src/features/delayApp/index.js +++ b/src/features/delayApp/index.js @@ -23,29 +23,23 @@ function setVisibility(value) { } export default function init(stores) { - reaction( - () => stores.features.features.needToWaitToProceed, - (enabled, r) => { - if (enabled) { - debug('Initializing `delayApp` feature'); + debug('Initializing `delayApp` feature'); - // Dispose the reaction to run this only once - r.dispose(); + let shownAfterLaunch = false; + let timeLastDelay = moment(); - const { needToWaitToProceedConfig: globalConfig } = stores.features.features; + reaction( + () => stores.features.features.needToWaitToProceed && !stores.user.data.isPremium, + (isEnabled) => { + if (isEnabled) { + debug('Enabling `delayApp` feature'); - let shownAfterLaunch = false; - let timeLastDelay = moment(); + const { needToWaitToProceedConfig: globalConfig } = stores.features.features; config.delayOffset = globalConfig.delayOffset !== undefined ? globalConfig.delayOffset : DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.delayOffset; config.delayDuration = globalConfig.wait !== undefined ? globalConfig.wait : DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.wait; autorun(() => { - if (stores.user.data.isPremium) { - debug('Skipping app delay as user is Premium Supporter'); - return; - } - if (stores.services.all.length === 0) { shownAfterLaunch = true; return; @@ -68,6 +62,8 @@ export default function init(stores) { }, DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.wait + 1000); // timer needs to be able to hit 0 } }); + } else { + setVisibility(false); } }, ); diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js index 2eccf87ee..0adee6adf 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js @@ -1,4 +1,4 @@ -import { computed, observable } from 'mobx'; +import { computed, observable, reaction } from 'mobx'; import Store from './lib/Store'; import CachedRequest from './lib/CachedRequest'; @@ -22,6 +22,13 @@ export default class FeaturesStore extends Store { await this.featuresRequest._promise; setTimeout(this._enableFeatures.bind(this), 1); + + // single key reaction + reaction(() => this.stores.user.data.isPremium, () => { + if (this.stores.user.isLoggedIn) { + this.featuresRequest.invalidate({ immediately: true }); + } + }); } @computed get anonymousFeatures() {