Files
Papo/public/ts/state/store.ts
Pascal Prießnitz 22caa79b54
All checks were successful
Deploy Discord Bot / deploy (push) Successful in 37s
[deploy]
2025-12-04 16:43:38 +01:00

50 lines
986 B
TypeScript

export interface AppConfig {
baseRoot: string;
baseDashboard: string;
baseAuth: string;
baseApi: string;
view: 'selection' | 'dashboard';
initialGuildId?: string;
isAdmin?: boolean;
userLabel?: string;
}
export interface AppState {
guildId?: string;
isAdmin?: boolean;
userLabel?: string;
}
type Listener = (state: AppState) => void;
let config: AppConfig | null = null;
let state: AppState = {};
const listeners = new Set<Listener>();
export function initConfig(next: AppConfig) {
config = next;
state = {
guildId: next.initialGuildId,
isAdmin: next.isAdmin,
userLabel: next.userLabel
};
}
export function getConfig() {
return config;
}
export function getState() {
return state;
}
export function setState(partial: Partial<AppState>) {
state = { ...state, ...partial };
listeners.forEach((l) => l(state));
}
export function subscribe(listener: Listener) {
listeners.add(listener);
return () => listeners.delete(listener);
}