mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
refactor: ui store events
This commit is contained in:
parent
91fed1a002
commit
e741c2b913
@ -1,10 +1,18 @@
|
|||||||
import { makeAutoObservable } from 'mobx';
|
import { makeAutoObservable } from 'mobx';
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import RootStore from './RootStore';
|
|
||||||
import AuthService from 'services/AuthService';
|
|
||||||
import { AxiosInstance } from 'axios';
|
import { AxiosInstance } from 'axios';
|
||||||
import { IDataResult, ILoginResult } from 'interfaces';
|
import { IDataResult, ILoginResult } from 'interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services
|
||||||
|
*/
|
||||||
|
import AuthService from 'services/AuthService';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores
|
||||||
|
*/
|
||||||
|
import RootStore from './RootStore';
|
||||||
|
|
||||||
export default class AuthStore {
|
export default class AuthStore {
|
||||||
public root: RootStore;
|
public root: RootStore;
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
import { makeAutoObservable, observable } from 'mobx';
|
import { makeAutoObservable, observable } from 'mobx';
|
||||||
import { createBrowserHistory } from 'history';
|
import { createBrowserHistory } from 'history';
|
||||||
import RootStore from './RootStore';
|
|
||||||
import { IWindowDimensions } from 'interfaces';
|
import { IWindowDimensions } from 'interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores
|
||||||
|
*/
|
||||||
|
import RootStore from './RootStore';
|
||||||
|
|
||||||
export default class UIStore {
|
export default class UIStore {
|
||||||
public root: RootStore;
|
public root: RootStore;
|
||||||
|
|
||||||
@ -20,22 +24,33 @@ export default class UIStore {
|
|||||||
windowDimensions: observable.struct,
|
windowDimensions: observable.struct,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setupListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize some listeners
|
||||||
|
*/
|
||||||
|
private setupListeners(): void {
|
||||||
|
/**
|
||||||
|
* Pathname changed
|
||||||
|
*/
|
||||||
this.history.listen(({ pathname }) => {
|
this.history.listen(({ pathname }) => {
|
||||||
console.log(`[history]: pathname changed to "${pathname}"`);
|
console.log(`[history]: pathname changed to "${pathname}"`);
|
||||||
this.location = pathname;
|
this.location = pathname;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.onresize = () => {
|
/**
|
||||||
this.windowDimensions = this.getWindowDimensions();
|
* Window dimensions updated
|
||||||
};
|
*/
|
||||||
|
window.onresize = () => this.updateWindowDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setLocation(location: string): void {
|
public setLocation(location: string): void {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWindowDimensions(): IWindowDimensions {
|
private updateWindowDimensions(): void {
|
||||||
return { width: window.innerWidth, height: window.innerHeight };
|
this.windowDimensions = { width: window.innerWidth, height: window.innerHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
get isDesktop() {
|
get isDesktop() {
|
||||||
|
|||||||
@ -2,7 +2,14 @@ import { AxiosInstance } from 'axios';
|
|||||||
import { makeAutoObservable, runInAction } from 'mobx';
|
import { makeAutoObservable, runInAction } from 'mobx';
|
||||||
import { IUserResult, IUser } from 'interfaces';
|
import { IUserResult, IUser } from 'interfaces';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services
|
||||||
|
*/
|
||||||
import UserService from 'services/UserService';
|
import UserService from 'services/UserService';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores
|
||||||
|
*/
|
||||||
import RootStore from './RootStore';
|
import RootStore from './RootStore';
|
||||||
|
|
||||||
export default class UserStore {
|
export default class UserStore {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user