diff --git a/ui/src/App.vue b/ui/src/App.vue index dda4ded..b975ac3 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -51,10 +51,6 @@ import UserView from "./components/UserView.vue"; }) export default class extends Vue { public readonly store = advent22Store(); - - public mounted(): void { - this.store.init(); - } } diff --git a/ui/src/main.ts b/ui/src/main.ts index 87f611e..6e719e6 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -1,5 +1,6 @@ import { Advent22Plugin } from "@/plugins/advent22"; import { FontAwesomePlugin } from "@/plugins/fontawesome"; +import { advent22Store } from "@/plugins/store"; import { createPinia } from "pinia"; import { createApp } from "vue"; import App from "./App.vue"; @@ -11,4 +12,7 @@ app.use(Advent22Plugin); app.use(FontAwesomePlugin); app.use(createPinia()); +const store = advent22Store(); +store.init(app.config.globalProperties.$advent22); + app.mount("#app"); diff --git a/ui/src/plugins/advent22.ts b/ui/src/plugins/advent22.ts index d9d3152..a3aba49 100644 --- a/ui/src/plugins/advent22.ts +++ b/ui/src/plugins/advent22.ts @@ -156,10 +156,8 @@ export class Advent22 { } } -export const ADVENT22 = new Advent22(); - export const Advent22Plugin: Plugin = { install(app: App) { - app.config.globalProperties.$advent22 = ADVENT22; + app.config.globalProperties.$advent22 = new Advent22(); }, }; diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 6d4b347..0cba139 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -1,5 +1,5 @@ import { Credentials, DoorsSaved, SiteConfigModel } from "@/lib/api"; -import { ADVENT22 } from "@/plugins/advent22"; +import { Advent22 } from "@/plugins/advent22"; import { AxiosBasicCredentials } from "axios"; import { acceptHMRUpdate, defineStore } from "pinia"; @@ -10,6 +10,7 @@ export const advent22Store = defineStore({ id: "advent22", state: () => ({ + advent22: {} as Advent22, api_creds: empty_creds(), is_touch_device: check_touch_device(), is_admin: false, @@ -31,8 +32,11 @@ export const advent22Store = defineStore({ }, actions: { - init(): void { - ADVENT22.api_get_blob("user/favicon") + init(advent22: Advent22): void { + this.advent22 = advent22; + + advent22 + .api_get_blob("user/favicon") .then((favicon_src) => { const link: HTMLLinkElement = document.querySelector("link[rel*='icon']") || @@ -47,9 +51,9 @@ export const advent22Store = defineStore({ .catch(() => {}); Promise.all([ - ADVENT22.api_get("user/site_config"), - ADVENT22.api_get("user/doors"), - ADVENT22.api_get("user/next_door"), + advent22.api_get("user/site_config"), + advent22.api_get("user/doors"), + advent22.api_get("user/next_door"), ]) .then(([site_config, user_doors, next_door]) => { document.title = site_config.title; @@ -63,14 +67,15 @@ export const advent22Store = defineStore({ if (next_door !== null) this.next_door_target = Date.now() + next_door; }) - .catch(ADVENT22.alert_user_error); + .catch(advent22.alert_user_error); }, login(creds: Credentials = empty_creds()): Promise { this.api_creds = creds; return new Promise((resolve, reject) => { - ADVENT22.api_get("admin/is_admin") + this.advent22 + .api_get("admin/is_admin") .then((is_admin) => { this.is_admin = is_admin; resolve(is_admin);