MlkLazychatSubmissionForm: Make Flow type checker happy.
Change-Id: I39ad254ea853e657b82069580e369ab701eafd81
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 @@
export class MlkLazychatSubmissionForm extends HTMLElement {
/*::
+ mainForm: HTMLFormElement;
textInput: HTMLTextAreaElement;
visibilityInput: HTMLInputElement;
loaded: boolean;
@@ -41,10 +42,13 @@
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 @@
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 @@
}
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 @@
}
async load() {
- if (!this.editedId || this.loaded) {
+ if (this.editedId === null || this.loaded) {
return;
}