store: catch failure to load from API

This commit is contained in:
Jörn-Michael Miehe 2024-08-26 19:13:08 +00:00
parent af5abc7c8f
commit d0d81510cc

View file

@ -67,30 +67,34 @@ export const advent22Store = defineStore({
document.getElementsByTagName("head")[0].appendChild(link);
} catch {}
const [is_admin, site_config, background_image, user_doors, next_door] =
await Promise.all([
this.update_is_admin(),
API.request<SiteConfigModel>("user/site_config"),
API.request<ImageData>("user/background_image"),
API.request<DoorSaved[]>("user/doors"),
API.request<number | null>("user/next_door"),
]);
is_admin; // discard value
try {
const [is_admin, site_config, background_image, user_doors, next_door] =
await Promise.all([
this.update_is_admin(),
API.request<SiteConfigModel>("user/site_config"),
API.request<ImageData>("user/background_image"),
API.request<DoorSaved[]>("user/doors"),
API.request<number | null>("user/next_door"),
]);
is_admin; // discard value
document.title = site_config.title;
document.title = site_config.title;
if (site_config.subtitle !== "")
document.title += " " + site_config.subtitle;
if (site_config.subtitle !== "")
document.title += " " + site_config.subtitle;
this.site_config = site_config;
this.background_image = background_image;
this.site_config = site_config;
this.background_image = background_image;
this.user_doors.length = 0;
for (const door_saved of user_doors) {
this.user_doors.push(Door.load(door_saved));
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;
} catch {
this.background_image = "error";
}
if (next_door !== null) this.next_door_target = Date.now() + next_door;
},
when_initialized(callback: () => void): void {