add store.on_initialized hooks

- start Calendar.toast_timeout when initialized
This commit is contained in:
Jörn-Michael Miehe 2023-11-11 01:47:18 +00:00
parent a63344dfe1
commit 8c93a974e6
2 changed files with 21 additions and 4 deletions

View file

@ -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) {

View file

@ -14,6 +14,8 @@ declare global {
type State = {
advent22: Advent22;
api_creds: RemovableRef<Credentials>;
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<boolean> {
return new Promise((resolve, reject) => {
this.advent22