Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(chat-sidebar): collapsible recents + unfocus on section switch

Louis Beaumonta8fbdf37fa89
diff --git a/apps/screenpipe-app-tauri/app/home/page.tsx b/apps/screenpipe-app-tauri/app/home/page.tsx
index 698805d2a..1012170f4 100644
--- a/apps/screenpipe-app-tauri/app/home/page.tsx
+++ b/apps/screenpipe-app-tauri/app/home/page.tsx
@@ -136,6 +136,21 @@ function HomeContent() {
};
}, [setActiveSection]);
+ // Clear the sidebar's "current" highlight when leaving the chat
+ // view; restore it from panelSessionId when coming back. The chat
+ // panel stays mounted (display:none) and keeps streaming, but
+ // visually the row shouldn't look "selected" while the user is
+ // looking at Pipes/Memories/etc.
+ useEffect(() => {
+ const { actions } = useChatStore.getState();
+ if (activeSection === "home") {
+ const panelId = useChatStore.getState().panelSessionId;
+ if (panelId) actions.setCurrent(panelId);
+ } else {
+ actions.setCurrent(null);
+ }
+ }, [activeSection]);
+
// Sidebar collapse state (persisted in localStorage)
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
const [teamPromoDismissed, setTeamPromoDismissed] = useState(false);
diff --git a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
index 904c09448..ad7a589bc 100644
--- a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
+++ b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
@@ -31,8 +31,8 @@
* a separate "delete forever" action would unlink the file.
*/
-import React, { useEffect, useMemo } from "react";
-import { Pin, X, AlertCircle } from "lucide-react";
+import React, { useEffect, useMemo, useState } from "react";
+import { Pin, X, AlertCircle, ChevronDown, ChevronRight } from "lucide-react";
import { emit, listen } from "@tauri-apps/api/event";
import { cn } from "@/lib/utils";
import {
@@ -117,7 +117,14 @@ export function ChatSidebar({ className }: ChatSidebarProps) {
};
const handleSelect = (id: string) => {
- if (id === currentId) return; // already on it, no-op
+ // No early return for id === currentId. Two reasons:
+ // 1. The user may be on a non-home section (Pipes/Memories/...);
+ // currentId is cleared in that case, but even if it weren't,
+ // we want the click to navigate back to home.
+ // 2. The click is the user's "show me this chat" intent — let
+ // the page-level chat-load-conversation listener flip the
+ // view; standalone-chat skips the snapshot+swap when the id
+ // already matches its piSessionIdRef so there's no flicker.
actions.setCurrent(id);
emit("chat-load-conversation", { conversationId: id });
};
@@ -170,62 +177,122 @@ export function ChatSidebar({ className }: ChatSidebarProps) {
}
};
+ // Layout contract:
+ // - Pinned section (header + rows) sits at the top, non-scrolling.
+ // It's typically a handful of rows so it doesn't need its own
+ // scroll viewport.
+ // - Recents section header is FIXED (does not scroll with the
+ // rows). Clicking it toggles a collapse/expand of the rows.
+ // - Only the rows under the recents header scroll. With 200 chats
+ // the header stays glued in place while the user scrubs the
+ // list — matches every chat client (Claude, Slack, iMessage).
+ // Persist the collapse state in localStorage so it survives reload
+ // and matches the user's expectation of "I closed it, leave it
+ // closed".
return (
- // No `h-full`. The wrapper sizes to its CONTENT (sections + rows) but
- // the inner scroll region caps at `max-h-full` so a 500-row history
- // doesn't blow past the available sidebar height. Without this, an
- // earlier `h-full + flex-1` made the scroll viewport always equal to
- // the parent's flex-1 share — even with 8 rows of content, you could
- // drag the scrollbar through hundreds of pixels of dead space.
<div
className={cn("flex flex-col min-h-0 text-sm", className)}
data-testid="chat-sidebar"
>
- <div
- className="overflow-y-auto overflow-x-hidden"
- style={{ maxHeight: "100%" }}
+ {pinned.length > 0 && (
+ <Section title="pinned">
+ {pinned.map((s) => (
+ <ChatRow
+ key={s.id}
+ session={s}
+ isCurrent={s.id === currentId}
+ onSelect={handleSelect}
+ onClose={handleClose}
+ onTogglePin={handleTogglePin}
+ />
+ ))}
+ </Section>
+ )}
+
+ {/* Recents — fixed header + collapsible scrollable body. The
+ flex-1 + min-h-0 pair is what makes the inner overflow-y-auto
+ actually work without leaking past the sidebar bottom. */}
+ <CollapsibleRecents
+ empty={recents.length === 0}
+ emptyText={
+ pinned.length === 0
+ ? "no chats yet — click + to start"
+ : "no recent chats"
+ }
>
- {pinned.length > 0 && (
- <Section title="pinned">
- {pinned.map((s) => (
- <ChatRow
- key={s.id}
- session={s}
- isCurrent={s.id === currentId}
- onSelect={handleSelect}
- onClose={handleClose}
- onTogglePin={handleTogglePin}
- />
- ))}
- </Section>
- )}
+ {recents.map((s) => (
+ <ChatRow
+ key={s.id}
+ session={s}
+ isCurrent={s.id === currentId}
+ onSelect={handleSelect}
+ onClose={handleClose}
+ onTogglePin={handleTogglePin}
+ />
+ ))}
+ </CollapsibleRecents>
+ </div>
+ );
+}
- {/* No "+" action here — the "New chat" item in the main nav
- (top of the sidebar) is the single new-conversation entry
- point. Two affordances for the same thing was confusing. */}
- <Section title="recents">
- {recents.length === 0 && pinned.length === 0 ? (
- <div className="px-3 py-2 text-xs text-muted-foreground/70 italic">
- no chats yet — click + to start
- </div>
- ) : recents.length === 0 ? (
+/** Recents container with a fixed (non-scrolling) header and a
+ * scrollable body underneath. Click the header to collapse. */
+function CollapsibleRecents({
+ empty,
+ emptyText,
+ children,
+}: {
+ empty: boolean;
+ emptyText: string;
+ children: React.ReactNode;
+}) {
+ const [collapsed, setCollapsedRaw] = useState<boolean>(() => {
+ try {
+ return localStorage.getItem("screenpipe:recents-collapsed") === "true";
+ } catch {
+ return false;
+ }
+ });
+ const setCollapsed = (v: boolean) => {
+ setCollapsedRaw(v);
+ try {
+ localStorage.setItem("screenpipe:recents-collapsed", String(v));
+ } catch {
+ // ignore — collapse state is best-effort
+ }
+ };
+ return (
+ <div className="flex flex-col flex-1 min-h-0 mb-2">
+ <button
+ type="button"
+ onClick={() => setCollapsed(!collapsed)}
+ className="shrink-0 px-3 py-1.5 flex items-center gap-1 hover:bg-muted/30 rounded-md mx-1 text-left"
+ aria-expanded={!collapsed}
+ aria-controls="chat-sidebar-recents"
+ >
+ {collapsed ? (
+ <ChevronRight className="h-3 w-3 text-muted-foreground/60 shrink-0" />
+ ) : (
+ <ChevronDown className="h-3 w-3 text-muted-foreground/60 shrink-0" />
+ )}
+ <span className="text-[10px] uppercase tracking-wider text-muted-foreground/60">
+ recents
+ </span>
+ </button>
+ {!collapsed && (
+ <div
+ id="chat-sidebar-recents"
+ className="flex-1 min-h-0 overflow-y-auto overflow-x-hidden"
+ >
+ {empty ? (
<div className="px-3 py-2 text-xs text-muted-foreground/70 italic">
- no recent chats
+ {emptyText}
</div>
) : (
- recents.map((s) => (
- <ChatRow
- key={s.id}
- session={s}
- isCurrent={s.id === currentId}
- onSelect={handleSelect}
- onClose={handleClose}
- onTogglePin={handleTogglePin}
- />
- ))
+ <div className="flex flex-col">{children}</div>
)}
- </Section>
- </div>
+ </div>
+ )}
</div>
);
}
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index ffb264176..cfba5dda0 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -1652,6 +1652,19 @@ export function StandaloneChat({
const { loadConversationFile } = await import("@/lib/chat-storage");
const { useChatStore } = await import("@/lib/stores/chat-store");
+ // 0) Already on this conversation — skip the snapshot+swap. The
+ // page-level listener handles navigation back to home; we
+ // just make sure currentId reflects the panel so the sidebar
+ // re-highlights the row. Without this short-circuit, clicking
+ // the already-loaded chat from a non-home section would
+ // snapshot+reset+rehydrate the same id and briefly blank the
+ // panel.
+ if (convId === piSessionIdRef.current) {
+ useChatStore.getState().actions.setCurrent(convId);
+ emit("chat-current-session", { id: convId });
+ return;
+ }
+
// 1) Disk first — saved conversations are the canonical source.
const conv = await loadConversationFile(convId);
if (conv) {
@@ -1695,9 +1708,13 @@ export function StandaloneChat({
// assigns or resumes a session id. Without this the sidebar wouldn't
// know about session changes initiated inside the chat (in-panel "new",
// chat-prefill auto-send, history pick from the in-panel history view).
+ // Also mirror to chat-store.panelSessionId so the home page can restore
+ // the sidebar highlight when the user navigates back from a non-chat
+ // section without us emitting an event.
useEffect(() => {
if (!conversationId) return;
emit("chat-current-session", { id: conversationId });
+ useChatStore.getState().actions.setPanelSession(conversationId);
}, [conversationId]);
// If the Pi pool evicted the session we're currently viewing, swap the
diff --git a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
index 701326e14..b4dde13b0 100644
--- a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
+++ b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
@@ -109,8 +109,16 @@ export interface SessionRecord {
interface ChatStoreState {
/** All known sessions, keyed by id. Includes both alive and on-disk-only. */
sessions: Record<string, SessionRecord>;
- /** Currently focused session — the chat panel renders this one. */
+ /** Currently FOCUSED session — i.e. the chat the user is actively
+ * looking at. Cleared when the user navigates away from the chat
+ * view (Pipes/Memories/...) so the sidebar row stops being
+ * highlighted. Distinct from `panelSessionId` which never clears. */
currentId: string | null;
+ /** The chat the panel is rendering right now, regardless of whether
+ * the panel is visible. Tracks `piSessionIdRef.current`. The home
+ * page reads this to restore the sidebar highlight when the user
+ * navigates back from a non-chat section. */
+ panelSessionId: string | null;
}
interface ChatStoreActions {
@@ -126,6 +134,10 @@ interface ChatStoreActions {
/** Mark a session as currently in front. Implicitly clears its unread
* flag — viewing the chat counts as reading it. */
setCurrent: (id: string | null) => void;
+ /** Mirror of the panel's piSessionIdRef.current. Survives section
+ * switches; used to re-highlight the sidebar row when the user
+ * navigates back to home. */
+ setPanelSession: (id: string | null) => void;
/** Toggle the pinned state. */
togglePinned: (id: string) => void;
/** Mark a session as having new unseen assistant activity. The router
@@ -206,6 +218,7 @@ export type ChatStore = ChatStoreState & { actions: ChatStoreActions };
export const useChatStore = create<ChatStore>((set) => ({
sessions: {},
currentId: null,
+ panelSessionId: null,
actions: {
hydrateFromDisk: (records) =>
set((s) => {
@@ -281,6 +294,8 @@ export const useChatStore = create<ChatStore>((set) => ({
return { currentId: id };
}),
+ setPanelSession: (id) => set({ panelSessionId: id }),
+
togglePinned: (id) =>
set((s) => {
const existing = s.sessions[id];
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index 187f6f1ff..dbfa04094 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "2.4.71"
+version = "2.4.72"
description = "24/7 memory for your desktop. 100% local."
authors = ["you"]
license = ""