Page: place the player's echo before the request, show an answer under its question, scroll after the retry row

This commit is contained in:
Meta Vens 2026-12-02 21:09:36 +01:00
commit 4e067a073a

View file

@ -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 + ").")));
}