Pull request: beta client squashed
Merge in DNS/adguard-home from beta-client-2 to master
Squashed commit of the following:
commit b2640cc49a6c5484d730b534dcf5a8013d7fa478
Merge: 659def862 aef4659e9
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 19:23:09 2020 +0300
Merge branch 'master' into beta-client-2
commit 659def8626467949c35b7a6a0c99ffafb07b4385
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 17:25:14 2020 +0300
all: upgrade github actions node version
commit b4b8cf8dd75672e9155da5d111ac66e8f5ba1535
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date: Tue Dec 29 16:57:14 2020 +0300
all: beta client squashed
This commit is contained in:
1
client2/src/store/index.ts
Normal file
1
client2/src/store/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default, Store, storeValue } from './store';
|
||||
19
client2/src/store/installStore.ts
Normal file
19
client2/src/store/installStore.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createContext } from 'react';
|
||||
import Install from './stores/Install';
|
||||
import UI from './stores/ui';
|
||||
|
||||
export class Store {
|
||||
ui: UI;
|
||||
|
||||
install: Install;
|
||||
|
||||
constructor() {
|
||||
this.ui = new UI(this);
|
||||
this.install = new Install(this);
|
||||
}
|
||||
}
|
||||
|
||||
export const storeValue = new Store();
|
||||
|
||||
const StoreContext = createContext<Store>(storeValue);
|
||||
export default StoreContext;
|
||||
15
client2/src/store/store.ts
Normal file
15
client2/src/store/store.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createContext } from 'react';
|
||||
import UI from './stores/ui';
|
||||
|
||||
export class Store {
|
||||
ui: UI;
|
||||
|
||||
constructor() {
|
||||
this.ui = new UI(this);
|
||||
}
|
||||
}
|
||||
|
||||
export const storeValue = new Store();
|
||||
|
||||
const StoreContext = createContext<Store>(storeValue);
|
||||
export default StoreContext;
|
||||
50
client2/src/store/stores/Install.ts
Normal file
50
client2/src/store/stores/Install.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import InstallApi from 'Apis/install';
|
||||
import AddressesInfoBeta, { IAddressesInfoBeta } from 'Entities/AddressesInfoBeta';
|
||||
import { ICheckConfigRequestBeta } from 'Entities/CheckConfigRequestBeta';
|
||||
import CheckConfigResponse, { ICheckConfigResponse } from 'Entities/CheckConfigResponse';
|
||||
import { IInitialConfigurationBeta } from 'Entities/InitialConfigurationBeta';
|
||||
import { errorChecker } from 'Helpers/apiErrors';
|
||||
import { flow, makeAutoObservable } from 'mobx';
|
||||
|
||||
import { Store } from 'Store';
|
||||
|
||||
export default class Install {
|
||||
rootStore: Store;
|
||||
|
||||
addresses: AddressesInfoBeta | null;
|
||||
|
||||
constructor(rootStore: Store) {
|
||||
this.rootStore = rootStore;
|
||||
this.addresses = null;
|
||||
|
||||
makeAutoObservable(this, {
|
||||
rootStore: false,
|
||||
getAddresses: flow,
|
||||
});
|
||||
this.getAddresses();
|
||||
}
|
||||
|
||||
* getAddresses() {
|
||||
const response = yield InstallApi.installGetAddressesBeta();
|
||||
const { result } = errorChecker<IAddressesInfoBeta>(response);
|
||||
if (result) {
|
||||
this.addresses = new AddressesInfoBeta(result);
|
||||
}
|
||||
}
|
||||
|
||||
static async checkConfig(config: ICheckConfigRequestBeta) {
|
||||
const response = await InstallApi.installCheckConfigBeta(config);
|
||||
const { result } = errorChecker<ICheckConfigResponse>(response);
|
||||
if (result) {
|
||||
return new CheckConfigResponse(result);
|
||||
}
|
||||
}
|
||||
|
||||
static async configure(config: IInitialConfigurationBeta) {
|
||||
const response = await InstallApi.installConfigureBeta(config);
|
||||
const { result } = errorChecker<number>(response);
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
client2/src/store/stores/ui.ts
Normal file
25
client2/src/store/stores/ui.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { makeAutoObservable, observable } from 'mobx';
|
||||
|
||||
import Translator, { DEFAULT_LOCALE, messages, Locale, reactFormater } from 'Localization';
|
||||
import { Store } from 'Store';
|
||||
|
||||
export default class UI {
|
||||
rootStore: Store;
|
||||
|
||||
currentLang = DEFAULT_LOCALE;
|
||||
|
||||
intl = new Translator<Locale>(Locale.en, messages, DEFAULT_LOCALE, reactFormater);
|
||||
|
||||
constructor(rootStore: Store) {
|
||||
this.rootStore = rootStore;
|
||||
makeAutoObservable(this, {
|
||||
intl: observable.struct,
|
||||
rootStore: false,
|
||||
});
|
||||
}
|
||||
|
||||
updateLang = (lang: Locale) => {
|
||||
this.currentLang = lang;
|
||||
this.intl = this.intl.updateTranslator(lang);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user