diff --git a/ui/src/components/admin/ConfigView.vue b/ui/src/components/admin/ConfigView.vue index d0ce3db..af10454 100644 --- a/ui/src/components/admin/ConfigView.vue +++ b/ui/src/components/admin/ConfigView.vue @@ -255,10 +255,13 @@ export default class extends Vue { public on_open(ready: () => void, fail: () => void): void { Promise.all([ + this.store.update(), this.$advent22.api_get("admin/config_model"), this.$advent22.api_get("admin/doors"), ]) - .then(([admin_config_model, doors]) => { + .then(([store_update, admin_config_model, doors]) => { + store_update; // discard value + this.admin_config_model = admin_config_model; this.doors = doors; diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 681a09e..6547db4 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -60,53 +60,72 @@ export const advent22Store = defineStore({ actions: { init(): void { - this.update_is_admin(); - - this.advent22 - .api_get_blob("user/favicon") - .then((favicon_src) => { - const link: HTMLLinkElement = - document.querySelector("link[rel*='icon']") || - document.createElement("link"); - link.rel = "shortcut icon"; - link.type = "image/x-icon"; - link.href = favicon_src; - - if (link.parentElement === null) - document.getElementsByTagName("head")[0].appendChild(link); - }) - .catch(() => {}); - - Promise.all([ - this.advent22.api_get("user/site_config"), - this.advent22.api_get_blob("user/background_image"), - this.advent22.api_get("user/doors"), - this.advent22.api_get("user/next_door"), - ]) - .then(([site_config, background_image, user_doors, next_door]) => { - document.title = site_config.title; - - if (site_config.subtitle !== "") - document.title += " – " + site_config.subtitle; - - this.site_config = site_config; - - this.calendar_background_image = background_image; - - this.user_doors.length = 0; - for (const door_saved of user_doors) { - this.user_doors.push(Door.load(door_saved)); - } - - if (next_door !== null) - this.next_door_target = Date.now() + next_door; - + this.update() + .then(() => { this.is_initialized = true; for (const callback of this.on_initialized) callback(); }) .catch(this.advent22.alert_user_error); }, + update(): Promise { + return new Promise((resolve, reject) => { + this.advent22 + .api_get_blob("user/favicon") + .then((favicon_src) => { + const link: HTMLLinkElement = + document.querySelector("link[rel*='icon']") || + document.createElement("link"); + link.rel = "shortcut icon"; + link.type = "image/x-icon"; + link.href = favicon_src; + + if (link.parentElement === null) + document.getElementsByTagName("head")[0].appendChild(link); + }) + .catch(() => {}); + + Promise.all([ + this.update_is_admin(), + this.advent22.api_get("user/site_config"), + this.advent22.api_get_blob("user/background_image"), + this.advent22.api_get("user/doors"), + this.advent22.api_get("user/next_door"), + ]) + .then( + ([ + is_admin, + site_config, + background_image, + user_doors, + next_door, + ]) => { + is_admin; // discard value + + document.title = site_config.title; + + if (site_config.subtitle !== "") + document.title += " – " + site_config.subtitle; + + this.site_config = site_config; + + this.calendar_background_image = background_image; + + this.user_doors.length = 0; + for (const door_saved of user_doors) { + this.user_doors.push(Door.load(door_saved)); + } + + if (next_door !== null) + this.next_door_target = Date.now() + next_door; + + resolve(); + }, + ) + .catch(reject); + }); + }, + when_initialized(callback: () => void): void { if (this.is_initialized) { callback();