From 4e067a073abc1032414f70b313e8030e9ed70a8b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 21:09:36 +0100 Subject: [PATCH] Page: place the player's echo before the request, show an answer under its question, scroll after the retry row --- crates/ghostlight-dungeon/page/page.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ghostlight-dungeon/page/page.js b/crates/ghostlight-dungeon/page/page.js index 0018ec3..3123088 100644 --- a/crates/ghostlight-dungeon/page/page.js +++ b/crates/ghostlight-dungeon/page/page.js @@ -301,6 +301,7 @@ function renderLog() { if (entry.refusal) parts.push(el("p", { class: "line", role: "alert" }, entry.refusal)); if (entry.fault) parts.push(el("p", { class: "line", role: "alert" }, entry.fault)); if (entry.question) parts.push(el("div", { class: "ask" }, el("strong", {}, "The storyteller asks"), el("p", { class: "story" }, entry.question.text))); + if (entry.answer) parts.push(el("p", { class: "you" }, entry.answer)); const node = el("section", { class: "turn" }, parts); entry.node = node; return node; @@ -316,14 +317,18 @@ async function send(text, _unused, isRetry) { // The same text resent after a lost reply reuses its key, so it cannot play twice. if (!S.keyed || S.keyed.text !== text || isRetry) S.keyed = { text, key: uuid() }; $send.disabled = true; + // The echo is placed before the request: the stream can deliver the new turn before the reply returns. + if (answers && text) { last.answer = text; renderLog(); } else if (text) S.nextYou = text; const { status, body } = await post("play", { timeline: S.timeline, key: S.keyed.key, text, answers }); $send.disabled = false; if (status === 202 || status === 200) { - S.lastText = text || S.lastText; S.nextYou = text || null; S.keyed = null; + S.lastText = text || S.lastText; S.keyed = null; $text.value = ""; LS.set("draft:" + S.timeline, ""); $status.className = "status pulse"; $status.textContent = "Sent"; return; } + S.nextYou = null; if (last && answers) last.answer = null; + if (answers) renderLog(); $status.className = "status"; $retryRow.replaceChildren(errorLine(status === 0 ? "The server could not be reached. Your text is kept; Send resends it safely." : (body.error || "The turn was refused (" + status + ")."))); }