Skip to content

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

Sidebar: keep pinned threads in view and remember "Show all" per bot

AdityaUmale6789aa36a002
diff --git a/src/components/BulkSelectBar.tsx b/src/components/BulkSelectBar.tsx
index 2b27d761b5..8a794b8023 100644
--- a/src/components/BulkSelectBar.tsx
+++ b/src/components/BulkSelectBar.tsx
@@ -133,7 +133,7 @@ export function BulkSelectBar({ rows, selected, maxDeletable, freshConversation,
</div>;
}
-export function ThreadListFooter({ bulk, rows, selected, total, canShowAll, canSelect, onShowAll, maxDeletable, freshConversation, onDelete }: {
+export function ThreadListFooter({ bulk, rows, selected, total, canShowAll, canSelect, onShowAll, onShowFewer, maxDeletable, freshConversation, onDelete }: {
bulk: ReturnType<typeof useBulkSelect>;
rows: readonly SelectableRow[];
selected: Selection;
@@ -141,6 +141,8 @@ export function ThreadListFooter({ bulk, rows, selected, total, canShowAll, canS
canShowAll: boolean;
canSelect: boolean;
onShowAll: () => void;
+ /** Offered instead of "Show all" while a remembered full list is on and the short list would hide threads. */
+ onShowFewer?: () => void;
maxDeletable?: number;
freshConversation: boolean;
onDelete: (threadIds: string[]) => Promise<BulkDeleteResult>;
@@ -148,10 +150,11 @@ export function ThreadListFooter({ bulk, rows, selected, total, canShowAll, canS
if (bulk.active) {
return <BulkSelectBar rows={rows} selected={selected} maxDeletable={maxDeletable} freshConversation={freshConversation} onChange={bulk.setSelected} onDelete={onDelete} />;
}
- if (!canShowAll && !canSelect) return null;
+ if (!canShowAll && !onShowFewer && !canSelect) return null;
const link = "inline-flex h-7 items-center text-[13px] font-medium leading-4 text-ink-secondary hover:text-ink";
return <div className="flex items-center justify-between pl-6 pr-2">
- {canShowAll ? <button type="button" onClick={onShowAll} className={link}>{t("task.showAll", { count: total })}</button> : <span />}
+ {canShowAll ? <button type="button" onClick={onShowAll} className={link}>{t("task.showAll", { count: total })}</button>
+ : onShowFewer ? <button type="button" data-sidebar-show-fewer onClick={onShowFewer} className={link}>{t("task.showFewer")}</button> : <span />}
{canSelect && <button type="button" onClick={bulk.start} className={link}>{t("task.bulk.select")}</button>}
</div>;
}
diff --git a/src/components/Sidebar.pinned-show-all.dom.test.ts b/src/components/Sidebar.pinned-show-all.dom.test.ts
new file mode 100644
index 0000000000..62b18c65a3
--- /dev/null
+++ b/src/components/Sidebar.pinned-show-all.dom.test.ts
@@ -0,0 +1,100 @@
+// @vitest-environment happy-dom
+import { act, createElement } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { renderToStaticMarkup } from "react-dom/server";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { initialState, type Bot } from "@/state/store";
+import { forgetSidebarShowAllForTests, SIDEBAR_SHOW_ALL_KEY } from "@/lib/sidebar-preferences";
+
+vi.mock("./DesktopCapabilities", () => ({ useDesktopCapabilities: () => ({}) }));
+vi.mock("@/lib/interface-mode", async (original) => ({ ...await original<typeof import("@/lib/interface-mode")>(), useAdvancedMode: () => true }));
+
+const { BotThreadList, botRowProps } = await import("./Sidebar");
+const { SidebarBotActivity } = await import("./SidebarBotActivity");
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+// Nine loose threads: the short list keeps six, so the oldest are hidden until "Show all".
+const loose = Array.from({ length: 9 }, (_, index) => ({ threadId: `loose-${index}`, title: `Loose chat ${index}`, createdAt: 100 + index }));
+const filed = [
+ { threadId: "filed-pinned", title: "Filed pinned", createdAt: 1_000, projectId: "folder", pinned: true },
+ { threadId: "filed-plain", title: "Filed plain", createdAt: 1_001, projectId: "folder" },
+];
+const bot: Bot = {
+ id: "maus", threadId: "loose-8", name: "Maus", title: "", description: "", notifications: true,
+ color: "green", unread: false, messages: [], modelSelection: { instanceId: "fake", model: "test" },
+ projects: [{ id: "folder", name: "Taxes" }],
+ tasks: [...loose, ...filed],
+};
+
+let host: HTMLElement;
+let root: Root;
+const mount = async () => {
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ await act(async () => {
+ root.render(createElement(BotThreadList, { ...botRowProps(initialState, vi.fn(), bot, { density: "comfortable", query: "", onMenu: vi.fn() }), selected: true }));
+ });
+};
+const unmount = async () => {
+ await act(async () => { root.unmount(); });
+ host.remove();
+};
+const button = (label: string) => [...host.querySelectorAll("button")]
+ .find((element) => element.textContent?.trim() === label || element.getAttribute("aria-label") === label);
+const click = async (label: string) => {
+ const target = button(label);
+ expect(target, label).toBeTruthy();
+ await act(async () => { target!.click(); });
+};
+const saved = () => JSON.parse(localStorage.getItem(SIDEBAR_SHOW_ALL_KEY) ?? "[]");
+
+beforeEach(() => {
+ localStorage.clear();
+ forgetSidebarShowAllForTests();
+});
+afterEach(() => { document.body.innerHTML = ""; });
+
+describe("a bot's Show all threads", () => {
+ it("stays on after the list unmounts (bot collapsed or app reloaded) until Show fewer", async () => {
+ await mount();
+ expect(host.textContent).not.toContain("Loose chat 0");
+ await click("Show all 11 threads");
+ expect(host.textContent).toContain("Loose chat 0");
+ await unmount();
+
+ forgetSidebarShowAllForTests(); // read it back from storage, as a reload would
+ expect(saved()).toEqual(["maus"]);
+ await mount();
+ expect(host.textContent).toContain("Loose chat 0");
+ expect(button("Show all 11 threads")).toBeUndefined();
+
+ await click("Show fewer threads");
+ expect(host.textContent).not.toContain("Loose chat 0");
+ expect(button("Show all 11 threads")).toBeTruthy();
+ expect(saved()).toEqual([]);
+ await unmount();
+ });
+});
+
+describe("a collapsed folder", () => {
+ it("keeps showing its pinned threads and hides the rest", async () => {
+ await mount();
+ expect(host.textContent).toContain("Filed plain");
+ await click("Collapse Taxes threads");
+ expect(host.textContent).toContain("Filed pinned");
+ expect(host.textContent).not.toContain("Filed plain");
+ await unmount();
+ });
+});
+
+describe("a collapsed bot's pinned thread", () => {
+ it("is marked pinned, not unread, when nothing is going on in it", () => {
+ const html = renderToStaticMarkup(createElement(SidebarBotActivity, {
+ bot, rowThreadId: bot.threadId, density: "comfortable", pendingQueued: {}, dispatch: vi.fn(),
+ }));
+ expect(html).toContain('aria-label="Maus: Filed pinned · Pinned"');
+ expect(html).not.toContain("Unread");
+ });
+});
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 24d7aff825..1f5a4ef0ec 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -42,7 +42,7 @@ import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { draggedFolder, FOLDER_DRAG_TYPE, moveFolder, placeFolder } from "@/lib/folder-order";
import { folderUnreadThreadIds, markFolderRead } from "@/lib/folder-read";
import { HelperThreadGroup, orderedThreadList, partitionHelperThreads, SidebarThreadRow, stampClock, threadRecency, threadRowActions, useRelativeNow, useRevealedThreadRow, useSnoozeExpiry, visibleSidebarThreads } from "./SidebarThreadRow";
-import { setSidebarDensity, useSidebarDensity, usePinnedCircles, useUniversalPins, type SidebarDensity } from "@/lib/sidebar-preferences";
+import { setSidebarDensity, useSidebarDensity, usePinnedCircles, useSidebarShowAllThreads, useUniversalPins, type SidebarDensity } from "@/lib/sidebar-preferences";
import {
ATTENTION_SECTION_ID,
BOT_CHATS_SECTION_ID,
@@ -471,7 +471,7 @@ export function BotThreadList({ bot, selected, query, pendingQueued, routineRuns
const [reorderStatus, setReorderStatus] = useState("");
const [folderDrop, setFolderDrop] = useState<{ id: string; place: "before" | "after" } | null>(null);
const draggingFolder = useRef<string | null>(null);
- const [showAll, setShowAll] = useState(false);
+ const [showAll, setShowAll] = useSidebarShowAllThreads(bot.id);
const [permissionRefresh, setPermissionRefresh] = useState<{ threadId: string; kind: "local-auto" } | null>(null);
const currentProjectId = tasks.find((task) => task.threadId === bot.threadId)?.projectId;
useEffect(() => {
@@ -612,11 +612,11 @@ export function BotThreadList({ bot, selected, query, pendingQueued, routineRuns
onEdit={() => setEditingProject(project.id)} onMove={(direction, onSaved) => saveOrder(moveFolder(projectIds, project.id, direction), onSaved)}
onMarkRead={(onSaved) => { void readFolder(project.id, onSaved); }} />
</div>
- {open && <div role="group" aria-label={t("task.namedList", { name: project.name })}>
- {visible.map(renderThread)}
+ {(open || visible.some((task) => task.pinned === true)) && <div role="group" aria-label={t("task.namedList", { name: project.name })}>
+ {(open ? visible : visible.filter((task) => task.pinned === true)).map(renderThread)}
{projectTasks.length === 0 && <p className="px-2.5 py-1 text-[11px] text-ink-tertiary">{t("task.empty")}</p>}
- {/* The short list keeps only the newest threads, so an open folder can hold none of them: offer the rest. */}
- {!query && !bulk.active && visible.length < projectTasks.length && <button type="button" data-sidebar-folder-show-all={project.id} onClick={() => setShowAll(true)}
+ {/* A closed folder shows only its pinned threads. The short list keeps only the newest threads, so an open folder can hold none of them: offer the rest. */}
+ {open && !query && !bulk.active && visible.length < projectTasks.length && <button type="button" data-sidebar-folder-show-all={project.id} onClick={() => setShowAll(true)}
className="inline-flex h-7 items-center pl-6 text-[13px] font-medium leading-4 text-ink-secondary hover:text-ink">{t("folder.showAll")}</button>}
</div>}
</div>;
@@ -629,7 +629,7 @@ export function BotThreadList({ bot, selected, query, pendingQueued, routineRuns
{ungrouped.map(renderThread)}
<HelperThreadGroup tasks={orderedThreadList(helpers)} renderThread={renderThread} />
<ThreadListFooter bulk={bulk} rows={shownRows} selected={selection} total={ownTasks.length} canShowAll={!query && !showAll && ownTasks.length > visibleTasks.length} canSelect={tasks.length > 1}
- onShowAll={() => setShowAll(true)} freshConversation onDelete={(threadIds) => deleteThreadsInBulk({ botId: bot.id }, threadIds, dispatch)} />
+ onShowAll={() => setShowAll(true)} onShowFewer={showAll && !query && !bulk.active && visibleSidebarThreads(ownTasks, bot.threadId, query, projects, false, routineRuns).length < ownTasks.length ? () => setShowAll(false) : undefined} freshConversation onDelete={(threadIds) => deleteThreadsInBulk({ botId: bot.id }, threadIds, dispatch)} />
<LocalComputerAutoWarning
open={permissionRefresh?.kind === "local-auto"}
onCancel={() => setPermissionRefresh(null)}
diff --git a/src/components/SidebarBotActivity.tsx b/src/components/SidebarBotActivity.tsx
index 493b291ba5..d86e2cfc36 100644
--- a/src/components/SidebarBotActivity.tsx
+++ b/src/components/SidebarBotActivity.tsx
@@ -216,15 +216,17 @@ export function SidebarBotActivity({ bot, rowThreadId, density, pendingQueued, d
const waiting = task.activity === "waiting-on-you";
const teammateWait = !waiting && task.waitingForTeammates === true;
const working = !waiting && !teammateWait && (task.busy || task.activity === "working");
- const status = waiting ? t("sidebar.preview.waiting") : working ? t("chat.activity.working") : teammateWait ? t("sidebar.preview.waitingOnTeammate") : task.queued ? t("task.queued") : t("task.unread");
+ // A collapsed bot keeps its pinned threads listed here; one with nothing going on is shown as pinned, not unread.
+ const pinnedOnly = !waiting && !working && !teammateWait && !task.queued && !task.unread && task.pinned === true;
+ const status = waiting ? t("sidebar.preview.waiting") : working ? t("chat.activity.working") : teammateWait ? t("sidebar.preview.waitingOnTeammate") : task.queued ? t("task.queued") : pinnedOnly ? t("task.pinned") : t("task.unread");
const title = localizedTaskTitle(task.title);
const label = `${bot.name}: ${title} · ${status}${task.unread && (waiting || working || teammateWait || task.queued) ? ` · ${t("task.unread")}` : ""}`;
- const Icon = waiting ? CircleAlert : working ? Loader2 : teammateWait || task.queued ? Clock3 : BellDot;
+ const Icon = waiting ? CircleAlert : working ? Loader2 : teammateWait || task.queued ? Clock3 : pinnedOnly ? Pin : BellDot;
return <button key={task.threadId} type="button" data-sidebar-activity-row={task.threadId} aria-label={label} title={label}
onClick={() => dispatch({ type: "switchTask", botId: bot.id, threadId: task.threadId })}
className={cn("flex min-h-7 w-full min-w-0 items-center gap-1.5 rounded-md px-2 py-1 text-left text-[11px] outline-none hover:bg-raised/50 focus-visible:ring-1 focus-visible:ring-accent/60", iconOnly && "justify-center", waiting ? "text-warning" : "text-ink-secondary")}>
<Icon size={12} aria-hidden="true" className={cn("shrink-0", working && "animate-spin text-success", teammateWait && "text-warning", task.unread && !waiting && !working && !teammateWait && "text-accent")} />
- {!iconOnly && <><span className="min-w-0 flex-1 truncate">{title}</span><span className="shrink-0 text-[10px]">{waiting ? t("task.waiting") : status}</span>
+ {!iconOnly && <><span className="min-w-0 flex-1 truncate">{title}</span>{!pinnedOnly && <span className="shrink-0 text-[10px]">{waiting ? t("task.waiting") : status}</span>}
{task.unread && (waiting || working || teammateWait || task.queued) && <span className="size-1.5 shrink-0 rounded-full bg-accent" aria-hidden="true" />}</>}
</button>;
})}
diff --git a/src/lib/sidebar-preferences.ts b/src/lib/sidebar-preferences.ts
index 1e639054be..e4c7871fc3 100644
--- a/src/lib/sidebar-preferences.ts
+++ b/src/lib/sidebar-preferences.ts
@@ -457,3 +457,53 @@ export function saveSimpleSectionOrder(
): void {
saveStringList(SIMPLE_SIDEBAR_SECTION_ORDER_KEY, ids, storage);
}
+
+/** Bots whose sidebar thread list stays at "Show all N threads" until the person picks "Show fewer". */
+export const SIDEBAR_SHOW_ALL_KEY = "openmausbot.sidebarShowAllThreads.v1";
+
+let showAllBots: ReadonlySet<string> | null = null;
+const showAllListeners = new Set<() => void>();
+
+function currentShowAllBots(): ReadonlySet<string> {
+ showAllBots ??= new Set(loadStringList(SIDEBAR_SHOW_ALL_KEY));
+ return showAllBots;
+}
+
+function notifyShowAll(): void {
+ for (const listener of showAllListeners) listener();
+}
+
+function onShowAllStorage(event: StorageEvent): void {
+ if (event.key !== null && event.key !== SIDEBAR_SHOW_ALL_KEY) return;
+ if (event.storageArea && event.storageArea !== globalThis.localStorage) return;
+ showAllBots = null;
+ notifyShowAll();
+}
+
+function subscribeShowAll(listener: () => void): () => void {
+ if (showAllListeners.size === 0) globalThis.addEventListener?.("storage", onShowAllStorage);
+ showAllListeners.add(listener);
+ return () => {
+ showAllListeners.delete(listener);
+ if (showAllListeners.size === 0) globalThis.removeEventListener?.("storage", onShowAllStorage);
+ };
+}
+
+export function setSidebarShowAllThreads(botId: string, showAll: boolean): void {
+ const saved = currentShowAllBots();
+ if (saved.has(botId) === showAll) return;
+ // Newest first, so the stored list's cap drops the oldest bots.
+ const next = showAll ? [botId, ...saved] : [...saved].filter((id) => id !== botId);
+ showAllBots = new Set(saveStringList(SIDEBAR_SHOW_ALL_KEY, next));
+ notifyShowAll();
+}
+
+/** A bot's "Show all N threads", remembered so it survives collapsing the bot and reloading the app. */
+export function useSidebarShowAllThreads(botId: string): [boolean, (showAll: boolean) => void] {
+ const read = () => currentShowAllBots().has(botId);
+ return [useSyncExternalStore(subscribeShowAll, read, () => false), (showAll) => setSidebarShowAllThreads(botId, showAll)];
+}
+
+export function forgetSidebarShowAllForTests(): void {
+ showAllBots = null;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index 8e7141ff4f..0bde9e930a 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -3261,6 +3261,8 @@
"task.collapseNamed": "Collapse {name} threads",
"task.expandNamed": "Expand {name} threads",
"task.showAll": "Show all {count} threads",
+ "task.showFewer": "Show fewer threads",
+ "task.pinned": "Pinned",
"task.bulk.select": "Select threads",
"task.bulk.done": "Done",
"task.bulk.selectAll": "Select all",