@@ -122,10 +122,18 @@ export default function Layout(props: ParentProps) {
122122 }
123123 }
124124
125+ function projectSessions ( directory : string ) {
126+ if ( ! directory ) return [ ]
127+ const sessions = globalSync
128+ . child ( directory ) [ 0 ]
129+ . session . toSorted ( ( a , b ) => ( b . time . updated ?? b . time . created ) - ( a . time . updated ?? a . time . created ) )
130+ return flattenSessions ( sessions ?? [ ] )
131+ }
132+
125133 const currentSessions = createMemo ( ( ) => {
126134 if ( ! params . dir ) return [ ]
127135 const directory = base64Decode ( params . dir )
128- return flattenSessions ( globalSync . child ( directory ) [ 0 ] . session ?? [ ] )
136+ return projectSessions ( directory )
129137 } )
130138
131139 function navigateSessionByOffset ( offset : number ) {
@@ -162,7 +170,7 @@ export default function Layout(props: ParentProps) {
162170 const nextProject = projects [ nextProjectIndex ]
163171 if ( ! nextProject ) return
164172
165- const nextProjectSessions = flattenSessions ( globalSync . child ( nextProject . worktree ) [ 0 ] . session ?? [ ] )
173+ const nextProjectSessions = projectSessions ( nextProject . worktree )
166174 if ( nextProjectSessions . length === 0 ) {
167175 navigateToProject ( nextProject . worktree )
168176 return
@@ -511,7 +519,9 @@ export default function Layout(props: ParentProps) {
511519 const slug = createMemo ( ( ) => base64Encode ( props . project . worktree ) )
512520 const name = createMemo ( ( ) => getFilename ( props . project . worktree ) )
513521 const [ store , setProjectStore ] = globalSync . child ( props . project . worktree )
514- const sessions = createMemo ( ( ) => store . session ?? [ ] )
522+ const sessions = createMemo ( ( ) =>
523+ store . session . toSorted ( ( a , b ) => ( b . time . updated ?? b . time . created ) - ( a . time . updated ?? a . time . created ) ) ,
524+ )
515525 const rootSessions = createMemo ( ( ) => sessions ( ) . filter ( ( s ) => ! s . parentID ) )
516526 const childSessionsByParent = createMemo ( ( ) => {
517527 const map = new Map < string , Session [ ] > ( )
@@ -526,7 +536,7 @@ export default function Layout(props: ParentProps) {
526536 } )
527537 const hasMoreSessions = createMemo ( ( ) => store . session . length >= store . limit )
528538 const loadMoreSessions = async ( ) => {
529- setProjectStore ( "limit" , ( limit ) => limit + 10 )
539+ setProjectStore ( "limit" , ( limit ) => limit + 5 )
530540 await globalSync . project . loadSessions ( props . project . worktree )
531541 }
532542 const [ expanded , setExpanded ] = createSignal ( true )
0 commit comments