diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2018-12-10 17:15:37 +0100 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-02-12 13:35:31 +0100 |
commit | 4a537e890d95e8666985ce77df4c6327582332be (patch) | |
tree | b47dcd21e6b70de47ef45c882bbd0f55ce9aa603 /src | |
parent | ignore intellij project files (diff) | |
download | ferdium-app-4a537e890d95e8666985ce77df4c6327582332be.tar.gz ferdium-app-4a537e890d95e8666985ce77df4c6327582332be.tar.zst ferdium-app-4a537e890d95e8666985ce77df4c6327582332be.zip |
basic setup for workspaces feature
Diffstat (limited to 'src')
-rw-r--r-- | src/config.js | 1 | ||||
-rw-r--r-- | src/features/workspaces/api.js | 9 | ||||
-rw-r--r-- | src/features/workspaces/index.js | 34 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 29 | ||||
-rw-r--r-- | src/stores/FeaturesStore.js | 2 |
5 files changed, 75 insertions, 0 deletions
diff --git a/src/config.js b/src/config.js index 789ddd1a0..d7a485b8a 100644 --- a/src/config.js +++ b/src/config.js | |||
@@ -37,6 +37,7 @@ export const DEFAULT_FEATURES_CONFIG = { | |||
37 | }, | 37 | }, |
38 | isServiceProxyEnabled: false, | 38 | isServiceProxyEnabled: false, |
39 | isServiceProxyPremiumFeature: true, | 39 | isServiceProxyPremiumFeature: true, |
40 | isWorkspaceEnabled: true, | ||
40 | }; | 41 | }; |
41 | 42 | ||
42 | export const DEFAULT_WINDOW_OPTIONS = { | 43 | export const DEFAULT_WINDOW_OPTIONS = { |
diff --git a/src/features/workspaces/api.js b/src/features/workspaces/api.js new file mode 100644 index 000000000..1ee2440fe --- /dev/null +++ b/src/features/workspaces/api.js | |||
@@ -0,0 +1,9 @@ | |||
1 | // TODO: use real server instead | ||
2 | const workspaces = [ | ||
3 | { id: 'workspace-1', name: 'Private' }, | ||
4 | { id: 'workspace-2', name: 'Office' }, | ||
5 | ]; | ||
6 | |||
7 | export default { | ||
8 | getUserWorkspaces: () => Promise.resolve(workspaces), | ||
9 | }; | ||
diff --git a/src/features/workspaces/index.js b/src/features/workspaces/index.js new file mode 100644 index 000000000..b7e1090e8 --- /dev/null +++ b/src/features/workspaces/index.js | |||
@@ -0,0 +1,34 @@ | |||
1 | import { observable, reaction } from 'mobx'; | ||
2 | import { merge } from 'lodash'; | ||
3 | import WorkspacesStore from './store'; | ||
4 | import api from './api'; | ||
5 | |||
6 | const debug = require('debug')('Franz:feature:workspaces'); | ||
7 | |||
8 | let store = null; | ||
9 | const defaultState = { workspaces: [] }; | ||
10 | |||
11 | export const state = observable(defaultState); | ||
12 | |||
13 | export default function initWorkspaces(stores, actions) { | ||
14 | const { features, user } = stores; | ||
15 | reaction( | ||
16 | () => features.features.isWorkspaceEnabled && user.isLoggedIn, | ||
17 | (isEnabled) => { | ||
18 | if (isEnabled) { | ||
19 | debug('Initializing `workspaces` feature'); | ||
20 | store = new WorkspacesStore(stores, api, actions, state); | ||
21 | store.initialize(); | ||
22 | } else if (store) { | ||
23 | debug('Disabling `workspaces` feature'); | ||
24 | store.teardown(); | ||
25 | store = null; | ||
26 | // Reset state to default | ||
27 | merge(state, defaultState); | ||
28 | } | ||
29 | }, | ||
30 | { | ||
31 | fireImmediately: true, | ||
32 | }, | ||
33 | ); | ||
34 | } | ||
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js new file mode 100644 index 000000000..4b4e729ed --- /dev/null +++ b/src/features/workspaces/store.js | |||
@@ -0,0 +1,29 @@ | |||
1 | import { observable, reaction } from 'mobx'; | ||
2 | import Store from '../../stores/lib/Store'; | ||
3 | import CachedRequest from '../../stores/lib/CachedRequest'; | ||
4 | |||
5 | const debug = require('debug')('Franz:feature:workspaces'); | ||
6 | |||
7 | export default class WorkspacesStore extends Store { | ||
8 | @observable allWorkspacesRequest = new CachedRequest(this.api, 'getUserWorkspaces'); | ||
9 | |||
10 | constructor(stores, api, actions, state) { | ||
11 | super(stores, api, actions); | ||
12 | this.state = state; | ||
13 | } | ||
14 | |||
15 | setup() { | ||
16 | debug('fetching user workspaces'); | ||
17 | this.allWorkspacesRequest.execute(); | ||
18 | |||
19 | reaction( | ||
20 | () => this.allWorkspacesRequest.result, | ||
21 | workspaces => this.setWorkspaces(workspaces), | ||
22 | ); | ||
23 | } | ||
24 | |||
25 | setWorkspaces = (workspaces) => { | ||
26 | debug('setting user workspaces', workspaces.slice()); | ||
27 | this.state.workspaces = workspaces; | ||
28 | }; | ||
29 | } | ||
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js index eb2b21af3..05a620f0b 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js | |||
@@ -7,6 +7,7 @@ import delayApp from '../features/delayApp'; | |||
7 | import spellchecker from '../features/spellchecker'; | 7 | import spellchecker from '../features/spellchecker'; |
8 | import serviceProxy from '../features/serviceProxy'; | 8 | import serviceProxy from '../features/serviceProxy'; |
9 | import basicAuth from '../features/basicAuth'; | 9 | import basicAuth from '../features/basicAuth'; |
10 | import workspaces from '../features/workspaces'; | ||
10 | 11 | ||
11 | import { DEFAULT_FEATURES_CONFIG } from '../config'; | 12 | import { DEFAULT_FEATURES_CONFIG } from '../config'; |
12 | 13 | ||
@@ -56,5 +57,6 @@ export default class FeaturesStore extends Store { | |||
56 | spellchecker(this.stores, this.actions); | 57 | spellchecker(this.stores, this.actions); |
57 | serviceProxy(this.stores, this.actions); | 58 | serviceProxy(this.stores, this.actions); |
58 | basicAuth(this.stores, this.actions); | 59 | basicAuth(this.stores, this.actions); |
60 | workspaces(this.stores, this.actions); | ||
59 | } | 61 | } |
60 | } | 62 | } |