From 7643f35ec5e2101090a42ddf6dd73d76eec43627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sun, 28 Dec 2025 02:34:41 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20ui:=20minor=20refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove helper `loading_success` - typing in `ThouCanvas` - internal renamings and logic optimizations --- ui/src/components/bulma/Toast.vue | 2 +- ui/src/components/calendar/SVGRect.vue | 10 ++++++---- ui/src/components/calendar/ThouCanvas.vue | 22 ++++++++++++---------- ui/src/lib/helpers.ts | 15 ++++----------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/ui/src/components/bulma/Toast.vue b/ui/src/components/bulma/Toast.vue index cd5d985..5fb3525 100644 --- a/ui/src/components/bulma/Toast.vue +++ b/ui/src/components/bulma/Toast.vue @@ -25,7 +25,7 @@ const message = useTemplateRef("message"); onMounted(() => emit("handle", { show(options: ToastOptions = {}) { - if (!(message.value instanceof HTMLElement)) return; + if (message.value === null) return; toast({ ...options, diff --git a/ui/src/components/calendar/SVGRect.vue b/ui/src/components/calendar/SVGRect.vue index ed4f205..7e96918 100644 --- a/ui/src/components/calendar/SVGRect.vue +++ b/ui/src/components/calendar/SVGRect.vue @@ -20,7 +20,7 @@ diff --git a/ui/src/components/calendar/ThouCanvas.vue b/ui/src/components/calendar/ThouCanvas.vue index f3c5eba..89cc816 100644 --- a/ui/src/components/calendar/ThouCanvas.vue +++ b/ui/src/components/calendar/ThouCanvas.vue @@ -29,21 +29,23 @@ function get_event_thous(event: MouseEvent): Vector2D { ); } +type TCEventType = "mousedown" | "mousemove" | "mouseup" | "click" | "dblclick"; + +const is_tceventtype = (t: unknown): t is TCEventType => + t === "mousedown" || + t === "mousemove" || + t === "mouseup" || + t === "click" || + t === "dblclick"; + const emit = defineEmits<{ - (event: "mousedown", e: MouseEvent, point: Vector2D): void; - (event: "mouseup", e: MouseEvent, point: Vector2D): void; - (event: "mousemove", e: MouseEvent, point: Vector2D): void; - (event: "click", e: MouseEvent, point: Vector2D): void; - (event: "dblclick", e: MouseEvent, point: Vector2D): void; + (event: TCEventType, e: MouseEvent, point: Vector2D): void; }>(); function transform_mouse_event(event: MouseEvent) { - const point = get_event_thous(event); + if (!is_tceventtype(event.type)) return; - // mute a useless typescript error - const event_type = event.type as "mousedown"; - - emit(event_type, event, point); + emit(event.type, event, get_event_thous(event)); } diff --git a/ui/src/lib/helpers.ts b/ui/src/lib/helpers.ts index cd6fcf3..36bff86 100644 --- a/ui/src/lib/helpers.ts +++ b/ui/src/lib/helpers.ts @@ -20,29 +20,22 @@ export function unwrap_vuelike(value: VueLike): T { export type Loading = T | "loading" | "error"; -export function loading_success(o: Loading): o is T { - if (o === "loading") return false; - if (o === "error") return false; - - return true; -} - export function unwrap_loading(o: Loading): T { - if (!loading_success(o)) throw null; + if (o === "loading" || o === "error") throw null; return o; } export function wait_for(condition: () => boolean, action: () => void) { - const do_action = () => { + const enqueue_action = () => { if (!condition()) { - nextTick(do_action); + nextTick(enqueue_action); return; } action(); }; - do_action(); + enqueue_action(); } export function handle_error(error: unknown) {