aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/announcements/index.js
blob: 5ea74e0af28021fada49394c5d534257a36f21fe (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
import { reaction, runInAction } from 'mobx';
import { AnnouncementsStore } from './store';
import api from './api';
import state, { resetState } from './state';

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

let store = null;

export default function initAnnouncements(stores, actions) {
  // const { features } = stores;

  // Toggle workspace feature
  reaction(
    () => (
      true
      // features.features.isAnnouncementsEnabled
    ),
    (isEnabled) => {
      if (isEnabled) {
        debug('Initializing `announcements` feature');
        store = new AnnouncementsStore(stores, api, actions, state);
        store.initialize();
        runInAction(() => { state.isFeatureActive = true; });
      } else if (store) {
        debug('Disabling `announcements` feature');
        runInAction(() => { state.isFeatureActive = false; });
        store.teardown();
        store = null;
        resetState(); // Reset state to default
      }
    },
    {
      fireImmediately: true,
    },
  );
}