Skip to content

Commit 5ad2e1c

Browse files
fix(tui): sort session picker by full updated timestamp (anomalyco#24725)
Co-authored-by: Aiden Cline <[email protected]>
1 parent 7cf48c3 commit 5ad2e1c

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,25 @@ export function DialogSessionList() {
119119
))
120120
}
121121

122+
function orderByRecency(sessionsList: NonNullable<ReturnType<typeof sessions>>) {
123+
return sessionsList
124+
.filter((x) => x.parentID === undefined)
125+
.toSorted((a, b) => b.time.updated - a.time.updated)
126+
.map((x) => x.id)
127+
}
128+
129+
const [browseOrder] = createSignal<string[]>(orderByRecency(sync.data.session))
130+
122131
const options = createMemo(() => {
123132
const today = new Date().toDateString()
124-
return sessions()
125-
.filter((x) => x.parentID === undefined)
126-
.toSorted((a, b) => {
127-
const updatedDay = new Date(b.time.updated).setHours(0, 0, 0, 0) - new Date(a.time.updated).setHours(0, 0, 0, 0)
128-
if (updatedDay !== 0) return updatedDay
129-
return b.time.created - a.time.created
130-
})
133+
const sessionMap = new Map(sessions().filter((x) => x.parentID === undefined).map((x) => [x.id, x]))
134+
135+
const searchResult = searchResults()
136+
const displayOrder = searchResult ? orderByRecency(searchResult) : browseOrder()
137+
138+
return displayOrder
139+
.map((id) => sessionMap.get(id))
140+
.filter((x) => x !== undefined)
131141
.map((x) => {
132142
const workspace = x.workspaceID ? project.workspace.get(x.workspaceID) : undefined
133143

0 commit comments

Comments
 (0)