Просмотр исходного кода

fix(tui): sort session picker by full updated timestamp (#24725)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Jose Vargas 4 месяцев назад
Родитель
Сommit
f0cb17a812
1 измененных файлов с 17 добавлено и 7 удалено
  1. 17 7
      packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx

+ 17 - 7
packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx

@@ -119,15 +119,25 @@ export function DialogSessionList() {
     ))
   }
 
+  function orderByRecency(sessionsList: NonNullable<ReturnType<typeof sessions>>) {
+    return sessionsList
+      .filter((x) => x.parentID === undefined)
+      .toSorted((a, b) => b.time.updated - a.time.updated)
+      .map((x) => x.id)
+  }
+
+  const [browseOrder] = createSignal<string[]>(orderByRecency(sync.data.session))
+
   const options = createMemo(() => {
     const today = new Date().toDateString()
-    return sessions()
-      .filter((x) => x.parentID === undefined)
-      .toSorted((a, b) => {
-        const updatedDay = new Date(b.time.updated).setHours(0, 0, 0, 0) - new Date(a.time.updated).setHours(0, 0, 0, 0)
-        if (updatedDay !== 0) return updatedDay
-        return b.time.created - a.time.created
-      })
+    const sessionMap = new Map(sessions().filter((x) => x.parentID === undefined).map((x) => [x.id, x]))
+
+    const searchResult = searchResults()
+    const displayOrder = searchResult ? orderByRecency(searchResult) : browseOrder()
+
+    return displayOrder
+      .map((id) => sessionMap.get(id))
+      .filter((x) => x !== undefined)
       .map((x) => {
         const workspace = x.workspaceID ? project.workspace.get(x.workspaceID) : undefined