diff options
author | 2018-02-26 16:43:57 +0100 | |
---|---|---|
committer | 2018-02-26 16:43:57 +0100 | |
commit | d1e6f03395b4d2b668a8da6260aca8adf823f1db (patch) | |
tree | 7153ce10c48f1ba6453999bca8e4ba8a8aa410eb /src | |
parent | initial commit (diff) | |
download | ferdium-app-d1e6f03395b4d2b668a8da6260aca8adf823f1db.tar.gz ferdium-app-d1e6f03395b4d2b668a8da6260aca8adf823f1db.tar.zst ferdium-app-d1e6f03395b4d2b668a8da6260aca8adf823f1db.zip |
ADD `features` request
REFACTOR `defaults` -> `base`
Diffstat (limited to 'src')
-rw-r--r-- | src/api/FeaturesApi.js | 8 | ||||
-rw-r--r-- | src/api/server/ServerApi.js | 20 | ||||
-rw-r--r-- | src/containers/layout/AppLayoutContainer.js | 6 | ||||
-rw-r--r-- | src/stores/AppStore.js | 3 | ||||
-rw-r--r-- | src/stores/FeaturesStore.js | 35 |
5 files changed, 58 insertions, 14 deletions
diff --git a/src/api/FeaturesApi.js b/src/api/FeaturesApi.js index 5749ab336..292dc80cc 100644 --- a/src/api/FeaturesApi.js +++ b/src/api/FeaturesApi.js | |||
@@ -3,7 +3,11 @@ export default class FeaturesApi { | |||
3 | this.server = server; | 3 | this.server = server; |
4 | } | 4 | } |
5 | 5 | ||
6 | defaults() { | 6 | base() { |
7 | return this.server.getDefaultFeatures(); | 7 | return this.server.getBaseFeatures(); |
8 | } | ||
9 | |||
10 | features() { | ||
11 | return this.server.getFeatures(); | ||
8 | } | 12 | } |
9 | } | 13 | } |
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 0951dfeda..ad7988bb2 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -260,8 +260,8 @@ export default class ServerApi { | |||
260 | } | 260 | } |
261 | 261 | ||
262 | // Features | 262 | // Features |
263 | async getDefaultFeatures() { | 263 | async getBaseFeatures() { |
264 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/features/default`, this._prepareAuthRequest({ | 264 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/features/base`, this._prepareAuthRequest({ |
265 | method: 'GET', | 265 | method: 'GET', |
266 | })); | 266 | })); |
267 | if (!request.ok) { | 267 | if (!request.ok) { |
@@ -270,7 +270,21 @@ export default class ServerApi { | |||
270 | const data = await request.json(); | 270 | const data = await request.json(); |
271 | 271 | ||
272 | const features = data; | 272 | const features = data; |
273 | console.debug('ServerApi::getDefaultFeatures resolves', features); | 273 | console.debug('ServerApi::getBaseFeatures resolves', features); |
274 | return features; | ||
275 | } | ||
276 | |||
277 | async getFeatures() { | ||
278 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/features`, this._prepareAuthRequest({ | ||
279 | method: 'GET', | ||
280 | })); | ||
281 | if (!request.ok) { | ||
282 | throw request; | ||
283 | } | ||
284 | const data = await request.json(); | ||
285 | |||
286 | const features = data; | ||
287 | console.debug('ServerApi::getFeatures resolves', features); | ||
274 | return features; | 288 | return features; |
275 | } | 289 | } |
276 | 290 | ||
diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index e4a9d60c3..2db2b7bb7 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js | |||
@@ -26,6 +26,7 @@ export default class AppLayoutContainer extends Component { | |||
26 | render() { | 26 | render() { |
27 | const { | 27 | const { |
28 | app, | 28 | app, |
29 | features, | ||
29 | services, | 30 | services, |
30 | ui, | 31 | ui, |
31 | news, | 32 | news, |
@@ -64,10 +65,13 @@ export default class AppLayoutContainer extends Component { | |||
64 | 65 | ||
65 | const { children } = this.props; | 66 | const { children } = this.props; |
66 | 67 | ||
68 | const isLoadingFeatures = features.featuresRequest.isExecuting | ||
69 | && features.featuresRequest.isExecutingFirstTime; | ||
70 | |||
67 | const isLoadingServices = services.allServicesRequest.isExecuting | 71 | const isLoadingServices = services.allServicesRequest.isExecuting |
68 | && services.allServicesRequest.isExecutingFirstTime; | 72 | && services.allServicesRequest.isExecutingFirstTime; |
69 | 73 | ||
70 | if (isLoadingServices) { | 74 | if (isLoadingFeatures || isLoadingServices) { |
71 | return ( | 75 | return ( |
72 | <AppLoader /> | 76 | <AppLoader /> |
73 | ); | 77 | ); |
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index a5640e8d3..162422017 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -158,9 +158,6 @@ export default class AppStore extends Store { | |||
158 | this.locale = this._getDefaultLocale(); | 158 | this.locale = this._getDefaultLocale(); |
159 | 159 | ||
160 | this._healthCheck(); | 160 | this._healthCheck(); |
161 | |||
162 | const defaults = this.stores.features.defaults; | ||
163 | console.log(defaults) | ||
164 | } | 161 | } |
165 | 162 | ||
166 | @computed get cacheSize() { | 163 | @computed get cacheSize() { |
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js index 5f738557f..817c2273f 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js | |||
@@ -5,14 +5,39 @@ import CachedRequest from './lib/CachedRequest'; | |||
5 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | 6 | ||
7 | export default class RecipesStore extends Store { | 7 | export default class RecipesStore extends Store { |
8 | @observable defaultFeaturesRequest = new CachedRequest(this.api.features, 'defaults'); | 8 | @observable baseFeaturesRequest = new CachedRequest(this.api.features, 'base'); |
9 | @observable featuresRequest = new CachedRequest(this.api.features, 'features'); | ||
9 | 10 | ||
10 | setup() { | 11 | setup() { |
11 | return this.defaults; | 12 | this.registerReactions([ |
13 | this._monitorLoginStatus.bind(this), | ||
14 | this._debugFeatures.bind(this), | ||
15 | ]); | ||
12 | } | 16 | } |
13 | 17 | ||
14 | @computed get defaults() { | 18 | @computed get base() { |
15 | console.log('GETTING DEFAULTS') | 19 | return this.baseFeaturesRequest.execute().result || {}; |
16 | return this.defaultFeaturesRequest.execute().result || []; | 20 | } |
21 | |||
22 | @computed get features() { | ||
23 | if (this.stores.user.isLoggedIn) { | ||
24 | return this.featuresRequest.execute().result || {}; | ||
25 | } | ||
26 | |||
27 | return this.base; | ||
28 | } | ||
29 | |||
30 | _debugFeatures() { | ||
31 | console.log(this.base, this.features) | ||
32 | } | ||
33 | |||
34 | _monitorLoginStatus() { | ||
35 | if (this.stores.user.isLoggedIn) { | ||
36 | this.featuresRequest.invalidate({ immediately: true }); | ||
37 | this.featuresRequest.execute(); | ||
38 | } else { | ||
39 | this.baseFeaturesRequest.invalidate({ immediately: true }); | ||
40 | this.baseFeaturesRequest.execute(); | ||
41 | } | ||
17 | } | 42 | } |
18 | } | 43 | } |