feat(ui): session nav follows visible list
Cmd+Shift+[ and Cmd+Shift+] now cycle through visible sessions only (parents + expanded children) and no longer include Instance Info. Sidebar session list auto-scrolls to keep the active session row in view.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createSignal } from "solid-js"
|
||||
import { batch, createSignal } from "solid-js"
|
||||
|
||||
import type { Session, SessionStatus, Agent, Provider } from "../types/session"
|
||||
import { deleteSession, loadMessages } from "./session-api"
|
||||
@@ -46,6 +46,8 @@ const [loading, setLoading] = createSignal({
|
||||
const [messagesLoaded, setMessagesLoaded] = createSignal<Map<string, Set<string>>>(new Map())
|
||||
const [sessionInfoByInstance, setSessionInfoByInstance] = createSignal<Map<string, Map<string, SessionInfo>>>(new Map())
|
||||
|
||||
const [expandedSessionParents, setExpandedSessionParents] = createSignal<Map<string, Set<string>>>(new Map())
|
||||
|
||||
export type InstanceSessionIndicatorStatus = "permission" | SessionStatus
|
||||
|
||||
type InstanceIndicatorCounts = {
|
||||
@@ -430,6 +432,91 @@ function getSessionThreads(instanceId: string): SessionThread[] {
|
||||
return threads
|
||||
}
|
||||
|
||||
function isSessionParentExpanded(instanceId: string, parentSessionId: string): boolean {
|
||||
return Boolean(expandedSessionParents().get(instanceId)?.has(parentSessionId))
|
||||
}
|
||||
|
||||
function setSessionParentExpanded(instanceId: string, parentSessionId: string, expanded: boolean): void {
|
||||
setExpandedSessionParents((prev) => {
|
||||
const next = new Map(prev)
|
||||
const currentSet = next.get(instanceId) ?? new Set<string>()
|
||||
const updated = new Set(currentSet)
|
||||
|
||||
if (expanded) {
|
||||
updated.add(parentSessionId)
|
||||
} else {
|
||||
updated.delete(parentSessionId)
|
||||
}
|
||||
|
||||
if (updated.size === 0) {
|
||||
next.delete(instanceId)
|
||||
} else {
|
||||
next.set(instanceId, updated)
|
||||
}
|
||||
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
function toggleSessionParentExpanded(instanceId: string, parentSessionId: string): void {
|
||||
setExpandedSessionParents((prev) => {
|
||||
const next = new Map(prev)
|
||||
const currentSet = next.get(instanceId) ?? new Set<string>()
|
||||
const updated = new Set(currentSet)
|
||||
|
||||
if (updated.has(parentSessionId)) {
|
||||
updated.delete(parentSessionId)
|
||||
} else {
|
||||
updated.add(parentSessionId)
|
||||
}
|
||||
|
||||
next.set(instanceId, updated)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
function ensureSessionParentExpanded(instanceId: string, parentSessionId: string): void {
|
||||
if (isSessionParentExpanded(instanceId, parentSessionId)) return
|
||||
setSessionParentExpanded(instanceId, parentSessionId, true)
|
||||
}
|
||||
|
||||
function getVisibleSessionIds(instanceId: string): string[] {
|
||||
const threads = getSessionThreads(instanceId)
|
||||
if (threads.length === 0) return []
|
||||
|
||||
const expanded = expandedSessionParents().get(instanceId)
|
||||
const ids: string[] = []
|
||||
|
||||
for (const thread of threads) {
|
||||
ids.push(thread.parent.id)
|
||||
if (expanded?.has(thread.parent.id)) {
|
||||
for (const child of thread.children) {
|
||||
ids.push(child.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
function setActiveSessionFromList(instanceId: string, sessionId: string): void {
|
||||
const session = sessions().get(instanceId)?.get(sessionId)
|
||||
if (!session) return
|
||||
|
||||
if (session.parentId === null) {
|
||||
setActiveParentSession(instanceId, sessionId)
|
||||
return
|
||||
}
|
||||
|
||||
const parentId = session.parentId
|
||||
if (!parentId) return
|
||||
|
||||
batch(() => {
|
||||
setActiveParentSession(instanceId, parentId)
|
||||
setActiveSession(instanceId, sessionId)
|
||||
})
|
||||
}
|
||||
|
||||
function isSessionBusy(instanceId: string, sessionId: string): boolean {
|
||||
const instanceSessions = sessions().get(instanceId)
|
||||
if (!instanceSessions) return false
|
||||
@@ -586,6 +673,12 @@ export {
|
||||
getChildSessions,
|
||||
getSessionFamily,
|
||||
getSessionThreads,
|
||||
getVisibleSessionIds,
|
||||
isSessionParentExpanded,
|
||||
setSessionParentExpanded,
|
||||
toggleSessionParentExpanded,
|
||||
ensureSessionParentExpanded,
|
||||
setActiveSessionFromList,
|
||||
isSessionBusy,
|
||||
isSessionMessagesLoading,
|
||||
getSessionInfo,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
clearActiveParentSession,
|
||||
clearInstanceDraftPrompts,
|
||||
clearSessionDraftPrompt,
|
||||
ensureSessionParentExpanded,
|
||||
getActiveParentSession,
|
||||
getActiveSession,
|
||||
getChildSessions,
|
||||
@@ -18,17 +19,22 @@ import {
|
||||
getSessionInfo,
|
||||
getSessionThreads,
|
||||
getSessions,
|
||||
getVisibleSessionIds,
|
||||
isSessionBusy,
|
||||
isSessionMessagesLoading,
|
||||
isSessionParentExpanded,
|
||||
loading,
|
||||
providers,
|
||||
sessionInfoByInstance,
|
||||
sessions,
|
||||
setActiveParentSession,
|
||||
setActiveSession,
|
||||
setActiveSessionFromList,
|
||||
setSessionDraftPrompt,
|
||||
setSessionParentExpanded,
|
||||
setSessionStatus,
|
||||
} from "./session-state"
|
||||
toggleSessionParentExpanded,
|
||||
} from "./session-state"
|
||||
|
||||
import { getDefaultModel } from "./session-models"
|
||||
import {
|
||||
@@ -86,6 +92,7 @@ export {
|
||||
clearSessionDraftPrompt,
|
||||
createSession,
|
||||
deleteSession,
|
||||
ensureSessionParentExpanded,
|
||||
executeCustomCommand,
|
||||
renameSession,
|
||||
runShellCommand,
|
||||
@@ -103,8 +110,10 @@ export {
|
||||
getSessionInfo,
|
||||
getSessionThreads,
|
||||
getSessions,
|
||||
getVisibleSessionIds,
|
||||
isSessionBusy,
|
||||
isSessionMessagesLoading,
|
||||
isSessionParentExpanded,
|
||||
loadMessages,
|
||||
loading,
|
||||
providers,
|
||||
@@ -113,8 +122,11 @@ export {
|
||||
sessions,
|
||||
setActiveParentSession,
|
||||
setActiveSession,
|
||||
setActiveSessionFromList,
|
||||
setSessionDraftPrompt,
|
||||
setSessionParentExpanded,
|
||||
setSessionStatus,
|
||||
toggleSessionParentExpanded,
|
||||
updateSessionAgent,
|
||||
updateSessionModel,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user