Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(connect): an address typed key by key stays in its box

Absterrg0af16f9ba7133
diff --git a/src/components/PlaceAddSheet.tsx b/src/components/PlaceAddSheet.tsx
index b9cf0a4bf5..3d8ae5c933 100644
--- a/src/components/PlaceAddSheet.tsx
+++ b/src/components/PlaceAddSheet.tsx
@@ -74,7 +74,7 @@ export function OwnServerLink({ onBack, onConnected, connect = null, start = nul
}, 400);
return () => { current = false; window.clearTimeout(timer); };
}, [address, code, canProbe, workspaces]);
- const typeAddress = (value: string) => {
+ const typeAddress = (value: string, pasted: boolean) => {
setFailure(null);
const read = parseServerInput(value);
if (!read.ok && read.problem === "codeOnly" && read.code) {
@@ -84,7 +84,7 @@ export function OwnServerLink({ onBack, onConnected, connect = null, start = nul
return;
}
setAddress(value);
- if (read.ok && read.code === null && read.credential === null) window.setTimeout(() => codeField.current?.focus(), 0);
+ if (pasted && read.ok && read.code === null && read.credential === null) window.setTimeout(() => codeField.current?.focus(), 0);
};
const found = probe?.outcome === "found" ? probe : null;
const submit = async (event: FormEvent) => {
@@ -111,7 +111,7 @@ export function OwnServerLink({ onBack, onConnected, connect = null, start = nul
{onBack && <div><BackLink label={t("rail.back")} onClick={onBack} /></div>}
<Heading title={connect ? t("rail.connectTitle", { name: connect.name }) : start?.title ?? t("connect.title")} sub={t(connect ? "connect.signedInLede" : "connect.lede")} />
<label className="flex flex-col gap-1.5 text-[13px] font-medium text-ink">{t("connect.address")}
- <input data-autofocus={start?.locked ? undefined : true} data-own-server-link value={address} disabled={busy} readOnly={start?.locked === true} onChange={(event) => { if (!start?.locked) typeAddress(event.target.value); }}
+ <input data-autofocus={start?.locked ? undefined : true} data-own-server-link value={address} disabled={busy} readOnly={start?.locked === true} onChange={(event) => { if (!start?.locked) typeAddress(event.target.value, (event.nativeEvent as InputEvent).inputType === "insertFromPaste"); }}
placeholder={t("connect.addressPlaceholder")} autoCapitalize="none" autoCorrect="off" autoComplete="off" spellCheck={false} aria-invalid={Boolean(shownProblem) || undefined}
className="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] font-normal text-ink outline-none focus:border-accent/50" />
</label>
diff --git a/src/components/PlacesRail.test.ts b/src/components/PlacesRail.test.ts
index bae96726ad..910e7fd19b 100644
--- a/src/components/PlacesRail.test.ts
+++ b/src/components/PlacesRail.test.ts
@@ -285,6 +285,29 @@ it("Connect to a server says plainly that another computer's desktop app can't b
expect(form.querySelector("[data-connect-problem]")?.textContent).toContain("That 6-digit code pairs a phone with a desktop app");
});
+it("an address typed key by key stays in its box; a pasted one moves on to the code", async () => {
+ await mount(createElement(PlacesRail));
+ await click(host.querySelector("[data-rail-add]"));
+ await click(document.querySelector('[data-place-add-choice="server"]'));
+ const form = document.querySelector('[data-place-add="own-server"]')!;
+ const address = form.querySelector("[data-own-server-link]") as HTMLInputElement;
+ const afterTimers = () => act(async () => { await new Promise((done) => setTimeout(done, 0)); });
+ for (const key of "maus.local") {
+ const focused = document.activeElement as HTMLInputElement;
+ await type(focused, focused.value + key);
+ await afterTimers();
+ }
+ expect([address.value, (form.querySelector("[data-own-server-code]") as HTMLInputElement).value]).toEqual(["maus.local", ""]);
+ expect(document.activeElement).toBe(address);
+ await type(address, "");
+ await act(async () => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(address, "192.168.1.20:8799");
+ address.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste" }));
+ });
+ await afterTimers();
+ expect(document.activeElement).toBe(form.querySelector("[data-own-server-code]"));
+});
+
it("Connect to a server takes an address and a code typed apart: a code pasted alone moves to its field, and main names the server it found", async () => {
const probe = vi.fn(async (address: string): Promise<unknown> => (address.includes("192.168.1.20")
? { outcome: "found", origin: "http://192.168.1.20:8799", label: "kitchen-box", version: "0.1.147", transport: "private-http", code: null, credential: null }