aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2018-12-10 17:15:37 +0100
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-02-12 13:35:31 +0100
commit4a537e890d95e8666985ce77df4c6327582332be (patch)
treeb47dcd21e6b70de47ef45c882bbd0f55ce9aa603 /src
parentignore intellij project files (diff)
downloadferdium-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.js1
-rw-r--r--src/features/workspaces/api.js9
-rw-r--r--src/features/workspaces/index.js34
-rw-r--r--src/features/workspaces/store.js29
-rw-r--r--src/stores/FeaturesStore.js2
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
42export const DEFAULT_WINDOW_OPTIONS = { 43export 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
2const workspaces = [
3 { id: 'workspace-1', name: 'Private' },
4 { id: 'workspace-2', name: 'Office' },
5];
6
7export 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 @@
1import { observable, reaction } from 'mobx';
2import { merge } from 'lodash';
3import WorkspacesStore from './store';
4import api from './api';
5
6const debug = require('debug')('Franz:feature:workspaces');
7
8let store = null;
9const defaultState = { workspaces: [] };
10
11export const state = observable(defaultState);
12
13export 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 @@
1import { observable, reaction } from 'mobx';
2import Store from '../../stores/lib/Store';
3import CachedRequest from '../../stores/lib/CachedRequest';
4
5const debug = require('debug')('Franz:feature:workspaces');
6
7export 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';
7import spellchecker from '../features/spellchecker'; 7import spellchecker from '../features/spellchecker';
8import serviceProxy from '../features/serviceProxy'; 8import serviceProxy from '../features/serviceProxy';
9import basicAuth from '../features/basicAuth'; 9import basicAuth from '../features/basicAuth';
10import workspaces from '../features/workspaces';
10 11
11import { DEFAULT_FEATURES_CONFIG } from '../config'; 12import { 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}