1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import { autorun, observable, reaction } from 'mobx';
import moment from 'moment';
import DelayAppComponent from './Component';
import { DEFAULT_FEATURES_CONFIG } from '../../config';
import { gaEvent, gaPage } from '../../lib/analytics';
const debug = require('debug')('Franz:feature:delayApp');
export const config = {
delayOffset: DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.delayOffset,
delayDuration: DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.wait,
};
export const state = observable({
isDelayAppScreenVisible: DEFAULT_FEATURES_CONFIG.needToWaitToProceed,
});
function setVisibility(value) {
Object.assign(state, {
isDelayAppScreenVisible: value,
});
}
export default function init(stores) {
debug('Initializing `delayApp` feature');
let shownAfterLaunch = false;
let timeLastDelay = moment();
window.franz.features.delayApp = {
state,
};
reaction(
() => stores.user.isLoggedIn && stores.features.features.needToWaitToProceed && !stores.user.data.isPremium,
(isEnabled) => {
if (isEnabled) {
debug('Enabling `delayApp` feature');
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.services.all.length === 0) {
shownAfterLaunch = true;
return;
}
const diff = moment().diff(timeLastDelay);
if ((stores.app.isFocused && diff >= config.delayOffset) || !shownAfterLaunch) {
debug(`App will be delayed for ${config.delayDuration / 1000}s`);
setVisibility(true);
gaPage('/delayApp');
gaEvent('DelayApp', 'show', 'Delay App Feature');
timeLastDelay = moment();
shownAfterLaunch = true;
setTimeout(() => {
debug('Resetting app delay');
setVisibility(false);
}, DEFAULT_FEATURES_CONFIG.needToWaitToProceedConfig.wait + 1000); // timer needs to be able to hit 0
}
});
} else {
setVisibility(false);
}
},
);
}
export const Component = DelayAppComponent;
|