Convert portal navigation store to BudiStore

This commit is contained in:
Andrew Kingston 2025-01-13 11:28:04 +00:00
parent 65bd89250d
commit 12b283d41e
No known key found for this signature in database
2 changed files with 13 additions and 20 deletions

View File

@ -18,7 +18,7 @@
$: useAccountPortal = cloud && !$admin.disableAccountPortal $: useAccountPortal = cloud && !$admin.disableAccountPortal
navigation.actions.init($redirect) navigation.init($redirect)
const validateTenantId = async () => { const validateTenantId = async () => {
const host = window.location.host const host = window.location.host

View File

@ -1,38 +1,31 @@
import { writable } from "svelte/store" import { BudiStore } from "../BudiStore"
type GotoFuncType = (path: string) => void type GotoFuncType = (path: string) => void
interface PortalNavigationStore { interface NavigationState {
initialisated: boolean initialisated: boolean
goto: GotoFuncType goto: GotoFuncType
} }
export function createNavigationStore() { class NavigationStore extends BudiStore<NavigationState> {
const store = writable<PortalNavigationStore>({ constructor() {
initialisated: false, super({
goto: undefined as any, initialisated: false,
}) goto: undefined as any,
const { set, subscribe } = store })
}
const init = (gotoFunc: GotoFuncType) => { init(gotoFunc: GotoFuncType) {
if (typeof gotoFunc !== "function") { if (typeof gotoFunc !== "function") {
throw new Error( throw new Error(
`gotoFunc must be a function, found a "${typeof gotoFunc}" instead` `gotoFunc must be a function, found a "${typeof gotoFunc}" instead`
) )
} }
this.set({
set({
initialisated: true, initialisated: true,
goto: gotoFunc, goto: gotoFunc,
}) })
} }
return {
subscribe,
actions: {
init,
},
}
} }
export const navigation = createNavigationStore() export const navigation = new NavigationStore()