summaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
authorLibravatar haraldox <hnaumann+github@gmail.com>2018-02-26 17:06:27 +0100
committerLibravatar haraldox <hnaumann+github@gmail.com>2018-02-26 17:06:27 +0100
commit399f4f89229913c33e074bc3ee56a209ac2f3c1d (patch)
tree1b1078bf8e3fd9a81c4878e3a53814fe283917c4 /src/stores/SettingsStore.js
parentfeat(App) Feature Added enterprise UI (diff)
parentADD `features` request (diff)
downloadferdium-app-399f4f89229913c33e074bc3ee56a209ac2f3c1d.tar.gz
ferdium-app-399f4f89229913c33e074bc3ee56a209ac2f3c1d.tar.zst
ferdium-app-399f4f89229913c33e074bc3ee56a209ac2f3c1d.zip
Merge branch 'feature/features-api' into feature/enterprise-ui
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index da99a720f..b7d803398 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,17 +1,12 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed, observable, extendObservable } from 'mobx'; 2import { action, computed } from 'mobx';
3import localStorage from 'mobx-localstorage';
3 4
4import Store from './lib/Store'; 5import Store from './lib/Store';
5import Request from './lib/Request';
6import CachedRequest from './lib/CachedRequest';
7import { gaEvent } from '../lib/analytics'; 6import { gaEvent } from '../lib/analytics';
8import SettingsModel from '../models/Settings'; 7import SettingsModel from '../models/Settings';
9 8
10export default class SettingsStore extends Store { 9export default class SettingsStore extends Store {
11 @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings');
12 @observable updateSettingsRequest = new Request(this.api.local, 'updateSettings');
13 @observable removeSettingsKeyRequest = new Request(this.api.local, 'removeKey');
14
15 constructor(...args) { 10 constructor(...args) {
16 super(...args); 11 super(...args);
17 12
@@ -21,20 +16,16 @@ export default class SettingsStore extends Store {
21 } 16 }
22 17
23 setup() { 18 setup() {
24 this.allSettingsRequest.execute();
25 this._shareSettingsWithMainProcess(); 19 this._shareSettingsWithMainProcess();
26 } 20 }
27 21
28 @computed get all() { 22 @computed get all() {
29 return new SettingsModel(this.allSettingsRequest.result); 23 return new SettingsModel(localStorage.getItem('app') || {});
30 } 24 }
31 25
32 @action async _update({ settings }) { 26 @action async _update({ settings }) {
33 await this.updateSettingsRequest.execute(settings)._promise; 27 const appSettings = this.all;
34 await this.allSettingsRequest.patch((result) => { 28 localStorage.setItem('app', Object.assign(appSettings, settings));
35 if (!result) return;
36 extendObservable(result, settings);
37 });
38 29
39 // We need a little hack to wait until everything is patched 30 // We need a little hack to wait until everything is patched
40 setTimeout(() => this._shareSettingsWithMainProcess(), 0); 31 setTimeout(() => this._shareSettingsWithMainProcess(), 0);
@@ -43,8 +34,11 @@ export default class SettingsStore extends Store {
43 } 34 }
44 35
45 @action async _remove({ key }) { 36 @action async _remove({ key }) {
46 await this.removeSettingsKeyRequest.execute(key); 37 const appSettings = this.all;
47 await this.allSettingsRequest.invalidate({ immediately: true }); 38 if (Object.hasOwnProperty.call(appSettings, key)) {
39 delete appSettings[key];
40 localStorage.setItem('app', appSettings);
41 }
48 42
49 this._shareSettingsWithMainProcess(); 43 this._shareSettingsWithMainProcess();
50 } 44 }