diff options
author | 2022-06-22 16:21:23 +0200 | |
---|---|---|
committer | 2022-06-23 17:50:07 +0530 | |
commit | caf43fc8d64c27a1aad4a5d6507313c513c1a447 (patch) | |
tree | c0a7bcb950cdf555b3e8a33a57e2241e7051861d /src/stores/FeaturesStore.js | |
parent | Workaroud for in-app Password Recovery (#342) (diff) | |
download | ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.tar.gz ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.tar.zst ferdium-app-caf43fc8d64c27a1aad4a5d6507313c513c1a447.zip |
chore: featureStore and GlobalErrorStore JS => TS
Diffstat (limited to 'src/stores/FeaturesStore.js')
-rw-r--r-- | src/stores/FeaturesStore.js | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js deleted file mode 100644 index e2c0c08ef..000000000 --- a/src/stores/FeaturesStore.js +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | import { computed, observable, runInAction } from 'mobx'; | ||
2 | |||
3 | import Store from './lib/Store'; | ||
4 | import CachedRequest from './lib/CachedRequest'; | ||
5 | |||
6 | import serviceProxy from '../features/serviceProxy'; | ||
7 | import basicAuth from '../features/basicAuth'; | ||
8 | import workspaces from '../features/workspaces'; | ||
9 | import quickSwitch from '../features/quickSwitch'; | ||
10 | import publishDebugInfo from '../features/publishDebugInfo'; | ||
11 | import communityRecipes from '../features/communityRecipes'; | ||
12 | import todos from '../features/todos'; | ||
13 | import appearance from '../features/appearance'; | ||
14 | |||
15 | export default class FeaturesStore extends Store { | ||
16 | @observable defaultFeaturesRequest = new CachedRequest( | ||
17 | this.api.features, | ||
18 | 'default', | ||
19 | ); | ||
20 | |||
21 | @observable featuresRequest = new CachedRequest( | ||
22 | this.api.features, | ||
23 | 'features', | ||
24 | ); | ||
25 | |||
26 | @observable features = {}; | ||
27 | |||
28 | async setup() { | ||
29 | this.registerReactions([ | ||
30 | this._updateFeatures, | ||
31 | this._monitorLoginStatus.bind(this), | ||
32 | ]); | ||
33 | |||
34 | await this.featuresRequest._promise; | ||
35 | setTimeout(this._setupFeatures.bind(this), 1); | ||
36 | } | ||
37 | |||
38 | @computed get anonymousFeatures() { | ||
39 | return this.defaultFeaturesRequest.execute().result || {}; | ||
40 | } | ||
41 | |||
42 | _updateFeatures = () => { | ||
43 | const features = {}; | ||
44 | if (this.stores.user.isLoggedIn) { | ||
45 | let requestResult = {}; | ||
46 | try { | ||
47 | requestResult = this.featuresRequest.execute().result; | ||
48 | } catch (error) { | ||
49 | console.error(error); | ||
50 | } | ||
51 | Object.assign(features, requestResult); | ||
52 | } | ||
53 | runInAction('FeaturesStore::_updateFeatures', () => { | ||
54 | this.features = features; | ||
55 | }); | ||
56 | }; | ||
57 | |||
58 | _monitorLoginStatus() { | ||
59 | if (this.stores.user.isLoggedIn) { | ||
60 | this.featuresRequest.invalidate({ immediately: true }); | ||
61 | } else { | ||
62 | this.defaultFeaturesRequest.execute(); | ||
63 | this.defaultFeaturesRequest.invalidate({ immediately: true }); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | _setupFeatures() { | ||
68 | serviceProxy(this.stores); | ||
69 | basicAuth(); | ||
70 | workspaces(this.stores, this.actions); | ||
71 | quickSwitch(); | ||
72 | publishDebugInfo(); | ||
73 | communityRecipes(this.stores, this.actions); | ||
74 | todos(this.stores, this.actions); | ||
75 | appearance(this.stores); | ||
76 | } | ||
77 | } | ||