From e3e19a05728313744273ca9007fc645ec23d629b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Fri, 23 Aug 2024 18:59:11 +0000 Subject: [PATCH] WIP: major refactoring --- ui/src/lib/store.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ui/src/lib/store.ts b/ui/src/lib/store.ts index e12ef2a..9b7388f 100644 --- a/ui/src/lib/store.ts +++ b/ui/src/lib/store.ts @@ -1,6 +1,6 @@ import { acceptHMRUpdate, defineStore } from "pinia"; import { API } from "./api"; -import { Loading, loading_success } from "./helpers"; +import { Loading } from "./helpers"; import { Credentials, DoorSaved, ImageData, SiteConfigModel } from "./model"; import { Door } from "./rects/door"; @@ -11,10 +11,10 @@ declare global { } type State = { - on_initialized: (() => void)[]; + on_initialized: (() => void)[] | null; is_touch_device: boolean; is_admin: boolean; - site_config: Loading; + site_config: SiteConfigModel; background_image: Loading; user_doors: Door[]; next_door_target: number | null; @@ -31,15 +31,25 @@ export const advent22Store = defineStore({ navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0, is_admin: false, - site_config: "loading", + site_config: { + title: document.title, + subtitle: "", + content: "", + footer: "", + }, background_image: "loading", user_doors: [], next_door_target: null, }), actions: { - init(): void { - this.update().then(() => this.on_initialized.forEach((fn) => fn())); + async init(): Promise { + await this.update(); + + if (this.on_initialized !== null) { + for (const callback of this.on_initialized) callback(); + } + this.on_initialized = null; }, async update(): Promise { @@ -84,7 +94,7 @@ export const advent22Store = defineStore({ }, when_initialized(callback: () => void): void { - if (loading_success(this.site_config)) { + if (this.on_initialized === null) { callback(); } else { this.on_initialized.push(callback);