mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
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:
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 }
|
||||
}
|
||||
Reference in new issue
Block a user