Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): cover chat header with phone app dialog backdrop
Zidan Zhu6dc8edee4565
diff --git a/src/components/PhoneAppDialog.dom.test.ts b/src/components/PhoneAppDialog.dom.test.tsnew file mode 100644index 0000000000..3c3c2fb90c--- /dev/null+++ b/src/components/PhoneAppDialog.dom.test.ts@@ -0,0 +1,85 @@+// @vitest-environment happy-dom+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import { setLocale } from "@/lib/i18n";+import { GlassBar } from "./GlassScrollFrame";+import { PhoneAppDialog, type PhoneAppConnect } from "./PhoneAppDialog";++let host: HTMLDivElement;+let root: Root;+const close = vi.fn();++beforeEach(() => {+ setLocale("en");+ close.mockReset();+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+});++afterEach(() => {+ flushSync(() => root.unmount());+ host.remove();+});++function render(open = true, connect: PhoneAppConnect[] = []) {+ flushSync(() => root.render(createElement(GlassBar, {+ edge: "top",+ children: createElement(PhoneAppDialog, { open, onClose: close, connect }),+ })));+}++const dialog = () => document.querySelector<HTMLElement>("[role=dialog]");+const backdrop = () => dialog()!.parentElement!;+const button = (text: string) => Array.from(dialog()!.querySelectorAll("button")).find(item => item.textContent === text)!;++it("mounts the full-window backdrop outside the sidebar's glass stacking context", () => {+ render();+ expect(backdrop().parentElement).toBe(document.body);+ expect(backdrop().closest("[data-glass-bar]")).toBeNull();+ expect(host.querySelector("[role=dialog]")).toBeNull();+ expect(dialog()!.querySelectorAll("svg")).toHaveLength(2);+});++it("also escapes a transformed sidebar's fixed-position containing block", () => {+ host.style.transform = "translateX(0)";+ render();+ expect(backdrop().parentElement).toBe(document.body);+ expect(host.contains(backdrop())).toBe(false);+});++it("focuses Close and keeps the close button and Escape working after portalling", () => {+ render();+ expect(document.activeElement).toBe(button("Close"));+ flushSync(() => button("Close").click());+ expect(close).toHaveBeenCalledTimes(1);+ flushSync(() => window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", cancelable: true })));+ expect(close).toHaveBeenCalledTimes(2);+});++it("closes on a backdrop press while a press inside the card leaves it open", () => {+ render();+ flushSync(() => dialog()!.dispatchEvent(new MouseEvent("mousedown", { bubbles: true })));+ expect(close).not.toHaveBeenCalled();+ flushSync(() => backdrop().dispatchEvent(new MouseEvent("mousedown", { bubbles: true })));+ expect(close).toHaveBeenCalledTimes(1);+});++it("closes before opening the selected pairing destination", () => {+ const select = vi.fn();+ render(true, [{ key: "here", subtitle: "to this computer", onSelect: select }]);+ flushSync(() => dialog()!.querySelector<HTMLButtonElement>("[data-phone-app-connect=here]")!.click());+ expect(close).toHaveBeenCalledTimes(1);+ expect(select).toHaveBeenCalledTimes(1);+ expect(close.mock.invocationCallOrder[0]).toBeLessThan(select.mock.invocationCallOrder[0]!);+});++it("removes the portal and its Escape handler when closed", () => {+ render();+ render(false);+ expect(dialog()).toBeNull();+ window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));+ expect(close).not.toHaveBeenCalled();+});diff --git a/src/components/PhoneAppDialog.tsx b/src/components/PhoneAppDialog.tsxindex 5cf56468c5..7f98e0060b 100644--- a/src/components/PhoneAppDialog.tsx+++ b/src/components/PhoneAppDialog.tsx@@ -1,4 +1,5 @@import { useEffect, useRef } from "react";+import { createPortal } from "react-dom";import { QRCodeSVG } from "qrcode.react";import { ANDROID_APK_URL, IOS_APP_STORE_URL, openExternalLink } from "@/lib/app-links";@@ -34,7 +35,7 @@ export function PhoneAppDialog({ open, onClose, connect = [] }: { open: boolean;if (!open) return null;- return (+ const overlay = (<divclassName="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6"onMouseDown={(event) => event.target === event.currentTarget && onClose()}@@ -95,4 +96,6 @@ export function PhoneAppDialog({ open, onClose, connect = [] }: { open: boolean;</div></div>);++ return typeof document === "undefined" ? overlay : createPortal(overlay, document.body);}