diff options
author | 2019-03-01 14:25:44 +0100 | |
---|---|---|
committer | 2019-03-01 14:25:44 +0100 | |
commit | 739ef2e8a2dec94c3e10c3d26d797fe759fac7aa (patch) | |
tree | 4a2e066bf8627249f803eee16ba8e73268127fbd /src/features/workspaces/index.js | |
parent | fixes merge conflicts with latest develop (diff) | |
download | ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.gz ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.zst ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.zip |
finish workspaces mvp
Diffstat (limited to 'src/features/workspaces/index.js')
-rw-r--r-- | src/features/workspaces/index.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/features/workspaces/index.js b/src/features/workspaces/index.js index 50ac3b414..8091f49fc 100644 --- a/src/features/workspaces/index.js +++ b/src/features/workspaces/index.js | |||
@@ -1,14 +1,28 @@ | |||
1 | import { reaction } from 'mobx'; | 1 | import { reaction, runInAction } from 'mobx'; |
2 | import WorkspacesStore from './store'; | 2 | import WorkspacesStore from './store'; |
3 | import api from './api'; | 3 | import api from './api'; |
4 | import { state, resetState } from './state'; | 4 | import { workspacesState, resetState } from './state'; |
5 | 5 | ||
6 | const debug = require('debug')('Franz:feature:workspaces'); | 6 | const debug = require('debug')('Franz:feature:workspaces'); |
7 | 7 | ||
8 | let store = null; | 8 | let store = null; |
9 | 9 | ||
10 | export const filterServicesByActiveWorkspace = (services) => { | ||
11 | const { isFeatureActive, activeWorkspace } = workspacesState; | ||
12 | if (isFeatureActive && activeWorkspace) { | ||
13 | return services.filter(s => activeWorkspace.services.includes(s.id)); | ||
14 | } | ||
15 | return services; | ||
16 | }; | ||
17 | |||
18 | export const getActiveWorkspaceServices = (services) => { | ||
19 | return filterServicesByActiveWorkspace(services); | ||
20 | }; | ||
21 | |||
10 | export default function initWorkspaces(stores, actions) { | 22 | export default function initWorkspaces(stores, actions) { |
11 | const { features, user } = stores; | 23 | const { features, user } = stores; |
24 | |||
25 | // Toggle workspace feature | ||
12 | reaction( | 26 | reaction( |
13 | () => ( | 27 | () => ( |
14 | features.features.isWorkspaceEnabled && ( | 28 | features.features.isWorkspaceEnabled && ( |
@@ -18,10 +32,12 @@ export default function initWorkspaces(stores, actions) { | |||
18 | (isEnabled) => { | 32 | (isEnabled) => { |
19 | if (isEnabled) { | 33 | if (isEnabled) { |
20 | debug('Initializing `workspaces` feature'); | 34 | debug('Initializing `workspaces` feature'); |
21 | store = new WorkspacesStore(stores, api, actions, state); | 35 | store = new WorkspacesStore(stores, api, actions, workspacesState); |
22 | store.initialize(); | 36 | store.initialize(); |
37 | runInAction(() => { workspacesState.isFeatureActive = true; }); | ||
23 | } else if (store) { | 38 | } else if (store) { |
24 | debug('Disabling `workspaces` feature'); | 39 | debug('Disabling `workspaces` feature'); |
40 | runInAction(() => { workspacesState.isFeatureActive = false; }); | ||
25 | store.teardown(); | 41 | store.teardown(); |
26 | store = null; | 42 | store = null; |
27 | resetState(); // Reset state to default | 43 | resetState(); // Reset state to default |
@@ -31,4 +47,22 @@ export default function initWorkspaces(stores, actions) { | |||
31 | fireImmediately: true, | 47 | fireImmediately: true, |
32 | }, | 48 | }, |
33 | ); | 49 | ); |
50 | |||
51 | // Update active service on workspace switches | ||
52 | reaction(() => ({ | ||
53 | isFeatureActive: workspacesState.isFeatureActive, | ||
54 | activeWorkspace: workspacesState.activeWorkspace, | ||
55 | }), ({ isFeatureActive, activeWorkspace }) => { | ||
56 | if (!isFeatureActive) return; | ||
57 | if (activeWorkspace) { | ||
58 | const services = stores.services.allDisplayed; | ||
59 | const activeService = services.find(s => s.isActive); | ||
60 | const workspaceServices = filterServicesByActiveWorkspace(services); | ||
61 | const isActiveServiceInWorkspace = workspaceServices.includes(activeService); | ||
62 | if (!isActiveServiceInWorkspace) { | ||
63 | console.log(workspaceServices[0].id); | ||
64 | actions.service.setActive({ serviceId: workspaceServices[0].id }); | ||
65 | } | ||
66 | } | ||
67 | }); | ||
34 | } | 68 | } |