diff options
author | Amine Mouafik <amine@mouafik.fr> | 2019-05-12 20:00:41 +0700 |
---|---|---|
committer | Amine Mouafik <amine@mouafik.fr> | 2019-05-12 20:00:41 +0700 |
commit | d8a1d5f9151cc31f4c2b5c0096a35e49b2c74d61 (patch) | |
tree | 3974d449d8ef389fc61bf880ae758b5debc22a80 /src/stores/FeaturesStore.js | |
parent | Use dark background in SVG logo (diff) | |
parent | Update CHANGELOG.md (diff) | |
download | ferdium-app-d8a1d5f9151cc31f4c2b5c0096a35e49b2c74d61.tar.gz ferdium-app-d8a1d5f9151cc31f4c2b5c0096a35e49b2c74d61.tar.zst ferdium-app-d8a1d5f9151cc31f4c2b5c0096a35e49b2c74d61.zip |
Merge tag 'v5.1.0'
# Conflicts:
# README.md
# src/components/layout/AppLayout.js
Diffstat (limited to 'src/stores/FeaturesStore.js')
-rw-r--r-- | src/stores/FeaturesStore.js | 35 |
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 @@ | |||
1 | import { computed, observable, reaction } from 'mobx'; | 1 | import { |
2 | computed, | ||
3 | observable, | ||
4 | reaction, | ||
5 | runInAction, | ||
6 | } from 'mobx'; | ||
2 | 7 | ||
3 | import Store from './lib/Store'; | 8 | import Store from './lib/Store'; |
4 | import CachedRequest from './lib/CachedRequest'; | 9 | import CachedRequest from './lib/CachedRequest'; |
@@ -7,6 +12,10 @@ import delayApp from '../features/delayApp'; | |||
7 | import spellchecker from '../features/spellchecker'; | 12 | import spellchecker from '../features/spellchecker'; |
8 | import serviceProxy from '../features/serviceProxy'; | 13 | import serviceProxy from '../features/serviceProxy'; |
9 | import basicAuth from '../features/basicAuth'; | 14 | import basicAuth from '../features/basicAuth'; |
15 | import workspaces from '../features/workspaces'; | ||
16 | import shareFranz from '../features/shareFranz'; | ||
17 | import announcements from '../features/announcements'; | ||
18 | import settingsWS from '../features/settingsWS'; | ||
10 | 19 | ||
11 | import { DEFAULT_FEATURES_CONFIG } from '../config'; | 20 | import { 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 | } |