From fb4b38471b8c3fa3013b3c07dfcefe28ae428676 Mon Sep 17 00:00:00 2001 From: George Date: Wed, 15 Apr 2026 02:59:22 -0700 Subject: [PATCH] fix(ui): sync sidebar sessions after chat history deletion (#7707) Signed-off-by: George Co-authored-by: George --- ui/desktop/src/hooks/useNavigationSessions.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ui/desktop/src/hooks/useNavigationSessions.ts b/ui/desktop/src/hooks/useNavigationSessions.ts index be99d1a6..2ce10b1a 100644 --- a/ui/desktop/src/hooks/useNavigationSessions.ts +++ b/ui/desktop/src/hooks/useNavigationSessions.ts @@ -138,6 +138,39 @@ export function useNavigationSessions(options: UseNavigationSessionsOptions = {} }; }, []); + useEffect(() => { + const handleSessionDeleted = (event: Event) => { + const { sessionId } = (event as CustomEvent<{ sessionId: string }>).detail; + + setRecentSessions((prev) => prev.filter((session) => session.id !== sessionId)); + sessionsRef.current = sessionsRef.current.filter((session) => session.id !== sessionId); + + if (lastSessionIdRef.current === sessionId) { + lastSessionIdRef.current = null; + } + }; + + const handleSessionRenamed = (event: Event) => { + const { sessionId, newName } = + (event as CustomEvent<{ sessionId: string; newName: string }>).detail; + + setRecentSessions((prev) => + prev.map((session) => (session.id === sessionId ? { ...session, name: newName } : session)) + ); + sessionsRef.current = sessionsRef.current.map((session) => + session.id === sessionId ? { ...session, name: newName } : session + ); + }; + + window.addEventListener(AppEvents.SESSION_DELETED, handleSessionDeleted); + window.addEventListener(AppEvents.SESSION_RENAMED, handleSessionRenamed); + + return () => { + window.removeEventListener(AppEvents.SESSION_DELETED, handleSessionDeleted); + window.removeEventListener(AppEvents.SESSION_RENAMED, handleSessionRenamed); + }; + }, []); + const handleNavClick = useCallback( (path: string) => { if (path === '/pair') {