From 560beb0a446934933f9bfa0ff6e646c0e14a86cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 7 Sep 2023 00:34:42 +0000 Subject: [PATCH] improve `Door` integer coercion, remove PreviewDoor.editable --- ui/src/components/door_map/PreviewDoor.vue | 16 +++------------- ui/src/components/door_map/calendar.ts | 11 +++++++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ui/src/components/door_map/PreviewDoor.vue b/ui/src/components/door_map/PreviewDoor.vue index b58ed96..bb738b8 100644 --- a/ui/src/components/door_map/PreviewDoor.vue +++ b/ui/src/components/door_map/PreviewDoor.vue @@ -26,16 +26,11 @@ import SVGRect from "../rects/SVGRect.vue"; }, props: { door: Door, - editable: { - type: Boolean, - default: true, - }, }, emits: ["update:door"], }) export default class extends Vue { public door!: Door; - private editable!: boolean; public day_str = ""; public editing = false; @@ -74,14 +69,9 @@ export default class extends Vue { return result; } - private get day_num(): number { - const result = Number(this.day_str); - return isNaN(result) ? -1 : result; - } - private toggle_editing() { this.day_str = String(this.door.day); - this.editing = this.editable && !this.editing; + this.editing = !this.editing; } public on_click(event: MouseEvent) { @@ -100,7 +90,7 @@ export default class extends Vue { }; day_input_focus(); } else { - this.door.day = this.day_num; + this.door.day = this.day_str; } this.toggle_editing(); @@ -112,7 +102,7 @@ export default class extends Vue { } if (event.key === "Enter") { - this.door.day = this.day_num; + this.door.day = this.day_str; this.toggle_editing(); } else if (event.key === "Delete") { this.door.day = -1; diff --git a/ui/src/components/door_map/calendar.ts b/ui/src/components/door_map/calendar.ts index 035b230..5b17511 100644 --- a/ui/src/components/door_map/calendar.ts +++ b/ui/src/components/door_map/calendar.ts @@ -13,7 +13,14 @@ export class Door { return this._day } - public set day(day: number) { - this._day = Math.max(Math.floor(day), -1); + public set day(day: unknown) { + // integer coercion + const result = Number(day); + + if (isNaN(result)) { + this._day = -1; + } else { + this._day = Math.max(Math.floor(result), -1); + } } } \ No newline at end of file