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.
This commit is contained in:
@@ -10,9 +10,11 @@ import { showToastNotification } from "../lib/notifications"
|
|||||||
import {
|
import {
|
||||||
deleteSession,
|
deleteSession,
|
||||||
ensureSessionParentExpanded,
|
ensureSessionParentExpanded,
|
||||||
|
getVisibleSessionIds,
|
||||||
isSessionParentExpanded,
|
isSessionParentExpanded,
|
||||||
loading,
|
loading,
|
||||||
renameSession,
|
renameSession,
|
||||||
|
setActiveSessionFromList,
|
||||||
toggleSessionParentExpanded,
|
toggleSessionParentExpanded,
|
||||||
} from "../stores/sessions"
|
} from "../stores/sessions"
|
||||||
import { getLogger } from "../lib/logger"
|
import { getLogger } from "../lib/logger"
|
||||||
@@ -84,9 +86,45 @@ const SessionList: Component<SessionListProps> = (props) => {
|
|||||||
const handleDeleteSession = async (event: MouseEvent, sessionId: string) => {
|
const handleDeleteSession = async (event: MouseEvent, sessionId: string) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
if (isSessionDeleting(sessionId)) return
|
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 {
|
try {
|
||||||
await deleteSession(props.instanceId, sessionId)
|
await deleteSession(props.instanceId, sessionId)
|
||||||
|
if (fallbackSessionId) {
|
||||||
|
setActiveSessionFromList(props.instanceId, fallbackSessionId)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Failed to delete session ${sessionId}:`, error)
|
log.error(`Failed to delete session ${sessionId}:`, error)
|
||||||
showToastNotification({ message: "Unable to delete session", variant: "error" })
|
showToastNotification({ message: "Unable to delete session", variant: "error" })
|
||||||
|
|||||||
Reference in New Issue
Block a user