diff --git a/ui/src/components/Calendar.vue b/ui/src/components/Calendar.vue index b3006ff..02cf133 100644 --- a/ui/src/components/Calendar.vue +++ b/ui/src/components/Calendar.vue @@ -85,11 +85,13 @@ export default class extends Vue { if (this.store.is_touch_device) return; - this.toast_timeout = setTimeout(() => { - if (this.store.user_doors.length === 0) return; + this.store.when_initialized(() => { + this.toast_timeout = setTimeout(() => { + if (this.store.user_doors.length === 0) return; - this.toast!.show({ duration: 600000, type: "is-warning" }); - }, 10000); + this.toast!.show({ duration: 600000, type: "is-warning" }); + }, 10000); + }); } public door_click(day: number) { diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 8460713..681a09e 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -14,6 +14,8 @@ declare global { type State = { advent22: Advent22; api_creds: RemovableRef; + is_initialized: boolean; + on_initialized: (() => void)[]; is_touch_device: boolean; is_admin: boolean; site_config: SiteConfigModel; @@ -29,6 +31,8 @@ export const advent22Store = defineStore({ state: (): State => ({ advent22: new Advent22(), api_creds: useLocalStorage("advent22/auth", ["", ""]), + is_initialized: false, + on_initialized: [], is_touch_device: window.matchMedia("(any-hover: none)").matches || "ontouchstart" in window || @@ -96,10 +100,21 @@ export const advent22Store = defineStore({ if (next_door !== null) this.next_door_target = Date.now() + next_door; + + this.is_initialized = true; + for (const callback of this.on_initialized) callback(); }) .catch(this.advent22.alert_user_error); }, + when_initialized(callback: () => void): void { + if (this.is_initialized) { + callback(); + } else { + this.on_initialized.push(callback); + } + }, + update_is_admin(): Promise { return new Promise((resolve, reject) => { this.advent22