Skip to content

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

Notifications: the bell moves into the window's top bar beside Settings

AdityaUmaleac6b01808c9b
diff --git a/src/App.tsx b/src/App.tsx
index a416196369..a7f75b4f20 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -149,6 +149,7 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {
const sidePanelOpen = (Boolean(bot) && (state.settingsOpen || state.computerOpen || state.inspectorOpen || state.activityOpen)) || roomPanelOpen || (notificationFeed && state.notificationsOpen) || inboxShown;
const collapseSidebar = sidePanelOpen && !sidebarAndPanelFit;
const calendarFocus = state.activeView === "routines" && state.routinesFocus.view === "calendar";
+ const notificationTray = notificationFeed && !calendarFocus;
const noEngines =
state.connected &&
@@ -313,7 +314,7 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {
</>;
return (
<div className={cn("flex h-full flex-col", framed && "bg-frame")}>
- <WindowFrameBar />
+ <WindowFrameBar notifications={notificationTray} />
{!framed && strips}
<div className="relative flex min-h-0 flex-1">
{!calendarFocus && <button
@@ -414,8 +415,8 @@ function Shell({ viewer }: { viewer: WelcomeViewer | null }) {
{!remoteClient && state.inspectorOpen && bot && <InspectorPanel key={bot.threadId} bot={bot} />}
{!remoteClient && state.activityOpen && bot && <ActivityPanel key={`activity:${bot.id}`} bot={bot} />}
{inboxShown && <InboxPanel />}
- {notificationFeed && !calendarFocus && state.notificationsOpen && <NotificationsPanel />}
- {notificationFeed && !calendarFocus && <NotificationRail />}
+ {notificationTray && state.notificationsOpen && <NotificationsPanel />}
+ {notificationTray && !framed && <NotificationRail />}
</div>
</div>
{state.appSettingsOpen && <SettingsModal />}
diff --git a/src/components/NotificationsPanel.tsx b/src/components/NotificationsPanel.tsx
index 6d8958605d..fa5d2ecb5d 100644
--- a/src/components/NotificationsPanel.tsx
+++ b/src/components/NotificationsPanel.tsx
@@ -63,27 +63,38 @@ export function filterNotifications<T extends { botId: string }>(entries: T[], b
return botId === ALL_BOTS ? entries : entries.filter((entry) => entry.botId === botId);
}
-export function NotificationRail() {
+/** The bell that opens and closes the Notifications tray, with the unread count. `bar` puts it in the window's top bar
+ * (WindowFrameBar) at that bar's button size; otherwise it is the tab on the window's right edge (NotificationRail). */
+export function NotificationBell({ bar }: { bar?: string }) {
const { state, dispatch } = useStore();
const unread = state.notifications.reduce((count, n) => count + (n.read ? 0 : 1), 0);
+ return (
+ <button
+ type="button"
+ data-notification-bell
+ onClick={() => dispatch({ type: "toggleNotifications" })}
+ aria-label={unread > 0 ? t("notifications.railUnread", { count: unread }) : t("notifications.title")}
+ title={t("notifications.title")}
+ aria-pressed={state.notificationsOpen}
+ className={cn("relative", bar ?? "flex size-8 items-center justify-center rounded-md text-ink-secondary hover:bg-raised hover:text-ink", bar && state.notificationsOpen && "text-accent hover:text-accent")}
+ >
+ <Bell size={bar ? 15 : 17} strokeWidth={bar ? 1.75 : undefined} aria-hidden="true" />
+ {unread > 0 && (
+ <span className={cn("absolute flex items-center justify-center rounded-full bg-accent font-semibold text-accent-ink", bar ? "-right-1 -top-0.5 h-[13px] min-w-[13px] px-0.5 text-[9px]" : "-right-0.5 -top-0.5 h-[15px] min-w-[15px] px-1 text-[10px]")}>
+ {unread > 99 ? "99+" : unread}
+ </span>
+ )}
+ </button>
+ );
+}
+
+/** The bell on the window's right edge, for windows without the top bar (a browser, or the frame turned off). */
+export function NotificationRail() {
+ const { state } = useStore();
if (state.notificationsOpen) return null;
return (
<aside aria-label={t("notifications.title")} className="absolute right-0 top-1/2 z-20 -translate-y-1/2 rounded-l-lg border border-r-0 border-hairline/40 bg-panel p-1 shadow-sm">
- <button
- type="button"
- onClick={() => dispatch({ type: "toggleNotifications" })}
- aria-label={unread > 0 ? t("notifications.railUnread", { count: unread }) : t("notifications.title")}
- title={t("notifications.title")}
- aria-pressed={false}
- className="relative flex size-8 items-center justify-center rounded-md text-ink-secondary hover:bg-raised hover:text-ink"
- >
- <Bell size={17} />
- {unread > 0 && (
- <span className="absolute -right-0.5 -top-0.5 flex h-[15px] min-w-[15px] items-center justify-center rounded-full bg-accent px-1 text-[10px] font-semibold text-accent-ink">
- {unread > 99 ? "99+" : unread}
- </span>
- )}
- </button>
+ <NotificationBell />
</aside>
);
}
diff --git a/src/components/WindowFrameBar.test.ts b/src/components/WindowFrameBar.test.ts
index 9493d17982..185cadab20 100644
--- a/src/components/WindowFrameBar.test.ts
+++ b/src/components/WindowFrameBar.test.ts
@@ -15,11 +15,13 @@ const fixture = vi.hoisted(() => ({
config: {} as { team?: { name: string } },
look: null as { color: string | null } | null,
frameDrawn: vi.fn(),
+ notifications: [] as Array<{ read: boolean }>,
+ notificationsOpen: false,
}));
vi.mock("@/lib/chrome-rail", () => ({ useChromeRail: () => fixture.rail, setChromeRailHidden: () => {}, sayFrameDrawn: fixture.frameDrawn }));
vi.mock("@/lib/updater", () => ({ useUpdaterState: () => fixture.update }));
vi.mock("@/lib/place-look", () => ({ usePlaceLook: () => fixture.look }));
-vi.mock("@/state/store", () => ({ useStore: () => ({ state: { config: fixture.config }, dispatch: fixture.dispatch }) }));
+vi.mock("@/state/store", () => ({ useStore: () => ({ state: { config: fixture.config, notifications: fixture.notifications, notificationsOpen: fixture.notificationsOpen }, dispatch: fixture.dispatch }) }));
vi.mock("./DesktopCapabilities", async (importOriginal) => ({
...await importOriginal<typeof import("./DesktopCapabilities")>(),
useDesktopCapabilities: () => ({ capabilities: { windowChrome: fixture.windowChrome, windowFrame: fixture.windowFrame }, ready: true }),
@@ -27,6 +29,7 @@ vi.mock("./DesktopCapabilities", async (importOriginal) => ({
import { setLocale } from "@/lib/i18n";
import { tilesClearCorner } from "./SidebarTiles";
+import { NotificationRail } from "./NotificationsPanel";
import { UpdateIndicator } from "./UpdateIndicator";
import { WindowFrameBar } from "./WindowFrameBar";
@@ -45,6 +48,8 @@ beforeEach(() => {
fixture.look = null;
fixture.dispatch.mockClear();
fixture.frameDrawn.mockClear();
+ fixture.notifications = [];
+ fixture.notificationsOpen = false;
place = { local: false, name: "My Cloud", origin: "https://cloud.example", color: "blue" };
Object.assign(window, { ogb: { workspaces: { state: async () => place, onChanged: () => () => {}, menu: async () => {} } } });
});
@@ -147,6 +152,29 @@ describe("the window frame's top bar", () => {
expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleAppSettings", open: true });
});
+ it("holds the Notifications bell beside Settings, with the unread count, and it opens and closes the tray", async () => {
+ fixture.notifications = [{ read: false }, { read: true }, { read: false }];
+ await mount(createElement(WindowFrameBar, { notifications: true }));
+ const bell = () => bar()!.querySelector<HTMLButtonElement>("[data-notification-bell]")!;
+ expect(bell().getAttribute("aria-label")).toBe("Notifications, 2 unread");
+ expect(bell().textContent, "the unread count on the bell").toBe("2");
+ expect(bell().className.split(" ")).toEqual(expect.arrayContaining(["size-[22px]", "relative"]));
+ expect(bell().getAttribute("aria-pressed")).toBe("false");
+ const order = [...bar()!.querySelectorAll("button")].map((button) => button.hasAttribute("data-notification-bell") ? "bell" : button.getAttribute("aria-label"));
+ expect(order, "right before Settings, at the right end").toEqual(["Hide your computers", "bell", "App settings"]);
+ await act(async () => bell().click());
+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleNotifications" });
+ fixture.notificationsOpen = true;
+ await act(async () => root!.render(createElement(WindowFrameBar, { notifications: true })));
+ expect(bell().getAttribute("aria-pressed"), "it stays in the bar while the tray is open, to close it").toBe("true");
+ expect(bell().className.split(" ")).toContain("text-accent");
+ });
+
+ it("has no bell where the tray is off (turned off, a remote client, the calendar)", async () => {
+ await mount(createElement(WindowFrameBar));
+ expect(bar()!.querySelector("[data-notification-bell]")).toBeNull();
+ });
+
it("shows a download arrow in the accent while an update waits, its words in its name, and the sidebar's round buttons step aside for it", async () => {
fixture.update = { status: "downloading", percent: 45.4 };
await mount(createElement("div", null, createElement(WindowFrameBar), createElement("aside", null, createElement(UpdateIndicator))));
@@ -168,6 +196,21 @@ describe("the window frame's top bar", () => {
});
});
+describe("the bell on the window's edge, for windows without the top bar", () => {
+ it("is the same bell at the edge's size, with the unread count, and steps away while the tray is open", async () => {
+ fixture.notifications = [{ read: false }];
+ await mount(createElement(NotificationRail));
+ const bell = host.querySelector<HTMLButtonElement>("aside [data-notification-bell]")!;
+ expect(bell.getAttribute("aria-label")).toBe("Notifications, 1 unread");
+ expect(bell.className.split(" ")).toEqual(expect.arrayContaining(["size-8", "relative"]));
+ await act(async () => bell.click());
+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleNotifications" });
+ fixture.notificationsOpen = true;
+ await act(async () => root!.render(createElement(NotificationRail)));
+ expect(host.querySelector("aside")).toBeNull();
+ });
+});
+
describe("Simple's sidebar corner", () => {
// A 280px sidebar: 78px tiles 4px apart, centred, the grid's right edge at 280.
const row = (count: number, top = 10) => {
diff --git a/src/components/WindowFrameBar.tsx b/src/components/WindowFrameBar.tsx
index 61346ca258..630033d974 100644
--- a/src/components/WindowFrameBar.tsx
+++ b/src/components/WindowFrameBar.tsx
@@ -7,6 +7,7 @@ import { t } from "@/lib/i18n";
import { useStore } from "@/state/store";
import { ChromeRailToggle } from "./ChromeRailToggle";
import { captionChrome, useDesktopCapabilities, windowFrameable, windowFramed } from "./DesktopCapabilities";
+import { NotificationBell } from "./NotificationsPanel";
import { UpdateIndicator } from "./UpdateIndicator";
import { WindowPlaceTitle } from "./WindowPlaceTitle";
@@ -16,9 +17,10 @@ export const FRAME_BAR_BUTTON = "flex size-[22px] shrink-0 items-center justify-
/** The window frame's top bar (windowFramed), as thin as the traffic lights allow: they sit in it on macOS (main puts
* them there: electron/window-chrome.mjs), the caption buttons on Windows (WindowCaptionButtons, drawn over its right
* end). The rail's button follows the traffic lights; the place on screen is named in its middle; an update while one
- * waits, and the app's settings, close the right end. The whole bar drags the window. It reaches under the window's
- * rail (the page starts --rail-beside in), so its middle is the window's middle. */
-export function WindowFrameBar() {
+ * waits, the Notifications bell (when `notifications`: the tray is on here) and the app's settings, close the right end.
+ * The whole bar drags the window. It reaches under the window's rail (the page starts --rail-beside in), so its middle
+ * is the window's middle. */
+export function WindowFrameBar({ notifications = false }: { notifications?: boolean }) {
const { capabilities } = useDesktopCapabilities();
const { dispatch } = useStore();
const frameable = windowFrameable(capabilities), framed = windowFramed(capabilities);
@@ -39,6 +41,7 @@ export function WindowFrameBar() {
<WindowPlaceTitle />
<div data-frame-bar-end className={cn("flex items-center justify-end gap-0.5", mac ? "pr-2" : "pr-[140px]")}>
<UpdateIndicator bar={FRAME_BAR_BUTTON} />
+ {notifications && <NotificationBell bar={FRAME_BAR_BUTTON} />}
<button
type="button"
data-frame-settings