Skip to content

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

One list: the end line in the avatars-only sidebar, and no "no match" beside a match

milind-soni6e33a44dc7d2
diff --git a/src/components/OtherPlaceBots.dom.test.ts b/src/components/OtherPlaceBots.dom.test.ts
index 17a07167fe..b5d73a57f2 100644
--- a/src/components/OtherPlaceBots.dom.test.ts
+++ b/src/components/OtherPlaceBots.dom.test.ts
@@ -83,6 +83,19 @@ it("a sleeping Cloud with nothing kept says so as normal, and opening it wakes i
}
});
+it("in the avatars-only sidebar the line is its icon alone, its words its tooltip and label, and it still opens My Cloud", async () => {
+ const openMyCloud = vi.fn(async () => {});
+ window.ogb = { placesTogether: page, cloudSendPage: { openMyCloud } } as never;
+ said = state({ other: { home: "cloud", state: "asleep", bots: [] } });
+ await render(createElement(OtherPlaceLine, { key: "line", icons: true }));
+ const line = q("button[data-other-place-line]")!;
+ expect(line.textContent).toBe("");
+ expect(line.getAttribute("aria-label")).toBe("My Cloud is asleep. Open it to see its bots.");
+ expect(line.getAttribute("title")).toBe("My Cloud is asleep. Open it to see its bots.");
+ await act(async () => line.click());
+ expect(openMyCloud).toHaveBeenCalledTimes(1);
+});
+
it("a line is no search result: hidden while the sidebar is searched", async () => {
said = state({ other: { home: "cloud", state: "signin", bots: [] } });
await render(createElement(OtherPlaceLine, { key: "line", query: "scout" }));
diff --git a/src/components/OtherPlaceBots.tsx b/src/components/OtherPlaceBots.tsx
index 7e2f2da457..da922fc02e 100644
--- a/src/components/OtherPlaceBots.tsx
+++ b/src/components/OtherPlaceBots.tsx
@@ -29,17 +29,20 @@ function saidOf(state: PlacesTogetherState | null): Said | null {
/** My Cloud's page, opened from this computer's page (main's own switch, which wakes it as opening it always does). */
const openMyCloud = () => (window.ogb?.remoteClient?.active ? undefined : window.ogb?.cloudSendPage?.openMyCloud);
-export function OtherPlaceLine({ query = "" }: { query?: string }) {
+/** `icons`: the avatars-only sidebar, where the line is its icon alone, its words its tooltip and label. */
+export function OtherPlaceLine({ query = "", icons = false }: { query?: string; icons?: boolean }) {
const said = usePlacesTogetherPart(saidOf);
if (!said || query.trim()) return null;
const { icon: Icon, words, opens } = SAID[said];
const open = opens ? openMyCloud() : undefined;
const [home, state] = said.split(":");
- const body = <><Icon size={13} aria-hidden="true" className={cn("shrink-0", said === "cloud:waking" && "animate-pulse motion-reduce:animate-none")} /><span className="min-w-0">{t(words)}</span></>;
- const look = "flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[12px] leading-4 text-ink-secondary";
- return <div data-other-place={home} data-other-place-state={state} className="flex flex-col px-2 pb-1 pt-2">
+ const line = t(words);
+ const body = <><Icon size={icons ? 16 : 13} aria-hidden="true" className={cn("shrink-0", said === "cloud:waking" && "animate-pulse motion-reduce:animate-none")} />{icons ? null : <span className="min-w-0">{line}</span>}</>;
+ const look = icons ? "flex size-9 items-center justify-center self-center text-ink-secondary" : "flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[12px] leading-4 text-ink-secondary";
+ const named = icons ? { title: line, "aria-label": line } : {};
+ return <div data-other-place={home} data-other-place-state={state} className={cn("flex flex-col", icons ? "pt-2" : "px-2 pb-1 pt-2")}>
{open
- ? <button type="button" data-other-place-line="" onClick={() => { void open().catch(() => {}); }} className={cn(look, "rounded-lg hover:bg-menu-hover hover:text-ink")}>{body}</button>
- : <p role="status" data-other-place-line="" className={look}>{body}</p>}
+ ? <button type="button" data-other-place-line="" {...named} onClick={() => { void open().catch(() => {}); }} className={cn(look, "rounded-lg hover:bg-menu-hover hover:text-ink")}>{body}</button>
+ : <p role="status" data-other-place-line="" {...named} className={look}>{body}</p>}
</div>;
}
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index bfa9c6faa9..0c66e278ab 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -1349,7 +1349,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
<GlassScroller className={rail ? "[scrollbar-gutter:stable_both-edges]" : simpleDesk ? "px-3" : "px-2"}>
<div className={cn("flex flex-col", simpleDesk ? cn("gap-0.5 pb-2", !tiles && "pt-2") : advanced ? "gap-0.5" : "gap-1 pb-2 pt-2")}>
- {matchingBots.length === 0 && visibleGroups.length === 0 && q && q.length < MIN_QUERY && (
+ {matchingBots.length === 0 && visibleGroups.length === 0 && !placed.length && q && q.length < MIN_QUERY && (
<div className="px-3 py-6 text-center text-[13px] text-ink-secondary">{t("sidebar.noMatch", { query })}</div>
)}
{!q && <NeedsYouButton compact={rail} />}{!q && <SidebarPeople compact={rail} onOpened={phone ? onClose : undefined} />}
@@ -1462,7 +1462,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
</div>
);
})}
- <OtherPlaceLine query={query} /><MovedBotRows bots={state.bots} /><MovedToMyCloudRow bots={state.bots} /><SearchResults query={query} onLanded={() => { setQuery(""); setSearchOpen(false); }} />
+ <OtherPlaceLine query={query} icons={density === "icons"} /><MovedBotRows bots={state.bots} /><MovedToMyCloudRow bots={state.bots} /><SearchResults query={query} onLanded={() => { setQuery(""); setSearchOpen(false); }} />
{showPinnedCircleThreads && (
<PinnedCircleThreadSection
bots={pinnedBots}
diff --git a/src/lib/place-rows.test.ts b/src/lib/place-rows.test.ts
index 719036574c..1ca5dcf480 100644
--- a/src/lib/place-rows.test.ts
+++ b/src/lib/place-rows.test.ts
@@ -1,9 +1,11 @@
// @vitest-environment happy-dom
+import { act, createElement } from "react";
+import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { Bot } from "@/state/store";
import { setLocale } from "./i18n";
-import { isPlacedBot, otherPlaceDispatch, ownRows, placedBot, placedLine, placeMark, placeOfHome, resetPlaceRowsForTest, withOtherPlace, type Place } from "./place-rows";
-import type { PlaceBotRow } from "./places-together";
+import { isPlacedBot, otherPlaceDispatch, useOtherPlaceBots, ownRows, placedBot, placedLine, placeMark, placeOfHome, resetPlaceRowsForTest, withOtherPlace, type Place } from "./place-rows";
+import { resetPlacesTogetherForTest, type PlaceBotRow, type PlacesTogetherState } from "./places-together";
import { partitionSidebarBots, sidebarBotRows } from "./sidebar-layout";
const row = (home: "computer" | "cloud", id: string, over: Partial<PlaceBotRow> = {}): PlaceBotRow => ({ home, id, threadId: `t-${id}`, name: id, color: "blue", ...over });
@@ -11,7 +13,7 @@ const own = (id: string, over: Partial<Bot> = {}): Bot => ({ id, name: id, threa
notifications: true, messages: [], modelSelection: { instanceId: "here", model: "m" }, ...over });
beforeEach(() => setLocale("en"));
-afterEach(() => { resetPlaceRowsForTest(); vi.unstubAllGlobals(); delete (window as { ogb?: unknown }).ogb; });
+afterEach(() => { resetPlaceRowsForTest(); resetPlacesTogetherForTest(); vi.unstubAllGlobals(); delete (window as { ogb?: unknown }).ogb; });
describe("a row of the other place as a bot of the one list", () => {
it("is keyed by its place and its id, so the same id in two places is two bots", () => {
@@ -146,3 +148,31 @@ describe("the device mark", () => {
expect(placeMark(placeOfHome("cloud"), "asleep", false, "Atlas").label).toBe("O My Cloud está em repouso. Abrir Atlas o ativa.");
});
});
+
+describe("a steady list", () => {
+ it("main answering again with the same rows keeps the same list and the same bots, so no row is drawn again; a changed row is new", async () => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ let changed = () => {};
+ const answer = (bots: PlaceBotRow[]): PlacesTogetherState => ({ v: 1, available: true, on: true, here: "computer", other: { home: "cloud", state: "ready", bots } });
+ let said = answer([row("cloud", "scout"), row("cloud", "nova")]);
+ window.ogb = { placesTogether: { state: async () => ({ ...said, other: { ...said.other!, bots: said.other!.bots.map((bot) => ({ ...bot })) } }), onChanged: (callback: () => void) => { changed = callback; return () => {}; } } } as never;
+ const seen: Array<readonly Bot[]> = [];
+ const Probe = () => { seen.push(useOtherPlaceBots("")); return null; };
+ const host = document.createElement("div"), root = createRoot(host);
+ await act(async () => root.render(createElement(Probe)));
+ await act(async () => { await Promise.resolve(); });
+ const first = seen.at(-1)!;
+ expect(first.map((bot) => bot.id)).toEqual(["cloud:scout", "cloud:nova"]);
+ await act(async () => changed());
+ await act(async () => { await Promise.resolve(); });
+ expect(seen.at(-1)).toBe(first);
+ said = answer([row("cloud", "scout"), row("cloud", "nova", { unread: true })]);
+ await act(async () => changed());
+ await act(async () => { await Promise.resolve(); });
+ const next = seen.at(-1)!;
+ expect(next).not.toBe(first);
+ expect(next[0]).toBe(first[0]);
+ expect(next[1]).not.toBe(first[1]);
+ await act(async () => root.unmount());
+ });
+});