Skip to content

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

feat(ui): display inline keyboard shortcut hints in action menus

jonathanwxh-cellebae4ec24395
diff --git a/src/components/BotContextMenu.position.test.ts b/src/components/BotContextMenu.position.test.ts
index 2238e4f93c..2f98dba4d4 100644
--- a/src/components/BotContextMenu.position.test.ts
+++ b/src/components/BotContextMenu.position.test.ts
@@ -5,6 +5,7 @@ import type { Bot } from "@/state/store";
const fixture = vi.hoisted(() => ({
advanced: false,
+ selectedId: null as string | null,
effects: [] as Array<() => void | (() => void)>,
portal: null as { node: ReactElement<{ ref: RefObject<HTMLDivElement | null> }>; target: unknown } | null,
}));
@@ -24,7 +25,7 @@ vi.mock("@/lib/thread-preferences", () => ({ useShowThreads: () => true }));
vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => fixture.advanced }));
vi.mock("@/state/store", async (importOriginal) => {
const original = await importOriginal<typeof import("@/state/store")>();
- return { ...original, useStore: () => ({ state: { ...original.initialState, bots: [bot, { ...bot, id: "other" }] }, dispatch: vi.fn() }) };
+ return { ...original, useStore: () => ({ state: { ...original.initialState, selectedId: fixture.selectedId, bots: [bot, { ...bot, id: "other" }] }, dispatch: vi.fn() }) };
});
const { BotContextMenu } = await import("./Sidebar");
@@ -37,6 +38,7 @@ const bot: Bot = {
const listeners = new Map<string, () => void>();
beforeEach(() => {
fixture.advanced = false;
+ fixture.selectedId = null;
fixture.effects = [];
fixture.portal = null;
listeners.clear();
@@ -139,4 +141,19 @@ describe("bot actions menu viewport placement", () => {
fixture.effects = [];
expect(render()).toContain(t("sidebar.bot.makeChief"));
});
+
+ it("shows the platform New thread shortcut hint only for the selected bot", () => {
+ expect(render()).not.toContain("<kbd");
+ fixture.selectedId = bot.id;
+ const win = globalThis.window as unknown as { ogb?: { platform?: string } };
+ for (const advanced of [false, true]) {
+ fixture.advanced = advanced;
+ for (const [platform, expected] of [["darwin", "⌘ ⇧ N"], ["win32", "Ctrl Shift N"], ["linux", "Ctrl Shift N"]] as const) {
+ win.ogb = { platform };
+ const html = render();
+ expect(html).toContain("<kbd");
+ expect(html).toContain(expected);
+ }
+ }
+ });
});
diff --git a/src/components/ChatMoreMenu.test.ts b/src/components/ChatMoreMenu.test.ts
index 8e8ed68128..33636166ae 100644
--- a/src/components/ChatMoreMenu.test.ts
+++ b/src/components/ChatMoreMenu.test.ts
@@ -115,7 +115,18 @@ describe("ChatMoreMenu, the round ⋯ for the bot panel", () => {
expect(menuOf(createElement(ChatMoreMenu, { bot: fresh })).items.find((one) => one.key === "start-fresh")!.disabled).toBe(true);
});
- it("starts a new thread with the bot", () => {
+ it("starts a new thread with the bot and displays the platform shortcut hint", () => {
+ const win = globalThis.window as { ogb?: { platform?: string } };
+ try {
+ for (const [platform, expected] of [["darwin", "⌘ ⇧ N"], ["win32", "Ctrl Shift N"], ["linux", "Ctrl Shift N"]] as const) {
+ win.ogb = { platform };
+ const menu = menuOf(createElement(ChatMoreMenu, { bot }));
+ const newThread = menu.items.find((item) => item.key === "new-thread")!;
+ expect(renderToStaticMarkup(createElement("div", null, newThread.trailing))).toContain(expected);
+ }
+ } finally {
+ delete win.ogb;
+ }
const menu = menuOf(createElement(ChatMoreMenu, { bot }));
menu.items.find((item) => item.key === "new-thread")!.onSelect();
expect(fixture.dispatch).toHaveBeenCalledWith({ type: "newTask", botId: "pepper" });
diff --git a/src/components/ChatMoreMenu.tsx b/src/components/ChatMoreMenu.tsx
index daed1e51ca..a452603fbe 100644
--- a/src/components/ChatMoreMenu.tsx
+++ b/src/components/ChatMoreMenu.tsx
@@ -104,6 +104,7 @@ export function useChatMoreItems(profile: Bot, phoneHeader = false): { items: Si
separatorBefore: true,
label: t("task.newShort"),
icon: <SquarePen size={16} />,
+ trailing: <ShortcutHint id="new-thread" />,
onSelect: () => dispatch({ type: "newTask", botId: profile.id }),
} satisfies SidebarMenuItem]),
// With one thread there is nothing to switch to.
diff --git a/src/components/SidebarBotMenu.tsx b/src/components/SidebarBotMenu.tsx
index 2e4c205606..bf04d81d7c 100644
--- a/src/components/SidebarBotMenu.tsx
+++ b/src/components/SidebarBotMenu.tsx
@@ -26,6 +26,7 @@ import { useMoveToTeam } from "./MoveToTeam";
import type { MenuState } from "./Sidebar";
import { departmentNames, moveBotsToSection, useMayMoveBots } from "./bot-sections";
import { openBotSettings } from "./bot-panel/panel-link";
+import { ShortcutHint } from "./ShortcutHint";
import { isArchived } from "./SidebarThreadRow";
type Flyout = "more" | "move";
@@ -184,7 +185,7 @@ export function BotContextMenu({
icon: React.ReactNode,
label: string,
onClick?: () => void,
- opts?: { danger?: boolean; disabled?: boolean; hint?: string; keepOpen?: boolean },
+ opts?: { danger?: boolean; disabled?: boolean; hint?: string; keepOpen?: boolean; trailing?: React.ReactNode },
) => (
<button
key={label}
@@ -203,7 +204,12 @@ export function BotContextMenu({
)}
>
{icon}
- {label}
+ {opts?.trailing ? (
+ <>
+ <span className="flex-1 truncate text-start">{label}</span>
+ {opts.trailing}
+ </>
+ ) : label}
</button>
);
const divider = (key: string) => <div key={key} role="separator" className={MENU_ITEM_SEPARATOR} />;
@@ -218,6 +224,8 @@ export function BotContextMenu({
t(everyBotPaused ? "pause.resumeAll" : "pause.pauseAll"),
() => { void setEveryBotPaused(!everyBotPaused).catch((error: unknown) => dispatch({ type: "error", message: error instanceof Error ? error.message : String(error) })); });
+ const newThreadHint = state.selectedId === bot.id ? <ShortcutHint id="new-thread" /> : undefined;
+
if (simpleMenu) {
const showFlyout = (key: Flyout, focus: boolean) => {
more.openNow(key);
@@ -286,7 +294,7 @@ export function BotContextMenu({
...deleteAll,
];
// Simple view hides the thread list: start one, see them all (the panel's Conversations), and choose the one it opens.
- const newThread = bot.yourAccess === "view" ? null : item(<SquarePen size={16} className="text-ink-secondary" />, t("task.newShort"), () => dispatch({ type: "newTask", botId: bot.id }));
+ const newThread = bot.yourAccess === "view" ? null : item(<SquarePen size={16} className="text-ink-secondary" />, t("task.newShort"), () => dispatch({ type: "newTask", botId: bot.id }), { trailing: newThreadHint });
const viewThreads = item(<MessagesSquare size={16} className="text-ink-secondary" />, t("sidebar.bot.simple.viewThreads"), () => {
openForSettings();
openBotSettings(dispatch, "history", { botId: bot.id, anchor: "conversations" });
@@ -392,7 +400,7 @@ export function BotContextMenu({
className={cn("fixed z-40 max-h-[calc(100dvh-16px)] w-max min-w-[198px] max-w-[calc(100vw-16px)] overflow-y-auto overscroll-contain", MENU_SHEET, motion.className)} {...motion.exitProps}
>
{showThreads && <>
- {item(<SquarePen size={16} className="text-ink-secondary" />, t("task.newShort"), () => dispatch({ type: "newTask", botId: bot.id }))}
+ {item(<SquarePen size={16} className="text-ink-secondary" />, t("task.newShort"), () => dispatch({ type: "newTask", botId: bot.id }), { trailing: newThreadHint })}
{admin && item(<FolderOpen size={16} className="shrink-0 text-ink-secondary" />, t("task.folder.new"), () => onNewTaskFolder(bot.id))}
{item(<FolderPlus size={16} className="text-ink-secondary" />, t("folder.new"), () => onNewFolder(bot.id))}
</>}