Order the project picker by most recently selected
This commit is contained in:
@@ -511,6 +511,10 @@ final class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyFocus(_ f: Focus) {
|
func applyFocus(_ f: Focus) {
|
||||||
|
if f.projectId != focus.projectId {
|
||||||
|
markVisited(focus.projectId)
|
||||||
|
markVisited(f.projectId)
|
||||||
|
}
|
||||||
focus = f
|
focus = f
|
||||||
if f.taskId != selectedTaskId {
|
if f.taskId != selectedTaskId {
|
||||||
selectTask(f.taskId)
|
selectTask(f.taskId)
|
||||||
@@ -662,14 +666,14 @@ final class Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func markVisited(_ taskId: String?) {
|
private func markVisited(_ id: String?) {
|
||||||
guard let taskId else {
|
guard let id else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let at = Date().timeIntervalSince1970 * 1000
|
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 {
|
if records.isEmpty {
|
||||||
persistence.insert(VisitRecord(taskId: taskId, at: at))
|
persistence.insert(VisitRecord(taskId: id, at: at))
|
||||||
} else {
|
} else {
|
||||||
records[0].at = at
|
records[0].at = at
|
||||||
for record in records.dropFirst() {
|
for record in records.dropFirst() {
|
||||||
|
|||||||
@@ -234,19 +234,19 @@ final class SwitcherModel {
|
|||||||
}
|
}
|
||||||
return a.i < b.i
|
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
|
let images = store.images.images(imageKey).count
|
||||||
var rows: [SwitcherRow] = []
|
var rows: [SwitcherRow] = []
|
||||||
if images == 0 {
|
if images == 0 {
|
||||||
rows = matches.map { SwitcherRow(id: "task:\($0.task.id)", kind: .task($0.project, $0.task, $0.count)) }
|
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)))
|
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
|
let workflow = images == 0 ? workflowMatch(title) : nil
|
||||||
for project in targets ?? recent {
|
for project in targets ?? recent {
|
||||||
if title.isEmpty && images == 0 {
|
if title.isEmpty && images == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user