Dashboard work. Move configs to DB. Some script reorganization. Add nodemon configs.
This commit is contained in:
parent
168d82a966
commit
2adc5af8d7
39 changed files with 8441 additions and 2915 deletions
46
dashboard/src/store/auth.ts
Normal file
46
dashboard/src/store/auth.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { get, hasApiKey, post, setApiKey } from "../api";
|
||||
import { ActionTree, Module } from "vuex";
|
||||
import { AuthState, RootState } from "./types";
|
||||
|
||||
export const AuthStore: Module<AuthState, RootState> = {
|
||||
namespaced: true,
|
||||
|
||||
state: {
|
||||
apiKey: null,
|
||||
loadedInitialAuth: false,
|
||||
},
|
||||
|
||||
actions: {
|
||||
async loadInitialAuth({ dispatch, commit, state }) {
|
||||
if (state.loadedInitialAuth) return;
|
||||
|
||||
const storedKey = localStorage.getItem("apiKey");
|
||||
if (storedKey) {
|
||||
console.log("key?", storedKey);
|
||||
const result = await post("auth/validate-key", { key: storedKey });
|
||||
if (result.isValid) {
|
||||
await dispatch("setApiKey", storedKey);
|
||||
} else {
|
||||
localStorage.removeItem("apiKey");
|
||||
}
|
||||
}
|
||||
|
||||
commit("markInitialAuthLoaded");
|
||||
},
|
||||
|
||||
setApiKey({ commit, state }, newKey: string) {
|
||||
localStorage.setItem("apiKey", newKey);
|
||||
commit("setApiKey", newKey);
|
||||
},
|
||||
},
|
||||
|
||||
mutations: {
|
||||
setApiKey(state: AuthState, key) {
|
||||
state.apiKey = key;
|
||||
},
|
||||
|
||||
markInitialAuthLoaded(state: AuthState) {
|
||||
state.loadedInitialAuth = true;
|
||||
},
|
||||
},
|
||||
};
|
34
dashboard/src/store/guilds.ts
Normal file
34
dashboard/src/store/guilds.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { get } from "../api";
|
||||
import { Module } from "vuex";
|
||||
import { GuildState, LoadStatus, RootState } from "./types";
|
||||
|
||||
export const GuildStore: Module<GuildState, RootState> = {
|
||||
namespaced: true,
|
||||
|
||||
state: {
|
||||
availableGuildsLoadStatus: LoadStatus.None,
|
||||
available: [],
|
||||
configs: {},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async loadAvailableGuilds({ dispatch, commit, state }) {
|
||||
if (state.availableGuildsLoadStatus !== LoadStatus.None) return;
|
||||
commit("setAvailableGuildsLoadStatus", LoadStatus.Loading);
|
||||
|
||||
const availableGuilds = await get("guilds/available");
|
||||
commit("setAvailableGuilds", availableGuilds);
|
||||
},
|
||||
},
|
||||
|
||||
mutations: {
|
||||
setAvailableGuildsLoadStatus(state: GuildState, status: LoadStatus) {
|
||||
state.availableGuildsLoadStatus = status;
|
||||
},
|
||||
|
||||
setAvailableGuilds(state: GuildState, guilds) {
|
||||
state.available = guilds;
|
||||
state.availableGuildsLoadStatus = LoadStatus.Done;
|
||||
},
|
||||
},
|
||||
};
|
28
dashboard/src/store/index.ts
Normal file
28
dashboard/src/store/index.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import Vue from "vue";
|
||||
import Vuex, { Store } from "vuex";
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
import { RootState } from "./types";
|
||||
import { AuthStore } from "./auth";
|
||||
import { GuildStore } from "./guilds";
|
||||
|
||||
export const RootStore = new Vuex.Store<RootState>({
|
||||
modules: {
|
||||
auth: AuthStore,
|
||||
guilds: GuildStore,
|
||||
},
|
||||
});
|
||||
|
||||
// Set up typings so Vue/our components know about the state's types
|
||||
declare module "vue/types/options" {
|
||||
interface ComponentOptions<V extends Vue> {
|
||||
store?: Store<RootState>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "vue/types/vue" {
|
||||
interface Vue {
|
||||
$store: Store<RootState>;
|
||||
}
|
||||
}
|
27
dashboard/src/store/types.ts
Normal file
27
dashboard/src/store/types.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
export enum LoadStatus {
|
||||
None = 1,
|
||||
Loading,
|
||||
Done,
|
||||
}
|
||||
|
||||
export interface AuthState {
|
||||
apiKey: string | null;
|
||||
loadedInitialAuth: boolean;
|
||||
}
|
||||
|
||||
export interface GuildState {
|
||||
availableGuildsLoadStatus: LoadStatus;
|
||||
available: Array<{
|
||||
guild_id: string;
|
||||
name: string;
|
||||
icon: string | null;
|
||||
}>;
|
||||
configs: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type RootState = {
|
||||
auth: AuthState;
|
||||
guilds: GuildState;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue