Order the project picker by most recently selected

This commit is contained in:
Ian Gulliver
2026-10-22 13:16:19 -07:00
parent e61e491d47
commit d5ffd5b128
2 changed files with 14 additions and 10 deletions
+8 -4
View File
@@ -511,6 +511,10 @@ final class Store {
}
func applyFocus(_ f: Focus) {
if f.projectId != focus.projectId {
markVisited(focus.projectId)
markVisited(f.projectId)
}
focus = f
if f.taskId != selectedTaskId {
selectTask(f.taskId)
@@ -662,14 +666,14 @@ final class Store {
}
}
private func markVisited(_ taskId: String?) {
guard let taskId else {
private func markVisited(_ id: String?) {
guard let id else {
return
}
let at = Date().timeIntervalSince1970 * 1000
let records = fetchRecords(FetchDescriptor<VisitRecord>(predicate: #Predicate { $0.taskId == taskId }))
let records = fetchRecords(FetchDescriptor<VisitRecord>(predicate: #Predicate { $0.taskId == id }))
if records.isEmpty {
persistence.insert(VisitRecord(taskId: taskId, at: at))
persistence.insert(VisitRecord(taskId: id, at: at))
} else {
records[0].at = at
for record in records.dropFirst() {
+6 -6
View File
@@ -234,19 +234,19 @@ final class SwitcherModel {
}
return a.i < b.i
}
let focused = store.focusedProject()?.id
let used = store.projects.enumerated().map { i, p in
(i: i, project: p, at: p.id == focused ? Double.infinity : ((store.tasks[p.id] ?? []).map { visits[$0.id] ?? 0 } + [visits[p.id] ?? 0]).max()!)
}
let recent = used.sorted { $0.at != $1.at ? $0.at > $1.at : $0.i < $1.i }.map(\.project)
let images = store.images.images(imageKey).count
var rows: [SwitcherRow] = []
if images == 0 {
rows = matches.map { SwitcherRow(id: "task:\($0.task.id)", kind: .task($0.project, $0.task, $0.count)) }
for p in (targets ?? store.projects) where includes("\(p.name) project".lowercased(), q) {
for p in (targets ?? recent) where includes("\(p.name) project".lowercased(), q) {
rows.append(SwitcherRow(id: "project:\(p.id)", kind: .project(p)))
}
}
let focused = store.focusedProject()?.id
let used = store.projects.enumerated().map { i, p in
(i: i, project: p, at: p.id == focused ? Double.infinity : (store.tasks[p.id] ?? []).map { visits[$0.id] ?? 0 }.max() ?? 0)
}
let recent = used.sorted { $0.at != $1.at ? $0.at > $1.at : $0.i < $1.i }.map(\.project)
let workflow = images == 0 ? workflowMatch(title) : nil
for project in targets ?? recent {
if title.isEmpty && images == 0 {