Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: the send button's off rule is a tested function

This commit is contained in:
iris 2026-11-16 18:12:01 +01:00
commit 2fe5759cdf
3 changed files with 18 additions and 1 deletions

View file

@ -29,6 +29,7 @@ import {
enterSends,
matchCommands,
menuQuery,
sendDisabled,
textToSend,
moveSelection,
type AgentCommand,
@ -135,7 +136,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
type="submit"
aria-label="send"
title="send"
disabled={submitting || body.trim() === ""}
disabled={sendDisabled(body, submitting)}
aria-busy={submitting || undefined}
>
{submitting ? <Spinner /> : <SendIcon />}

View file

@ -119,3 +119,11 @@ export function textToSend(text: string): string {
const trimmed = text.trim();
return menuQuery(trimmed) === null ? text : trimmed;
}
/**
* Whether the send button is off: while a send is under way, or when the box
* holds nothing but whitespace.
*/
export function sendDisabled(text: string, submitting: boolean): boolean {
return submitting || text.trim() === "";
}

View file

@ -9,6 +9,7 @@ import {
matchCommands,
menuQuery,
moveSelection,
sendDisabled,
splitName,
textToSend,
} from "../src/agent/terminal/command-menu.ts";
@ -127,3 +128,10 @@ test("any other message goes as it is", () => {
assert.equal(textToSend("fix /etc/hosts"), "fix /etc/hosts");
assert.equal(textToSend(" "), " ");
});
test("send is off while sending and for a box with only whitespace", () => {
assert.equal(sendDisabled("", false), true);
assert.equal(sendDisabled(" \n ", false), true);
assert.equal(sendDisabled("hi", true), true);
assert.equal(sendDisabled("hi", false), false);
});