🔧 ui: minor code cleanups

This commit is contained in:
Jörn-Michael Miehe 2025-12-28 16:39:24 +00:00
parent 4bab74b852
commit 956d373b28
6 changed files with 19 additions and 39 deletions

View file

@ -16,7 +16,7 @@
ref="username_input" ref="username_input"
class="input" class="input"
type="text" type="text"
v-model="username" v-model="creds[0]"
/> />
</div> </div>
</div> </div>
@ -24,7 +24,7 @@
<div class="field"> <div class="field">
<label class="label">Passwort</label> <label class="label">Passwort</label>
<div class="control"> <div class="control">
<input class="input" type="password" v-model="password" /> <input class="input" type="password" v-model="creds[1]" />
</div> </div>
</div> </div>
</section> </section>
@ -33,13 +33,13 @@
<BulmaButton <BulmaButton
class="is-success" class="is-success"
@click.left="submit" @click.left="submit"
:icon="['fas', 'fa-unlock']" :icon="['fas', 'fa-unlock']"
text="Login" text="Login"
/> />
<BulmaButton <BulmaButton
class="is-danger" class="is-danger"
@click.left="cancel" @click.left="cancel"
:icon="['fas', 'fa-circle-xmark']" :icon="['fas', 'fa-circle-xmark']"
text="Abbrechen" text="Abbrechen"
/> />
</footer> </footer>
@ -60,11 +60,10 @@ const emit = defineEmits<{
(event: "cancel"): void; (event: "cancel"): void;
}>(); }>();
const username = ref(""); const creds = ref<Credentials>(["", ""]);
const password = ref("");
function submit(): void { function submit(): void {
emit("submit", [username.value, password.value]); emit("submit", creds.value);
} }
function cancel(): void { function cancel(): void {

View file

@ -39,7 +39,6 @@ export type HMultiModal = {
show_image(src: string, caption: string): void; show_image(src: string, caption: string): void;
show_loading(): void; show_loading(): void;
hide(): void; hide(): void;
dismiss(): void;
}; };
const emit = defineEmits<{ const emit = defineEmits<{
@ -65,7 +64,6 @@ onMounted(() => {
state.value = { show: "loading" }; state.value = { show: "loading" };
}, },
hide, hide,
dismiss,
}); });
const on_keydown = (e: KeyboardEvent) => { const on_keydown = (e: KeyboardEvent) => {

View file

@ -254,7 +254,7 @@ async function on_open(): Promise<void> {
API.request<DoorSaved[]>("admin/doors"), API.request<DoorSaved[]>("admin/doors"),
]); ]);
void store_update; void store_update; // discard value
admin_config_model.value = new_admin_config_model; admin_config_model.value = new_admin_config_model;
doors.value = new_doors; doors.value = new_doors;
} }

View file

@ -50,26 +50,20 @@ const preview_visible = computed(() => state.value.kind !== "idle");
function pop_door(point: Vector2D): VueLike<Door> | undefined { function pop_door(point: Vector2D): VueLike<Door> | undefined {
const idx = model.value.findIndex((rect) => rect.position.contains(point)); const idx = model.value.findIndex((rect) => rect.position.contains(point));
if (idx === -1) { if (idx === -1) return;
return;
}
return model.value.splice(idx, 1)[0]; return model.value.splice(idx, 1)[0];
} }
function draw_start(event: MouseEvent, point: Vector2D): void { function draw_start(event: MouseEvent, point: Vector2D): void {
if (preview_visible.value) { if (preview_visible.value) return;
return;
}
preview.value = new Rectangle(point, point); preview.value = new Rectangle(point, point);
state.value = { kind: "drawing" }; state.value = { kind: "drawing" };
} }
function draw_finish(): void { function draw_finish(): void {
if (state.value.kind !== "drawing") { if (state.value.kind !== "drawing") return;
return;
}
if (preview.value.area >= MIN_RECT_AREA) { if (preview.value.area >= MIN_RECT_AREA) {
model.value.push(new Door(preview.value)); model.value.push(new Door(preview.value));
@ -79,15 +73,11 @@ function draw_finish(): void {
} }
function drag_start(event: MouseEvent, point: Vector2D): void { function drag_start(event: MouseEvent, point: Vector2D): void {
if (preview_visible.value) { if (preview_visible.value) return;
return;
}
const drag_door = pop_door(point); const drag_door = pop_door(point);
if (drag_door === undefined) { if (drag_door === undefined) return;
return;
}
preview.value = drag_door.position; preview.value = drag_door.position;
@ -95,9 +85,7 @@ function drag_start(event: MouseEvent, point: Vector2D): void {
} }
function drag_finish(): void { function drag_finish(): void {
if (state.value.kind !== "dragging") { if (state.value.kind !== "dragging") return;
return;
}
model.value.push(new Door(preview.value, state.value.door.day)); model.value.push(new Door(preview.value, state.value.door.day));
@ -114,9 +102,7 @@ function on_mousemove(event: MouseEvent, point: Vector2D): void {
} }
function remove_rect(event: MouseEvent, point: Vector2D): void { function remove_rect(event: MouseEvent, point: Vector2D): void {
if (preview_visible.value) { if (preview_visible.value) return;
return;
}
pop_door(point); pop_door(point);
} }

View file

@ -41,9 +41,7 @@ function toggle_editing(): void {
} }
function on_click(event: MouseEvent): void { function on_click(event: MouseEvent): void {
if (!(event.target instanceof HTMLDivElement)) { if (!(event.target instanceof HTMLDivElement)) return;
return;
}
if (editing.value) { if (editing.value) {
unwrap_vuelike(model.value).day = day_str.value; unwrap_vuelike(model.value).day = day_str.value;
@ -58,9 +56,7 @@ function on_click(event: MouseEvent): void {
} }
function on_keydown(event: KeyboardEvent): void { function on_keydown(event: KeyboardEvent): void {
if (!editing.value) { if (!editing.value) return;
return;
}
if (event.key === "Enter") { if (event.key === "Enter") {
unwrap_vuelike(model.value).day = day_str.value; unwrap_vuelike(model.value).day = day_str.value;

View file

@ -76,7 +76,7 @@ export const advent22Store = defineStore({
API.request<DoorSaved[]>("user/doors"), API.request<DoorSaved[]>("user/doors"),
API.request<number | null>("user/next_door"), API.request<number | null>("user/next_door"),
]); ]);
is_admin; // discard value void is_admin; // discard value
document.title = site_config.title; document.title = site_config.title;
@ -116,7 +116,8 @@ export const advent22Store = defineStore({
}, },
logout() { logout() {
return this.login(["", ""]); API.creds = { username: "", password: "" };
this.is_admin = false;
}, },
toggle_touch_device(): void { toggle_touch_device(): void {