// @flow import /*:: ProgressSpinner from */ "../web_modules/elix/define/ProgressSpinner.js"; import { cast } from "../cms2/types.js"; const template = document.createElement('template'); template.innerHTML = `
Edit Message
`; export class MlkLazychatSubmissionForm extends HTMLElement { /*:: mainForm: HTMLFormElement; textInput: HTMLTextAreaElement; visibilityInput: HTMLInputElement; loaded: boolean; */ constructor() { super(); this.loaded = false; } static get observedAttributes() { return []; } show() { this.createShadow(); } createShadow() { if (this.shadowRoot !== null) { return; } 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')); if (this.editedId !== null) { this.mainForm.method = "post"; this.mainForm.action = `/lazychat/${this.editedId}/edit`; } } get editedId() /*:number | null*/ { let attr = this.getAttribute("edited-id"); if (attr === null) { return null; } return parseInt(attr, 10); } get isEditor() { return this.editedId !== null; } connectedCallback() {} disconnectedCallback() {} attributeChangedCallback(name /*:string*/, oldValue /*:string*/, newValue /*:string*/) {} focus() { this.show(); this.textInput.focus(); this.load(); } async load() { if (this.editedId === null || this.loaded) { return; } let fetchUrl = new URL(`/posts/${this.editedId}`, document.URL); let r = await fetch(fetchUrl, {headers: {"accept": "application/json"}}); if (!r.ok) { return; } let post = await r.json(); this.visibilityInput.value = post.visibility; if (post.texts['']) { this.textInput.value = post.texts[''].content; } this.loaded = true; } } customElements.define("mlk-lazychat-submission-form", MlkLazychatSubmissionForm);