From 1081bfb276bc2051c85afa296f2768f92d3aaaa6 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Fri, 9 Jan 2026 18:53:00 +0000 Subject: [PATCH] fix(ui): keep session view after delete When deleting the active session from the sidebar list, automatically select a nearby visible session instead of falling back to the info view. --- packages/ui/src/components/session-list.tsx | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/session-list.tsx b/packages/ui/src/components/session-list.tsx index e0c123be..9bd7fa09 100644 --- a/packages/ui/src/components/session-list.tsx +++ b/packages/ui/src/components/session-list.tsx @@ -10,9 +10,11 @@ import { showToastNotification } from "../lib/notifications" import { deleteSession, ensureSessionParentExpanded, + getVisibleSessionIds, isSessionParentExpanded, loading, renameSession, + setActiveSessionFromList, toggleSessionParentExpanded, } from "../stores/sessions" import { getLogger } from "../lib/logger" @@ -84,9 +86,45 @@ const SessionList: Component = (props) => { const handleDeleteSession = async (event: MouseEvent, sessionId: string) => { event.stopPropagation() if (isSessionDeleting(sessionId)) return - + + const shouldSelectFallback = props.activeSessionId === sessionId + let fallbackSessionId: string | undefined + + if (shouldSelectFallback) { + const visible = getVisibleSessionIds(props.instanceId) + const currentIndex = visible.indexOf(sessionId) + const remaining = visible.filter((id) => id !== sessionId) + + if (remaining.length > 0) { + if (currentIndex !== -1) { + for (let i = currentIndex; i < visible.length; i++) { + const candidate = visible[i] + if (candidate && candidate !== sessionId) { + fallbackSessionId = candidate + break + } + } + + if (!fallbackSessionId) { + for (let i = currentIndex - 1; i >= 0; i--) { + const candidate = visible[i] + if (candidate && candidate !== sessionId) { + fallbackSessionId = candidate + break + } + } + } + } + + fallbackSessionId ??= remaining[0] + } + } + try { await deleteSession(props.instanceId, sessionId) + if (fallbackSessionId) { + setActiveSessionFromList(props.instanceId, fallbackSessionId) + } } catch (error) { log.error(`Failed to delete session ${sessionId}:`, error) showToastNotification({ message: "Unable to delete session", variant: "error" })