mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
* 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
65 lines
1.7 KiB
TypeScript
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 }
|
|
}
|