Files
supabase/apps/studio/stores/RootStore.ts
T
Ivan Vasilov 436bdb10ae chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio.

* Move studio specific prettier ignores.

* Fix the ui references from studio.

* Fix the css imports.

* Fix all package.json issues.

* Fix the prettier setup for the studio app.

* Add .turbo folder to prettierignore.

* Fix the github workflows.
2023-11-15 12:38:55 +01:00

64 lines
1.8 KiB
TypeScript

import { configure } from 'mobx'
import { Project } from 'types'
import UiStore, { IUiStore } from './UiStore'
import AppStore, { IAppStore } from './app/AppStore'
import MetaStore, { IMetaStore } from './pgmeta/MetaStore'
import ProjectFunctionsStore, { IProjectFunctionsStore } from './project/ProjectFunctionsStore'
import VaultStore, { IVaultStore } from './project/VaultStore'
// Temporary disable mobx warnings
// TODO: need to remove this after refactoring old stores.
configure({
enforceActions: 'never',
})
export interface IRootStore {
app: IAppStore
ui: IUiStore
meta: IMetaStore
functions: IProjectFunctionsStore
vault: IVaultStore
selectedProjectRef?: string
setProject: (project: Project) => void
}
export class RootStore implements IRootStore {
app: IAppStore
ui: IUiStore
meta: IMetaStore
functions: IProjectFunctionsStore
vault: IVaultStore
selectedProjectRef: string | undefined
constructor() {
this.app = new AppStore(this)
this.ui = new UiStore(this)
this.meta = new MetaStore(this, { projectRef: '', connectionString: '' })
this.functions = new ProjectFunctionsStore(this, { projectRef: '' })
this.vault = new VaultStore(this)
}
/**
* Set selected project reference
*
* This method will also trigger project detail loading when it's not available
*/
setProject(project: Project) {
if (this.selectedProjectRef === project.ref) return
// reset ui projectRef in case of switching projects
// this will show the loading screen instead of showing the previous project
this.ui.setProjectRef(undefined)
this.meta.setProjectDetails(project)
this.functions.setProjectRef(project.ref)
// ui set must come last
this.ui.setProjectRef(project.ref)
this.selectedProjectRef = project.ref
}
}