Skip to content

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

Page card: turn Point off when the open page asks to be closed

luishron1236c5557db3fa8
diff --git a/src/components/app/AppMessage.compact.test.ts b/src/components/app/AppMessage.compact.test.ts
index 3820f54bba..32df600737 100644
--- a/src/components/app/AppMessage.compact.test.ts
+++ b/src/components/app/AppMessage.compact.test.ts
@@ -97,6 +97,26 @@ describe("a bot's page as a compact card", () => {
expect(pane.querySelector("[data-page-pane]")).toBeNull();
});
+ it("turns Point off when the open page asks to be closed, so the card opens it again", async () => {
+ for (const room of [false, true]) {
+ await render(row(payload()), room);
+ await press(opener());
+ const opened = document.querySelector<HTMLElement>("[data-page-fullscreen=a1]")!;
+ const view = opened.querySelector("iframe")!.contentWindow!;
+ vi.spyOn(view, "postMessage").mockImplementation(() => {});
+ const point = Array.from(opened.querySelectorAll("button")).find((button) => button.textContent?.trim() === "Point")!;
+ await press(point);
+ expect(point.getAttribute("aria-pressed")).toBe("true");
+ for (const data of [{ id: "init", method: "ui/initialize" }, { method: "ui/notifications/initialized" }, { method: "ui/notifications/request-teardown" }]) {
+ await act(async () => { window.dispatchEvent(new MessageEvent("message", { data: { jsonrpc: "2.0", params: {}, ...data }, source: view as unknown as MessageEventSource })); });
+ }
+ await settle();
+ expect(document.querySelector("[data-page-fullscreen]")).toBeNull();
+ expect(opener().getAttribute("aria-pressed")).toBe("false");
+ expect(card().querySelector("[data-app-box]")!.hasAttribute("inert")).toBe(true);
+ }
+ });
+
it("keeps the card's own tools working without opening the page", async () => {
await render(row(payload()));
await press(card().querySelector<HTMLButtonElement>("[aria-label='About this app']")!);
diff --git a/src/components/app/AppMessage.tsx b/src/components/app/AppMessage.tsx
index 2811147ec6..f8214a63f5 100644
--- a/src/components/app/AppMessage.tsx
+++ b/src/components/app/AppMessage.tsx
@@ -333,7 +333,7 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {
/>
)}
{page && fullScreen && current && (
- <PageFullScreen {...tools} title={payload.title} doc={current} botId={botId} threadId={threadId} handle={wide} close={() => setFullScreen(false)} pane={pane}
+ <PageFullScreen {...tools} title={payload.title} doc={current} botId={botId} threadId={threadId} handle={wide} close={() => { point.stop(); setFullScreen(false); }} pane={pane}
{...(!room ? { onSelection: setSelection } : {})} />
)}
</div>