aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/FeaturesStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/FeaturesStore.js')
-rw-r--r--src/stores/FeaturesStore.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js
index 0adee6adf..e7832088b 100644
--- a/src/stores/FeaturesStore.js
+++ b/src/stores/FeaturesStore.js
@@ -1,4 +1,9 @@
1import { computed, observable, reaction } from 'mobx'; 1import {
2 computed,
3 observable,
4 reaction,
5 runInAction,
6} from 'mobx';
2 7
3import Store from './lib/Store'; 8import Store from './lib/Store';
4import CachedRequest from './lib/CachedRequest'; 9import CachedRequest from './lib/CachedRequest';
@@ -7,6 +12,10 @@ import delayApp from '../features/delayApp';
7import spellchecker from '../features/spellchecker'; 12import spellchecker from '../features/spellchecker';
8import serviceProxy from '../features/serviceProxy'; 13import serviceProxy from '../features/serviceProxy';
9import basicAuth from '../features/basicAuth'; 14import basicAuth from '../features/basicAuth';
15import workspaces from '../features/workspaces';
16import shareFranz from '../features/shareFranz';
17import announcements from '../features/announcements';
18import settingsWS from '../features/settingsWS';
10 19
11import { DEFAULT_FEATURES_CONFIG } from '../config'; 20import { DEFAULT_FEATURES_CONFIG } from '../config';
12 21
@@ -15,13 +24,16 @@ export default class FeaturesStore extends Store {
15 24
16 @observable featuresRequest = new CachedRequest(this.api.features, 'features'); 25 @observable featuresRequest = new CachedRequest(this.api.features, 'features');
17 26
27 @observable features = Object.assign({}, DEFAULT_FEATURES_CONFIG);
28
18 async setup() { 29 async setup() {
19 this.registerReactions([ 30 this.registerReactions([
31 this._updateFeatures,
20 this._monitorLoginStatus.bind(this), 32 this._monitorLoginStatus.bind(this),
21 ]); 33 ]);
22 34
23 await this.featuresRequest._promise; 35 await this.featuresRequest._promise;
24 setTimeout(this._enableFeatures.bind(this), 1); 36 setTimeout(this._setupFeatures.bind(this), 1);
25 37
26 // single key reaction 38 // single key reaction
27 reaction(() => this.stores.user.data.isPremium, () => { 39 reaction(() => this.stores.user.data.isPremium, () => {
@@ -35,13 +47,16 @@ export default class FeaturesStore extends Store {
35 return this.defaultFeaturesRequest.execute().result || DEFAULT_FEATURES_CONFIG; 47 return this.defaultFeaturesRequest.execute().result || DEFAULT_FEATURES_CONFIG;
36 } 48 }
37 49
38 @computed get features() { 50 _updateFeatures = () => {
51 const features = Object.assign({}, DEFAULT_FEATURES_CONFIG);
39 if (this.stores.user.isLoggedIn) { 52 if (this.stores.user.isLoggedIn) {
40 return this.featuresRequest.execute().result || DEFAULT_FEATURES_CONFIG; 53 const requestResult = this.featuresRequest.execute().result;
54 Object.assign(features, requestResult);
41 } 55 }
42 56 runInAction('FeaturesStore::_updateFeatures', () => {
43 return DEFAULT_FEATURES_CONFIG; 57 this.features = features;
44 } 58 });
59 };
45 60
46 _monitorLoginStatus() { 61 _monitorLoginStatus() {
47 if (this.stores.user.isLoggedIn) { 62 if (this.stores.user.isLoggedIn) {
@@ -51,10 +66,14 @@ export default class FeaturesStore extends Store {
51 } 66 }
52 } 67 }
53 68
54 _enableFeatures() { 69 _setupFeatures() {
55 delayApp(this.stores, this.actions); 70 delayApp(this.stores, this.actions);
56 spellchecker(this.stores, this.actions); 71 spellchecker(this.stores, this.actions);
57 serviceProxy(this.stores, this.actions); 72 serviceProxy(this.stores, this.actions);
58 basicAuth(this.stores, this.actions); 73 basicAuth(this.stores, this.actions);
74 workspaces(this.stores, this.actions);
75 shareFranz(this.stores, this.actions);
76 announcements(this.stores, this.actions);
77 settingsWS(this.stores, this.actions);
59 } 78 }
60} 79}