فهرست منبع

fix(desktop): session ordered by most recent

Adam 2 ماه پیش
والد
کامیت
b0aaf04957
2فایلهای تغییر یافته به همراه15 افزوده شده و 5 حذف شده
  1. 1 1
      packages/desktop/src/context/global-sync.tsx
  2. 14 4
      packages/desktop/src/pages/layout.tsx

+ 1 - 1
packages/desktop/src/context/global-sync.tsx

@@ -107,7 +107,7 @@ function createGlobalSync() {
           .slice()
           .filter((s) => !s.time.archived)
           .sort((a, b) => a.id.localeCompare(b.id))
-        // Include sessions up to the limit, plus any updated in the last hour
+        // Include up to the limit, plus any updated in the last 4 hours
         const sessions = nonArchived.filter((s, i) => {
           if (i < store.limit) return true
           const updated = new Date(s.time.updated).getTime()

+ 14 - 4
packages/desktop/src/pages/layout.tsx

@@ -122,10 +122,18 @@ export default function Layout(props: ParentProps) {
     }
   }
 
+  function projectSessions(directory: string) {
+    if (!directory) return []
+    const sessions = globalSync
+      .child(directory)[0]
+      .session.toSorted((a, b) => (b.time.updated ?? b.time.created) - (a.time.updated ?? a.time.created))
+    return flattenSessions(sessions ?? [])
+  }
+
   const currentSessions = createMemo(() => {
     if (!params.dir) return []
     const directory = base64Decode(params.dir)
-    return flattenSessions(globalSync.child(directory)[0].session ?? [])
+    return projectSessions(directory)
   })
 
   function navigateSessionByOffset(offset: number) {
@@ -162,7 +170,7 @@ export default function Layout(props: ParentProps) {
     const nextProject = projects[nextProjectIndex]
     if (!nextProject) return
 
-    const nextProjectSessions = flattenSessions(globalSync.child(nextProject.worktree)[0].session ?? [])
+    const nextProjectSessions = projectSessions(nextProject.worktree)
     if (nextProjectSessions.length === 0) {
       navigateToProject(nextProject.worktree)
       return
@@ -511,7 +519,9 @@ export default function Layout(props: ParentProps) {
     const slug = createMemo(() => base64Encode(props.project.worktree))
     const name = createMemo(() => getFilename(props.project.worktree))
     const [store, setProjectStore] = globalSync.child(props.project.worktree)
-    const sessions = createMemo(() => store.session ?? [])
+    const sessions = createMemo(() =>
+      store.session.toSorted((a, b) => (b.time.updated ?? b.time.created) - (a.time.updated ?? a.time.created)),
+    )
     const rootSessions = createMemo(() => sessions().filter((s) => !s.parentID))
     const childSessionsByParent = createMemo(() => {
       const map = new Map<string, Session[]>()
@@ -526,7 +536,7 @@ export default function Layout(props: ParentProps) {
     })
     const hasMoreSessions = createMemo(() => store.session.length >= store.limit)
     const loadMoreSessions = async () => {
-      setProjectStore("limit", (limit) => limit + 10)
+      setProjectStore("limit", (limit) => limit + 5)
       await globalSync.project.loadSessions(props.project.worktree)
     }
     const [expanded, setExpanded] = createSignal(true)