Files
opencode-manager/frontend/src/components/session/session-partition.ts
T
Chris Scott 015a44a5f3 feat(sidebar): add repo-grouped session navigation with live status (#361)
* feat(sidebar): add repo-grouped session navigation with live status

- Add a searchable, collapsible session tree to the desktop sidebar, grouped by repository with pinned and time-bucketed ordering.
- Track per-session busy, retry, and compact status in a shared store fed by the SSE event stream and scoped by directory.
- Extract shared navigation components reused by the desktop tree and the mobile repo quick-switch sheet.
- Show a Git tab and hide Schedules inside a repo on the mobile tab bar; add Repos and Assistant entries to the session More drawer.
- Replace the CommitsTab local relative-time formatter with a shared formatShortRelativeTime util.

* refactor(sidebar): unify session status tracking and navigation helpers

* feat(sidebar): add collapsible sessions and menu sections

* fix(sessions): keep specific live status over snapshot busy
2026-09-26 21:50:23 -04:00

65 lines
1.7 KiB
TypeScript

import type { Session } from '@/api/types'
export interface PartitionedSessions {
pinned: Session[]
today: Session[]
older: Session[]
}
export interface SelectRootSessionsOptions {
directories?: ReadonlySet<string>
keyFn: (session: Session) => string
}
export function selectRootSessions(
sessions: Session[],
options: SelectRootSessionsOptions,
): Session[] {
const { directories, keyFn } = options
const roots = sessions.filter((session) => {
if (session.parentID) return false
const directory = session.location.directory
if (directories && directories.size > 0 && directory && !directories.has(directory)) return false
return true
})
const uniqueSessions = new Map<string, Session>()
for (const session of roots) {
const key = keyFn(session)
if (!uniqueSessions.has(key)) {
uniqueSessions.set(key, session)
}
}
return Array.from(uniqueSessions.values()).sort((a, b) => b.time.updated - a.time.updated)
}
export function partitionSessions(
sessions: Session[],
pinnedKeys: ReadonlySet<string>,
keyFn: (session: Session) => string,
now: number = Date.now(),
): PartitionedSessions {
const startOfDay = new Date(now)
startOfDay.setHours(0, 0, 0, 0)
const startMs = startOfDay.getTime()
const byUpdatedDesc = (a: Session, b: Session) => b.time.updated - a.time.updated
const pinned: Session[] = []
const today: Session[] = []
const older: Session[] = []
for (const s of sessions) {
if (pinnedKeys.has(keyFn(s))) {
pinned.push(s)
} else if (s.time.updated >= startMs) {
today.push(s)
} else {
older.push(s)
}
}
pinned.sort(byUpdatedDesc)
today.sort(byUpdatedDesc)
older.sort(byUpdatedDesc)
return { pinned, today, older }
}