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