refactor: ui store events

This commit is contained in:
Sergey Yarkov 2021-08-27 18:11:25 +03:00
parent 91fed1a002
commit e741c2b913
3 changed files with 38 additions and 8 deletions

View File

@ -1,10 +1,18 @@
import { makeAutoObservable } from 'mobx';
import Cookies from 'js-cookie';
import RootStore from './RootStore';
import AuthService from 'services/AuthService';
import { AxiosInstance } from 'axios';
import { IDataResult, ILoginResult } from 'interfaces';
/**
* Services
*/
import AuthService from 'services/AuthService';
/**
* Stores
*/
import RootStore from './RootStore';
export default class AuthStore {
public root: RootStore;

View File

@ -1,8 +1,12 @@
import { makeAutoObservable, observable } from 'mobx';
import { createBrowserHistory } from 'history';
import RootStore from './RootStore';
import { IWindowDimensions } from 'interfaces';
/**
* Stores
*/
import RootStore from './RootStore';
export default class UIStore {
public root: RootStore;
@ -20,22 +24,33 @@ export default class UIStore {
windowDimensions: observable.struct,
});
this.setupListeners();
}
/**
* Initialize some listeners
*/
private setupListeners(): void {
/**
* Pathname changed
*/
this.history.listen(({ pathname }) => {
console.log(`[history]: pathname changed to "${pathname}"`);
this.location = pathname;
});
window.onresize = () => {
this.windowDimensions = this.getWindowDimensions();
};
/**
* Window dimensions updated
*/
window.onresize = () => this.updateWindowDimensions();
}
public setLocation(location: string): void {
this.location = location;
}
private getWindowDimensions(): IWindowDimensions {
return { width: window.innerWidth, height: window.innerHeight };
private updateWindowDimensions(): void {
this.windowDimensions = { width: window.innerWidth, height: window.innerHeight };
}
get isDesktop() {

View File

@ -2,7 +2,14 @@ import { AxiosInstance } from 'axios';
import { makeAutoObservable, runInAction } from 'mobx';
import { IUserResult, IUser } from 'interfaces';
/**
* Services
*/
import UserService from 'services/UserService';
/**
* Stores
*/
import RootStore from './RootStore';
export default class UserStore {