store: catch failure to load from API
This commit is contained in:
parent
af5abc7c8f
commit
d0d81510cc
1 changed files with 23 additions and 19 deletions
|
@ -67,30 +67,34 @@ export const advent22Store = defineStore({
|
||||||
document.getElementsByTagName("head")[0].appendChild(link);
|
document.getElementsByTagName("head")[0].appendChild(link);
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
const [is_admin, site_config, background_image, user_doors, next_door] =
|
try {
|
||||||
await Promise.all([
|
const [is_admin, site_config, background_image, user_doors, next_door] =
|
||||||
this.update_is_admin(),
|
await Promise.all([
|
||||||
API.request<SiteConfigModel>("user/site_config"),
|
this.update_is_admin(),
|
||||||
API.request<ImageData>("user/background_image"),
|
API.request<SiteConfigModel>("user/site_config"),
|
||||||
API.request<DoorSaved[]>("user/doors"),
|
API.request<ImageData>("user/background_image"),
|
||||||
API.request<number | null>("user/next_door"),
|
API.request<DoorSaved[]>("user/doors"),
|
||||||
]);
|
API.request<number | null>("user/next_door"),
|
||||||
is_admin; // discard value
|
]);
|
||||||
|
is_admin; // discard value
|
||||||
|
|
||||||
document.title = site_config.title;
|
document.title = site_config.title;
|
||||||
|
|
||||||
if (site_config.subtitle !== "")
|
if (site_config.subtitle !== "")
|
||||||
document.title += " – " + site_config.subtitle;
|
document.title += " – " + site_config.subtitle;
|
||||||
|
|
||||||
this.site_config = site_config;
|
this.site_config = site_config;
|
||||||
this.background_image = background_image;
|
this.background_image = background_image;
|
||||||
|
|
||||||
this.user_doors.length = 0;
|
this.user_doors.length = 0;
|
||||||
for (const door_saved of user_doors) {
|
for (const door_saved of user_doors) {
|
||||||
this.user_doors.push(Door.load(door_saved));
|
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 {
|
when_initialized(callback: () => void): void {
|
||||||
|
|
Loading…
Reference in a new issue