Skip to content

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

Let a chat's page card be used in place, with a footer button to open it whole

AdityaUmalefa94fa1f8c40
diff --git a/src/components/app/AppChrome.tsx b/src/components/app/AppChrome.tsx
index 0d799a1e27..1698e134cb 100644
--- a/src/components/app/AppChrome.tsx
+++ b/src/components/app/AppChrome.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState, type ReactNode } from "react";
-import { AppWindow, CircleAlert, CircleCheck, Info, Loader2, RotateCw } from "lucide-react";
+import { AppWindow, CircleAlert, CircleCheck, Info, Loader2, Maximize2, RotateCw, X } from "lucide-react";
import { cn } from "@/lib/cn";
import { intlLocale, t } from "@/lib/i18n";
import { openExternalLink } from "@/lib/app-links";
@@ -71,7 +71,7 @@ export function AppHeader({
);
}
-export function PageCardFooter({ title, detail, updated, infoId, infoOpen, onInfo, onReload, reloading = false }: {
+export function PageCardFooter({ title, detail, updated, infoId, infoOpen, onInfo, onReload, reloading = false, open }: {
title: string;
detail: string;
updated: boolean;
@@ -80,6 +80,7 @@ export function PageCardFooter({ title, detail, updated, infoId, infoOpen, onInf
onInfo(): void;
onReload?: () => void;
reloading?: boolean;
+ open?: { pressed: boolean; onClick(): void };
}) {
return (
<div data-page-footer className="flex min-h-18 items-center gap-3 border-t border-ink/[0.08] px-5 py-4">
@@ -106,6 +107,14 @@ export function PageCardFooter({ title, detail, updated, infoId, infoOpen, onInf
</button>
)}
</div>
+ {open && (
+ <button type="button" data-page-open aria-pressed={open.pressed} onClick={open.onClick}
+ aria-label={t(open.pressed ? "chat.preview.closePage" : "chat.preview.openPage")}
+ title={t(open.pressed ? "chat.preview.closePage" : "chat.preview.openPage")}
+ className={cn(ICON_BUTTON, "-me-1.5", open.pressed && "bg-ink/[0.07] text-ink")}>
+ {open.pressed ? <X aria-hidden="true" size={16} /> : <Maximize2 aria-hidden="true" size={14} />}
+ </button>
+ )}
</div>
);
}
diff --git a/src/components/app/AppMessage.compact.test.ts b/src/components/app/AppMessage.compact.test.ts
index c5e669ba88..ba05ba9a1e 100644
--- a/src/components/app/AppMessage.compact.test.ts
+++ b/src/components/app/AppMessage.compact.test.ts
@@ -61,17 +61,39 @@ afterEach(() => {
});
describe("a bot's page as a compact card", () => {
- it("keeps the keyboard out of the preview, in a chat and in a room, and leaves the card's own buttons reachable", async () => {
+ it("keeps the keyboard out of the preview while it is covered, in a chat and in a room, and leaves the card's own buttons reachable", async () => {
for (const room of [false, true]) {
await render(row(payload()), room);
const box = card().querySelector<HTMLElement>("[data-app-box]")!;
expect(box.querySelector("iframe")).not.toBeNull();
+ expect(box.querySelector("[data-page-settling]")).not.toBeNull();
expect(box.hasAttribute("inert")).toBe(true);
expect(opener().closest("[inert]")).toBeNull();
expect(card().querySelector("[data-page-footer]")!.closest("[inert]")).toBeNull();
}
});
+ it("lets the page be used in place in a chat, opening it whole only from the footer's button", async () => {
+ await render(row(payload()));
+ await pageSays(false);
+ const box = card().querySelector<HTMLElement>("[data-app-box]")!;
+ expect(box.hasAttribute("inert")).toBe(false);
+ expect(opener().closest("[data-page-footer]")).not.toBeNull();
+ expect(opener().className).not.toContain("inset-0");
+ await press(box);
+ expect(pane.querySelector("[data-page-pane]")).toBeNull();
+ await press(opener());
+ expect(pane.querySelector("[data-page-pane=a1]")).not.toBeNull();
+ });
+
+ it("keeps a room's card view-only, the whole card opening the page", async () => {
+ await render(row(payload()), true);
+ await pageSays(false);
+ expect(card().querySelector("[data-app-box]")!.hasAttribute("inert")).toBe(true);
+ expect(opener().closest("[data-page-footer]")).toBeNull();
+ expect(opener().className).toContain("inset-0");
+ });
+
it("shows only the preview and a footer with the title and what it is", async () => {
await render(row(payload()));
expect(card().querySelector<HTMLElement>("[data-app-box]")!.style.height).toBe(`${PAGE_PREVIEW_HEIGHT}px`);
diff --git a/src/components/app/AppMessage.tsx b/src/components/app/AppMessage.tsx
index 43e3671d30..5f53de4d42 100644
--- a/src/components/app/AppMessage.tsx
+++ b/src/components/app/AppMessage.tsx
@@ -290,8 +290,8 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {
message.text ? <div dir="auto" className={cn("line-clamp-6 whitespace-pre-wrap text-[13px] leading-[18px] text-ink-secondary", compact ? "px-4 pt-3" : bordered ? "px-4 pb-3" : "pb-2")}>{message.text}</div> : null
) : (
<div data-app-box className={cn("relative w-full", compact && "overflow-hidden", bordered && !compact && "border-t border-ink/[0.08]", point.pointing && "ring-2 ring-inset ring-accent/60")}
- // The whole card opens the page, so the keyboard must not reach what the preview shows underneath it.
- inert={(compact && Boolean(current) && !point.pointing) || undefined}
+ // The keyboard must not reach a preview that is covered: by the settling cover, or in a room by the card's opener.
+ inert={(compact && Boolean(current) && (Boolean(room) || undecided) && !point.pointing) || undefined}
style={{ height: boxHeight }}>
{titled && <div data-page-title title={payload.title} className={CARD_TITLE}><bdi dir="auto">{payload.title}</bdi></div>}
{current ? (
@@ -358,8 +358,9 @@ function AppRow({ botId, botName, threadId, message, payload, pool, room }: {
onInfo={() => setInfoOpen((open) => !open)}
onReload={docKey ? reloadNow : undefined}
reloading={fetching && Boolean(current)}
+ {...(pane && current && !point.pointing ? { open: { pressed: fullScreen, onClick: tools.fullScreen.toggle } } : {})}
/>
- {current && !point.pointing && (
+ {room && current && !point.pointing && (
<button type="button" data-page-open onClick={tools.fullScreen.toggle} aria-pressed={fullScreen}
aria-label={t(fullScreen ? "chat.preview.closePage" : "chat.preview.openPage")}
className="absolute inset-0 cursor-pointer rounded-2xl transition-colors duration-[120ms] hover:bg-ink/[0.04] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus motion-reduce:transition-none" />