From 0fb9d12078b07947f8df732564477bd3f8eabaea Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 13 Apr 2020 21:31:40 +0200 Subject: MlkLazychatSubmissionForm: Make Flow type checker happy. Change-Id: I39ad254ea853e657b82069580e369ab701eafd81 --- .../resources/lazychat/MlkLazychatSubmissionForm.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js index 6cb3059..5b67cee 100644 --- a/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js +++ b/src/main/resources/META-INF/resources/lazychat/MlkLazychatSubmissionForm.js @@ -30,6 +30,7 @@ template.innerHTML = ` export class MlkLazychatSubmissionForm extends HTMLElement { /*:: + mainForm: HTMLFormElement; textInput: HTMLTextAreaElement; visibilityInput: HTMLInputElement; loaded: boolean; @@ -41,10 +42,13 @@ export class MlkLazychatSubmissionForm extends HTMLElement { let shadow = this.attachShadow({mode: "open"}); shadow.appendChild(template.content.cloneNode(true)); + this.mainForm = + cast(shadow.getElementById('main-form')); this.textInput = cast(shadow.getElementById('text-input')); this.visibilityInput = cast(shadow.getElementById('visibility-input')); + this.loaded = false; } @@ -52,8 +56,12 @@ export class MlkLazychatSubmissionForm extends HTMLElement { return []; } - get editedId() { - return this.getAttribute("edited-id"); + get editedId() /*:number | null*/ { + let attr = this.getAttribute("edited-id"); + if (attr === undefined || attr === null) { + return null; + } + return parseInt(attr); } get isEditor() { @@ -61,10 +69,9 @@ export class MlkLazychatSubmissionForm extends HTMLElement { } connectedCallback() { - if (this.isEditor) { - let form = this.shadowRoot.getElementById("main-form"); - form.method = "post"; - form.action = `/lazychat/p/${this.editedId}/edit`; + if (this.editedId !== null) { + this.mainForm.method = "post"; + this.mainForm.action = `/lazychat/p/${this.editedId}/edit`; } } @@ -78,7 +85,7 @@ export class MlkLazychatSubmissionForm extends HTMLElement { } async load() { - if (!this.editedId || this.loaded) { + if (this.editedId === null || this.loaded) { return; } -- cgit v1.2.3