aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/shareFranz/index.js
blob: 87deacef43808436d3d54a223fd66bdba3040b35 (plain) (blame)
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
import { observable, reaction } from 'mobx';
import ms from 'ms';

import { state as delayAppState } from '../delayApp';
import { gaEvent, gaPage } from '../../lib/analytics';

export { default as Component } from './Component';

const debug = require('debug')('Franz:feature:shareFranz');

const defaultState = {
  isModalVisible: false,
  lastShown: null,
};

export const state = observable(defaultState);

export default function initialize(stores) {
  debug('Initialize shareFranz feature');

  window.franz.features.shareFranz = {
    state,
  };

  function showModal() {
    debug('Showing share window');

    state.isModalVisible = true;

    gaEvent('Share Franz', 'show');
    gaPage('/share-modal');
  }

  reaction(
    () => stores.user.isLoggedIn,
    () => {
      setTimeout(() => {
        if (stores.settings.stats.appStarts % 50 === 0) {
          if (delayAppState.isDelayAppScreenVisible) {
            debug('Delaying share modal by 5 minutes');
            setTimeout(() => showModal(), ms('5m'));
          } else {
            showModal();
          }
        }
      }, ms('2s'));
    },
    {
      fireImmediately: true,
    },
  );
}