aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/index.js
blob: 560b732abb99b15df3df42aa24ad189a29a7772f (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
import { reaction } from 'mobx';
import WorkspacesStore from './store';
import { resetApiRequests } from './api';

const debug = require('debug')('Ferdi:feature:workspaces');

export const GA_CATEGORY_WORKSPACES = 'Workspaces';
export const DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED = false;

export const workspaceStore = new WorkspacesStore();

export default function initWorkspaces(stores, actions) {
  stores.workspaces = workspaceStore;
  const { features } = stores;

  // Toggle workspace feature
  reaction(
    () => features.features.isWorkspaceEnabled,
    (isEnabled) => {
      if (isEnabled && !workspaceStore.isFeatureActive) {
        debug('Initializing `workspaces` feature');
        workspaceStore.start(stores, actions);
      } else if (workspaceStore.isFeatureActive) {
        debug('Disabling `workspaces` feature');
        workspaceStore.stop();
        resetApiRequests();
      }
    },
    {
      fireImmediately: true,
    },
  );
}

export const WORKSPACES_ROUTES = {
  ROOT: '/settings/workspaces',
  EDIT: '/settings/workspaces/:action/:id',
};