chore: app config store updates

This commit is contained in:
sriram veeraghanta 2023-12-11 14:55:05 +05:30
parent 912213e051
commit d0688e5287
7 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import { observable, action, makeObservable, runInAction } from "mobx";
// types
import { RootStore } from "./root";
import { IAppConfig } from "types/app";
// services
import { AppConfigService } from "services/app_config.service";
export interface IAppConfigStore {
envConfig: IAppConfig | null;
// action
fetchAppConfig: () => Promise<any>;
}
class AppConfigStore implements IAppConfigStore {
// observables
envConfig: IAppConfig | null = null;
// root store
rootStore;
// service
appConfigService;
constructor(_rootStore: RootStore) {
makeObservable(this, {
// observables
envConfig: observable.ref,
// actions
fetchAppConfig: action,
});
this.appConfigService = new AppConfigService();
this.rootStore = _rootStore;
}
fetchAppConfig = async () => {
try {
const config = await this.appConfigService.envConfig();
runInAction(() => {
this.envConfig = config;
});
return config;
} catch (error) {
throw error;
}
};
}
export default AppConfigStore;

View File

@ -0,0 +1,15 @@
export class AppRootStore {
config;
commandPalette;
eventTracker;
instance;
theme;
constructor() {
this.config = new ConfigStore();
this.commandPalette = new CommandPaletteStore();
this.eventTracker = new EventTrackerStore();
this.instance = new InstanceStore();
this.theme = new ThemeStore();
}
}

View File

View File

30
web/store/root.store.ts Normal file
View File

@ -0,0 +1,30 @@
import { enableStaticRendering } from "mobx-react-lite";
// root stores
import { AppRootStore } from "./application";
enableStaticRendering(typeof window === "undefined");
export class RootStore {
app;
user;
workspace;
project;
cycle;
module;
projectView;
constructor() {
this.app = new AppRootStore();
this.user = new UserRootStore();
this.workspace = new WorkspaceRootStore();
this.project = new ProjectRootStore();
this.cycle = new CycleRootStore();
this.module = new ModuleRootStore();
this.projectView = new ProjectViewRootStore();
this.page = new PageRootStore();
this.issue = new IssueRootStore();
// independent stores
this.label = new labelStore();
this.state = new stateStore();
}
}