Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(App): Fix app delay for Premium Supporters
  • Loading branch information
adlk committed Jan 9, 2019
1 parent eee1fe6 commit 08c40f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/containers/settings/AccountScreen.js
Expand Up @@ -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');
}
Expand Down
26 changes: 11 additions & 15 deletions src/features/delayApp/index.js
Expand Up @@ -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;
Expand All @@ -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);
}
},
);
Expand Down
9 changes: 8 additions & 1 deletion 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';
Expand All @@ -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() {
Expand Down

0 comments on commit 08c40f0

Please sign in to comment.