mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-11 01:22:48 +00:00
UI Overhaul
This commit is contained in:
43
client/app/stores/app.store.ts
Normal file
43
client/app/stores/app.store.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import jwt_decode from 'jwt-decode';
|
||||
import { action, observable } from 'mobx';
|
||||
import { IClaims } from '../model';
|
||||
import { axios, StorageService } from '../services';
|
||||
import { Util } from '../util';
|
||||
|
||||
export class AppStore {
|
||||
@observable
|
||||
public navbarOpen: boolean = false;
|
||||
@observable
|
||||
public jwt?: string;
|
||||
@observable
|
||||
public claims?: IClaims;
|
||||
|
||||
constructor() {
|
||||
const jwt = StorageService.getJWT();
|
||||
this.setJWT(jwt as string);
|
||||
this.initNavbar();
|
||||
}
|
||||
|
||||
private initNavbar() {
|
||||
if (!Util.isMobileScreen()) {
|
||||
this.navbarOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
private setJWT(jwt?: string) {
|
||||
if (!jwt) {
|
||||
return;
|
||||
}
|
||||
axios.defaults.headers['Authorization'] = `Bearer ${jwt}`;
|
||||
this.jwt = jwt;
|
||||
const claims = jwt_decode(jwt);
|
||||
if (claims) {
|
||||
this.claims = claims as IClaims;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
public toggleNavbar = () => {
|
||||
this.navbarOpen = !this.navbarOpen;
|
||||
};
|
||||
}
|
||||
2
client/app/stores/index.ts
Normal file
2
client/app/stores/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './app.store';
|
||||
export * from './root.store';
|
||||
7
client/app/stores/root.store.ts
Normal file
7
client/app/stores/root.store.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { AppStore } from './app.store';
|
||||
|
||||
export class RootStore {
|
||||
public appStore = new AppStore();
|
||||
}
|
||||
|
||||
export const rootStoreInstance = new RootStore();
|
||||
Reference in New Issue
Block a user