@@ -116,6 +116,25 @@ export default function Layout(props: ParentProps) {
116116 }
117117 } )
118118
119+ function sortSessions ( a : Session , b : Session ) {
120+ const now = Date . now ( )
121+ const oneMinuteAgo = now - 60 * 1000
122+ const aUpdated = a . time . updated ?? a . time . created
123+ const bUpdated = b . time . updated ?? b . time . created
124+ const aRecent = aUpdated > oneMinuteAgo
125+ const bRecent = bUpdated > oneMinuteAgo
126+
127+ // If both are recent (within last minute), sort by ID to prevent jumping
128+ if ( aRecent && bRecent ) return a . id . localeCompare ( b . id )
129+
130+ // Recent sessions come before non-recent
131+ if ( aRecent && ! bRecent ) return - 1
132+ if ( ! aRecent && bRecent ) return 1
133+
134+ // Neither is recent, sort by update time descending
135+ return bUpdated - aUpdated
136+ }
137+
119138 function flattenSessions ( sessions : Session [ ] ) : Session [ ] {
120139 const childrenMap = new Map < string , Session [ ] > ( )
121140 for ( const session of sessions ) {
@@ -148,9 +167,7 @@ export default function Layout(props: ParentProps) {
148167
149168 function projectSessions ( directory : string ) {
150169 if ( ! directory ) return [ ]
151- const sessions = globalSync
152- . child ( directory ) [ 0 ]
153- . session . toSorted ( ( a , b ) => ( b . time . updated ?? b . time . created ) - ( a . time . updated ?? a . time . created ) )
170+ const sessions = globalSync . child ( directory ) [ 0 ] . session . toSorted ( sortSessions )
154171 return flattenSessions ( sessions ?? [ ] )
155172 }
156173
@@ -552,9 +569,7 @@ export default function Layout(props: ParentProps) {
552569 const slug = createMemo ( ( ) => base64Encode ( props . project . worktree ) )
553570 const name = createMemo ( ( ) => getFilename ( props . project . worktree ) )
554571 const [ store , setProjectStore ] = globalSync . child ( props . project . worktree )
555- const sessions = createMemo ( ( ) =>
556- store . session . toSorted ( ( a , b ) => ( b . time . updated ?? b . time . created ) - ( a . time . updated ?? a . time . created ) ) ,
557- )
572+ const sessions = createMemo ( ( ) => store . session . toSorted ( sortSessions ) )
558573 const rootSessions = createMemo ( ( ) => sessions ( ) . filter ( ( s ) => ! s . parentID ) )
559574 const childSessionsByParent = createMemo ( ( ) => {
560575 const map = new Map < string , Session [ ] > ( )
0 commit comments