aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2022-08-04 00:12:03 +0100
committerLibravatar GitHub <noreply@github.com>2022-08-03 23:12:03 +0000
commitc2509e860752e23812bb408e331c02c918aadd54 (patch)
treeb855163ad1bddaaa19c47a9cea2713c6899ea1a5 /src/stores
parentRevert to older working version of 'macos-notification-state' (diff)
downloadferdium-app-c2509e860752e23812bb408e331c02c918aadd54.tar.gz
ferdium-app-c2509e860752e23812bb408e331c02c918aadd54.tar.zst
ferdium-app-c2509e860752e23812bb408e331c02c918aadd54.zip
chore: change values inside mobx actions to fix console warnings (#532)
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.ts22
-rw-r--r--src/stores/RequestStore.ts16
-rw-r--r--src/stores/ServicesStore.ts21
-rw-r--r--src/stores/SettingsStore.ts11
-rw-r--r--src/stores/lib/Request.js24
-rw-r--r--src/stores/lib/TypedStore.ts14
6 files changed, 68 insertions, 40 deletions
diff --git a/src/stores/AppStore.ts b/src/stores/AppStore.ts
index af1a0daae..08d2f718c 100644
--- a/src/stores/AppStore.ts
+++ b/src/stores/AppStore.ts
@@ -503,6 +503,17 @@ export default class AppStore extends TypedStore {
503 this.isClearingAllCache = false; 503 this.isClearingAllCache = false;
504 } 504 }
505 505
506 @action _setLocale() {
507 if (this.stores.user?.isLoggedIn && this.stores.user?.data.locale) {
508 this.locale = this.stores.user.data.locale;
509 } else if (!this.locale) {
510 this.locale = this._getDefaultLocale();
511 }
512
513 moment.locale(this.locale);
514 debug(`Set locale to "${this.locale}"`);
515 }
516
506 // Reactions 517 // Reactions
507 _offlineCheck() { 518 _offlineCheck() {
508 if (!this.isOnline) { 519 if (!this.isOnline) {
@@ -516,17 +527,6 @@ export default class AppStore extends TypedStore {
516 } 527 }
517 } 528 }
518 529
519 _setLocale() {
520 if (this.stores.user?.isLoggedIn && this.stores.user?.data.locale) {
521 this.locale = this.stores.user.data.locale;
522 } else if (!this.locale) {
523 this.locale = this._getDefaultLocale();
524 }
525
526 moment.locale(this.locale);
527 debug(`Set locale to "${this.locale}"`);
528 }
529
530 _getDefaultLocale() { 530 _getDefaultLocale() {
531 return getLocale({ 531 return getLocale({
532 locale: ferdiumLocale, 532 locale: ferdiumLocale,
diff --git a/src/stores/RequestStore.ts b/src/stores/RequestStore.ts
index 59982c05a..279615e50 100644
--- a/src/stores/RequestStore.ts
+++ b/src/stores/RequestStore.ts
@@ -44,12 +44,7 @@ export default class RequestStore extends TypedStore {
44 this.servicesRequest = this.stores.services.allServicesRequest; 44 this.servicesRequest = this.stores.services.allServicesRequest;
45 45
46 ipcRenderer.on('localServerPort', (_, data) => { 46 ipcRenderer.on('localServerPort', (_, data) => {
47 if (data.port) { 47 this.setData(data);
48 this.localServerPort = data.port;
49 }
50 if (data.token) {
51 this.localServerToken = data.token;
52 }
53 }); 48 });
54 } 49 }
55 50
@@ -70,6 +65,15 @@ export default class RequestStore extends TypedStore {
70 this.servicesRequest.reload(); 65 this.servicesRequest.reload();
71 } 66 }
72 67
68 @action setData(data: { port: number; token: string | undefined }): void {
69 if (data.port) {
70 this.localServerPort = data.port;
71 }
72 if (data.token) {
73 this.localServerToken = data.token;
74 }
75 }
76
73 // Reactions 77 // Reactions
74 _autoRetry(): void { 78 _autoRetry(): void {
75 const delay = (this.retries <= 10 ? this.retries : 10) * this.retryDelay; 79 const delay = (this.retries <= 10 ? this.retries : 10) * this.retryDelay;
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts
index 7812d5aee..83ec7d18e 100644
--- a/src/stores/ServicesStore.ts
+++ b/src/stores/ServicesStore.ts
@@ -618,6 +618,10 @@ export default class ServicesStore extends TypedStore {
618 await request._promise; 618 await request._promise;
619 } 619 }
620 620
621 @action _setIsActive(service: Service, state: boolean): void {
622 service.isActive = state;
623 }
624
621 @action _setActive({ serviceId, keepActiveRoute = null }) { 625 @action _setActive({ serviceId, keepActiveRoute = null }) {
622 if (!keepActiveRoute) this.stores.router.push('/'); 626 if (!keepActiveRoute) this.stores.router.push('/');
623 const service = this.one(serviceId); 627 const service = this.one(serviceId);
@@ -625,10 +629,10 @@ export default class ServicesStore extends TypedStore {
625 for (const s of this.all) { 629 for (const s of this.all) {
626 if (s.isActive) { 630 if (s.isActive) {
627 s.lastUsed = Date.now(); 631 s.lastUsed = Date.now();
628 s.isActive = false; 632 this._setIsActive(s, false);
629 } 633 }
630 } 634 }
631 service.isActive = true; 635 this._setIsActive(service, true);
632 this._awake({ serviceId: service.id }); 636 this._awake({ serviceId: service.id });
633 637
634 if ( 638 if (
@@ -650,7 +654,7 @@ export default class ServicesStore extends TypedStore {
650 @action _blurActive() { 654 @action _blurActive() {
651 const service = this.active; 655 const service = this.active;
652 if (service) { 656 if (service) {
653 service.isActive = false; 657 this._setIsActive(service, false);
654 } else { 658 } else {
655 debug('No service is active'); 659 debug('No service is active');
656 } 660 }
@@ -1194,13 +1198,14 @@ export default class ServicesStore extends TypedStore {
1194 _mapActiveServiceToServiceModelReaction() { 1198 _mapActiveServiceToServiceModelReaction() {
1195 const { activeService } = this.stores.settings.all.service; 1199 const { activeService } = this.stores.settings.all.service;
1196 if (this.allDisplayed.length > 0) { 1200 if (this.allDisplayed.length > 0) {
1197 this.allDisplayed.map(service => 1201 for (const service of this.allDisplayed) {
1198 Object.assign(service, { 1202 this._setIsActive(
1199 isActive: activeService 1203 service,
1204 activeService
1200 ? activeService === service.id 1205 ? activeService === service.id
1201 : this.allDisplayed[0].id === service.id, 1206 : this.allDisplayed[0].id === service.id,
1202 }), 1207 );
1203 ); 1208 }
1204 } 1209 }
1205 } 1210 }
1206 1211
diff --git a/src/stores/SettingsStore.ts b/src/stores/SettingsStore.ts
index e2903c952..811bc6f76 100644
--- a/src/stores/SettingsStore.ts
+++ b/src/stores/SettingsStore.ts
@@ -100,8 +100,11 @@ export default class SettingsStore extends TypedStore {
100 }); 100 });
101 } 101 }
102 debug('Get appSettings resolves', resp.type, resp.data); 102 debug('Get appSettings resolves', resp.type, resp.data);
103 Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); 103 this.actions.settings.update({
104 this.loaded = true; 104 type: resp.type,
105 data: resp.data,
106 });
107 this.setLoaded();
105 ipcRenderer.send('initialAppSettings', resp); 108 ipcRenderer.send('initialAppSettings', resp);
106 }); 109 });
107 110
@@ -148,6 +151,10 @@ export default class SettingsStore extends TypedStore {
148 }; 151 };
149 } 152 }
150 153
154 @action async setLoaded(): Promise<void> {
155 this.loaded = true;
156 }
157
151 @action async _update({ type, data }): Promise<void> { 158 @action async _update({ type, data }): Promise<void> {
152 const appSettings = this.all; 159 const appSettings = this.all;
153 if (!this.fileSystemSettingsTypes.includes(type)) { 160 if (!this.fileSystemSettingsTypes.includes(type)) {
diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js
index e58341790..60c943a42 100644
--- a/src/stores/lib/Request.js
+++ b/src/stores/lib/Request.js
@@ -18,6 +18,18 @@ export default class Request {
18 18
19 @observable wasExecuted = false; 19 @observable wasExecuted = false;
20 20
21 @action _reset() {
22 this.error = null;
23 this.result = null;
24 this.isExecuting = false;
25 this.isError = false;
26 this.wasExecuted = false;
27 this._isWaitingForResponse = false;
28 this._promise = Promise;
29
30 return this;
31 }
32
21 _promise = Promise; 33 _promise = Promise;
22 34
23 _api = {}; 35 _api = {};
@@ -139,15 +151,5 @@ export default class Request {
139 for (const hook of Request._hooks) hook(this); 151 for (const hook of Request._hooks) hook(this);
140 } 152 }
141 153
142 reset = () => { 154 reset = () => this._reset();
143 this.error = null;
144 this.result = null;
145 this.isExecuting = false;
146 this.isError = false;
147 this.wasExecuted = false;
148 this._isWaitingForResponse = false;
149 this._promise = Promise;
150
151 return this;
152 };
153} 155}
diff --git a/src/stores/lib/TypedStore.ts b/src/stores/lib/TypedStore.ts
index e44eadd32..0a669e669 100644
--- a/src/stores/lib/TypedStore.ts
+++ b/src/stores/lib/TypedStore.ts
@@ -1,4 +1,10 @@
1import { computed, IReactionPublic, makeObservable, observable } from 'mobx'; 1import {
2 action,
3 computed,
4 IReactionPublic,
5 makeObservable,
6 observable,
7} from 'mobx';
2import { Actions } from '../../actions/lib/actions'; 8import { Actions } from '../../actions/lib/actions';
3import { ApiInterface } from '../../api'; 9import { ApiInterface } from '../../api';
4import { Stores } from '../../@types/stores.types'; 10import { Stores } from '../../@types/stores.types';
@@ -15,6 +21,10 @@ export default abstract class TypedStore {
15 21
16 actions: Actions; 22 actions: Actions;
17 23
24 @action _setResetStatus() {
25 this._status = null;
26 }
27
18 @computed get actionStatus() { 28 @computed get actionStatus() {
19 return this._status || []; 29 return this._status || [];
20 } 30 }
@@ -49,6 +59,6 @@ export default abstract class TypedStore {
49 } 59 }
50 60
51 resetStatus(): void { 61 resetStatus(): void {
52 this._status = null; 62 this._setResetStatus();
53 } 63 }
54} 64}