Remove the task Project tab; ⌘P selects the project
This commit is contained in:
@@ -8,48 +8,22 @@ private let refreshKinds: Set<String> = ["task.merged", "project.created"]
|
||||
|
||||
struct ProjectView: View {
|
||||
@Environment(Store.self) private var store
|
||||
@Environment(Overlays.self) private var overlays
|
||||
@ViewState private var todos: [String: Result<Todo, ApiError>] = [:]
|
||||
@ViewState private var off: (() -> Void)?
|
||||
@FocusState private var keys: Bool
|
||||
|
||||
var body: some View {
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView {
|
||||
if let p = store.focusedProject() {
|
||||
ProjectBlock(project: p, todo: todos[p.id])
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 16)
|
||||
} else {
|
||||
Muted(text: "No project selected.")
|
||||
}
|
||||
}
|
||||
.onChange(of: store.selectedTaskId) {
|
||||
if let id = store.selectedTaskId {
|
||||
proxy.scrollTo(id)
|
||||
}
|
||||
ScrollView {
|
||||
if let p = store.focusedProject() {
|
||||
ProjectBlock(project: p, todo: todos[p.id])
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 16)
|
||||
} else {
|
||||
Muted(text: "No project selected.")
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.focusable()
|
||||
.focusEffectDisabled()
|
||||
.focused($keys)
|
||||
.onKeyPress(keys: [.upArrow, .downArrow]) { press in
|
||||
step(press.key == .downArrow ? 1 : -1)
|
||||
return .handled
|
||||
}
|
||||
.onKeyPress(.return) {
|
||||
guard store.selectedTaskId != nil, store.focusedProject() != nil else {
|
||||
return .ignored
|
||||
}
|
||||
store.sheet = nil
|
||||
return .handled
|
||||
}
|
||||
.onAppear {
|
||||
if !(overlays.window?.firstResponder is NSTextView) {
|
||||
keys = true
|
||||
}
|
||||
off = store.events.add { ev in
|
||||
if refreshKinds.contains(ev.kind), let projectId = ev.projectId {
|
||||
load(projectId)
|
||||
@@ -57,9 +31,6 @@ struct ProjectView: View {
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
.onChange(of: overlays.projectFocus) {
|
||||
keys = true
|
||||
}
|
||||
.onDisappear {
|
||||
off?()
|
||||
off = nil
|
||||
@@ -79,25 +50,6 @@ struct ProjectView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func step(_ by: Int) {
|
||||
guard let p = store.focusedProject() else {
|
||||
return
|
||||
}
|
||||
let active = (store.tasks[p.id] ?? []).filter { $0.status == .active }
|
||||
let rows = nested(store, active).map(\.task.id)
|
||||
if rows.isEmpty {
|
||||
return
|
||||
}
|
||||
let next: Int
|
||||
if let i = rows.firstIndex(where: { $0 == store.selectedTaskId }) {
|
||||
next = min(max(i + by, 0), rows.count - 1)
|
||||
} else {
|
||||
next = by > 0 ? 0 : rows.count - 1
|
||||
}
|
||||
store.sheet = Sheet(owner: .task(rows[next]), view: .tab(.project))
|
||||
store.focusTask(rows[next])
|
||||
}
|
||||
|
||||
private func refresh() {
|
||||
if let p = store.focusedProject() {
|
||||
load(p.id)
|
||||
|
||||
Reference in New Issue
Block a user