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:
parent
5fa427266a
commit
4e067a073a
1 changed files with 6 additions and 1 deletions
|
|
@ -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 + ").")));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue