fix(ui): sync sidebar sessions after chat history deletion (#7707)

Signed-off-by: George <george@zuos.us>
Co-authored-by: George <george@zuos.us>
This commit is contained in:
George
2026-04-15 02:59:22 -07:00
committed by GitHub
parent b7f1316ab8
commit fb4b38471b
@@ -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') {