mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 16:23:00 +00:00
WIP: major refactoring
This commit is contained in:
parent
15b957791f
commit
e3e19a0572
1 changed files with 17 additions and 7 deletions
|
@ -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<SiteConfigModel>;
|
||||
site_config: SiteConfigModel;
|
||||
background_image: Loading<ImageData>;
|
||||
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<void> {
|
||||
await this.update();
|
||||
|
||||
if (this.on_initialized !== null) {
|
||||
for (const callback of this.on_initialized) callback();
|
||||
}
|
||||
this.on_initialized = null;
|
||||
},
|
||||
|
||||
async update(): Promise<void> {
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue