Public: anyone can read this; the crew can change it.
/talk keeps an unsent line across a reload and clears it once sent #14152
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14126-talk-keeps-an-unsent-line-across-a-reloa → main 3 commits fork
2 files
changed +5
−5
src/web/pages/talk_client.ts +4 −4
| @@ -130,8 +130,8 @@ if (root) { | ||
| 130 | 130 | jump.addEventListener("click", () => { stuck = true; toEnd(true); box.focus(); }); |
| 131 | 131 | const draftKey = "talk-draft:" + (root.dataset.user || "") + ":" + (cid || ""); |
| 132 | 132 | let draftTimer = 0; |
| 133 | const saveDraft = () => { clearTimeout(draftTimer); try { if (box.value) localStorage.setItem(draftKey, box.value); else localStorage.removeItem(draftKey); } catch (_) {} }; | |
| 134 | try { if (!box.value) box.value = localStorage.getItem(draftKey) || ""; } catch (_) {} | |
| 133 | const saveDraft = () => { clearTimeout(draftTimer); try { if (box.value) sessionStorage.setItem(draftKey, box.value); else sessionStorage.removeItem(draftKey); } catch (_) {} }; | |
| 134 | try { if (!box.value) box.value = sessionStorage.getItem(draftKey) || ""; } catch (_) {} | |
| 135 | 135 | const grow = () => { box.style.height = "auto"; box.style.height = Math.min(box.scrollHeight, window.innerHeight * 0.4) + "px"; }; |
| 136 | 136 | box.addEventListener("input", () => { |
| 137 | 137 | grow(); |
| @@ -325,7 +325,7 @@ if (root) { | ||
| 325 | 325 | const text = box.value.trim(); |
| 326 | 326 | if (!text) { if (attached.length) say("Add a few words about what you attached."); return; } |
| 327 | 327 | if (editing) { |
| 328 | if (await again("edit", new URLSearchParams({ text }))) { clearTimeout(draftTimer); try { localStorage.removeItem(draftKey); } catch (_) {} } | |
| 328 | if (await again("edit", new URLSearchParams({ text }))) { clearTimeout(draftTimer); try { sessionStorage.removeItem(draftKey); } catch (_) {} } | |
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | const steer = e.submitter === steerBtn; |
| @@ -346,7 +346,7 @@ if (root) { | ||
| 346 | 346 | chips.replaceChildren(); |
| 347 | 347 | grow(); |
| 348 | 348 | clearTimeout(draftTimer); |
| 349 | try { localStorage.removeItem(draftKey); } catch (_) {} | |
| 349 | try { sessionStorage.removeItem(draftKey); } catch (_) {} | |
| 350 | 350 | stuck = true; |
| 351 | 351 | const out = await res.json().catch(() => ({})); |
| 352 | 352 | if (out.how === "queued") { say("Queued: it sends after this answer."); if (!source) follow(); return; } |
test/talk-page.test.ts +1 −1
| @@ -392,7 +392,7 @@ describe("the page", () => { | ||
| 392 | 392 | const nav = { clipboard: { writeText: async (t: string) => { copied.push(t); } } }; |
| 393 | 393 | class ES { on: Record<string, (e: { data: string }) => void> = {}; constructor() { sources.push(this); } addEventListener(n: string, f: (e: { data: string }) => void) { this.on[n] = f; } close() {} } |
| 394 | 394 | doc.getElementById("end").scrollIntoView = () => {}; |
| 395 | new Function("document", "window", "EventSource", "fetch", "localStorage", "navigator", talkJs)(doc, window, ES, fetchStub, local, nav); | |
| 395 | new Function("document", "window", "EventSource", "fetch", "sessionStorage", "navigator", talkJs)(doc, window, ES, fetchStub, local, nav); | |
| 396 | 396 | const box = doc.querySelector("textarea"); |
| 397 | 397 | const key = (init: object) => box.dispatchEvent(new window.KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true, ...init })); |
| 398 | 398 | const emit = (id: string, html: string) => sources.at(-1)!.on["turn"]!({ data: JSON.stringify({ id, html }) }); |
new above
offline