feat: add session pinning for pinned/recent session groups (#301)

* feat: add session pinning for pinned/recent session groups

* refactor: extract buildSessionKey, deduplicate SessionCard rendering, clean up pins on delete
This commit is contained in:
Chris Scott authored and GitHub committed 2026-06-30 19:22:26 -04:00
1 parent 217f5bd989
commit a9b6f7ce46
21 files changed
+762 -58

No files matched your search

@@ -0,0 +1,36 @@
import type { Session } from '@/api/types'
export interface PartitionedSessions {
pinned: Session[]
today: Session[]
older: Session[]
}
export function partitionSessions(
sessions: Session[],
pinnedKeys: Set<string>,
keyFn: (session: { id: string; directory?: string }) => 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 }
}