send form: submit via fetch so live view stays put

This commit is contained in:
müde 2026-05-15 16:05:51 +02:00
parent f83c0aa717
commit 0a24946c1e

View file

@ -104,11 +104,27 @@ async fn index(State(state): State<AppState>) -> Html<String> {
fn render_online(label: &str) -> String { fn render_online(label: &str) -> String {
format!( format!(
"<p class=\"status-online\">▓█▓▒░ harness alive — turn loop running ▓█▓▒░</p>\n\ "<p class=\"status-online\">▓█▓▒░ harness alive — turn loop running ▓█▓▒░</p>\n\
<form method=\"POST\" action=\"/send\" class=\"sendform\">\n \ <form id=\"sendform\" class=\"sendform\">\n \
<input name=\"body\" placeholder=\"message {label} as operator…\" required autocomplete=\"off\">\n \ <input id=\"sendbody\" name=\"body\" placeholder=\"message {label} as operator…\" required autocomplete=\"off\">\n \
<button type=\"submit\" class=\"btn btn-send\">◆ S3ND</button>\n\ <button type=\"submit\" class=\"btn btn-send\">◆ S3ND</button>\n\
</form>\n\ </form>\n\
<p class=\"meta\">enqueued with <code>from: operator</code> on this agent's inbox; the next turn picks it up.</p>\n\ <p class=\"meta\">enqueued with <code>from: operator</code> on this agent's inbox; the next turn picks it up.</p>\n\
<script>\n\
document.getElementById('sendform').addEventListener('submit', async function(e) {{\n \
e.preventDefault();\n \
const input = document.getElementById('sendbody');\n \
const body = input.value.trim();\n \
if (!body) return;\n \
const fd = new FormData();\n \
fd.set('body', body);\n \
const resp = await fetch('/send', {{ method: 'POST', body: fd, redirect: 'manual' }});\n \
if (resp.type === 'opaqueredirect' || (resp.ok && resp.status < 400)) {{\n \
input.value = '';\n \
}} else {{\n \
alert('send failed: ' + resp.status);\n \
}}\n\
}});\n\
</script>\n\
{LIVE_PANEL}", {LIVE_PANEL}",
) )
} }