notes get their own left tab

This commit is contained in:
Ian Gulliver
2026-10-18 23:37:56 -07:00
parent d294159fcd
commit d567261fbd
6 changed files with 166 additions and 143 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ struct OverlayAlert: Identifiable {
}
enum LeftTab {
case lead, status, server, settings
case lead, notes, status, server, settings
}
@MainActor
+156
View File
@@ -0,0 +1,156 @@
import ByreAPI
import SwiftUI
typealias LeadNote = Components.Schemas.LeadNote
@MainActor
private var notesProject = ""
struct NotesView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
Text("Your lead notes your priorities and preferences as it works with you, and starts every session with them.")
.foregroundStyle(Palette.muted)
.fixedSize(horizontal: false, vertical: true)
.padding(.top, 16)
LeadNotes()
}
.padding(.horizontal, 16)
.padding(.top, 8)
.padding(.bottom, 16)
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Palette.bg)
}
}
private struct LeadNotes: View {
@Environment(Store.self) private var store
@Environment(Overlays.self) private var overlays
@ViewState private var list: [LeadNote]?
@ViewState private var failure: String?
@ViewState private var loads = 0
@ViewState private var project = notesProject
@ViewState private var off: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 0) {
if let list {
if list.isEmpty {
hint("Your lead hasn't noted anything about how you work yet.")
} else {
let groups = [("", "Every project")] + store.projects.map { ($0.id, $0.name) }
let current = groups.contains { $0.0 == project } ? project : ""
let shown = list.filter { ($0.projectId ?? "") == current }
let label = { (g: (String, String)) in "\(g.1) (\(list.filter { ($0.projectId ?? "") == g.0 }.count))" }
Menu {
ForEach(groups, id: \.0) { g in
Button(label(g)) {
project = g.0
notesProject = g.0
}
}
} label: {
HStack(spacing: 8) {
Text(label(groups.first { $0.0 == current } ?? groups[0]))
Image(systemName: "chevron.up.chevron.down")
.font(.system(size: 9, weight: .semibold))
}
.foregroundStyle(Palette.text)
.modifier(FieldStyle())
.contentShape(Rectangle())
}
.menuStyle(.button)
.buttonStyle(.plain)
.menuIndicator(.hidden)
.fixedSize()
.help("Which notes to show")
.padding(.bottom, 8)
if shown.isEmpty {
hint("No notes here yet.")
} else {
ForEach(shown, id: \.id) { note in
NoteRow(note: note)
}
}
}
} else if let failure {
hint(failure)
}
}
.padding(.top, 8)
.onAppear {
off = store.events.add { ev in
if ev.kind == "lead.note_saved" || ev.kind == "lead.note_deleted" {
load()
}
}
load()
}
.onDisappear {
off?()
off = nil
loads += 1
}
}
private func hint(_ text: String) -> some View {
Text(text).foregroundStyle(Palette.muted)
}
private func load() {
loads += 1
let n = loads
Task {
do {
let loaded = try await store.api.client.listLeadNotes().ok.body.json
if n == loads {
list = loaded
}
} catch {
failure = errorText(error)
list = nil
}
}
}
}
private struct NoteRow: View {
let note: LeadNote
@Environment(Store.self) private var store
@Environment(Overlays.self) private var overlays
@ViewState private var frame: CGRect = .zero
var body: some View {
HStack(alignment: .firstTextBaseline, spacing: 12) {
Text(note.text)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
Button("delete") {
Task {
if !(await overlays.showConfirm(["Delete this note? Your lead stops applying it.", note.text], action: "Delete", danger: true, anchor: frame)) {
return
}
do {
_ = try await store.api.client.deleteLeadNote(path: .init(noteId: note.id)).noContent
} catch {
overlays.showAlert(errorText(error))
}
}
}
.buttonStyle(SmallLinkButtonStyle())
.onGeometryChange(for: CGRect.self) { g in
g.frame(in: .named("window"))
} action: { f in
frame = f
}
}
.padding(.vertical, 6)
.overlay(alignment: .top) {
Rectangle().fill(Palette.border).frame(height: 1)
}
}
}
+6 -1
View File
@@ -136,6 +136,9 @@ private struct LeftPane: View {
PaneTabButton(label: "Lead", active: tab == .lead) {
overlays.leftTab = .lead
}
PaneTabButton(label: "Notes", active: tab == .notes) {
overlays.leftTab = .notes
}
PaneTabButton(label: "Status", active: tab == .status) {
overlays.leftTab = .status
}
@@ -171,7 +174,9 @@ private struct LeftPane: View {
.opacity(tab == .lead ? 1 : 0)
.allowsHitTesting(tab == .lead)
.accessibilityHidden(tab != .lead)
if tab == .status {
if tab == .notes {
NotesView()
} else if tab == .status {
StatusView()
} else if tab == .server {
ServerView()
-138
View File
@@ -2,7 +2,6 @@ import ByreAPI
import SwiftUI
import UserNotifications
typealias LeadNote = Components.Schemas.LeadNote
typealias NotificationPrefs = Components.Schemas.NotificationPrefs
@MainActor
@@ -13,9 +12,6 @@ private let kinds: [(key: WritableKeyPath<NotificationPrefs, Bool>, label: Strin
(\.rateLimits, "Rate limits"),
]
@MainActor
private var notesProject = ""
struct SettingsView: View {
@Environment(Store.self) private var store
@@ -54,11 +50,6 @@ struct SettingsView: View {
.foregroundStyle(Palette.muted)
.fixedSize(horizontal: false, vertical: true)
PermissionsCheck(run: checkLocalPermissions)
heading("What your lead has learned")
Text("Your lead notes your priorities and preferences as it works with you, and starts every session with them.")
.foregroundStyle(Palette.muted)
.fixedSize(horizontal: false, vertical: true)
LeadNotes()
}
.padding(.horizontal, 16)
.padding(.top, 8)
@@ -224,132 +215,3 @@ private struct ModelMenu: View {
.padding(.top, 8)
}
}
private struct LeadNotes: View {
@Environment(Store.self) private var store
@Environment(Overlays.self) private var overlays
@ViewState private var list: [LeadNote]?
@ViewState private var failure: String?
@ViewState private var loads = 0
@ViewState private var project = notesProject
@ViewState private var off: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 0) {
if let list {
if list.isEmpty {
hint("Your lead hasn't noted anything about how you work yet.")
} else {
let groups = [("", "Every project")] + store.projects.map { ($0.id, $0.name) }
let current = groups.contains { $0.0 == project } ? project : ""
let shown = list.filter { ($0.projectId ?? "") == current }
let label = { (g: (String, String)) in "\(g.1) (\(list.filter { ($0.projectId ?? "") == g.0 }.count))" }
Menu {
ForEach(groups, id: \.0) { g in
Button(label(g)) {
project = g.0
notesProject = g.0
}
}
} label: {
HStack(spacing: 8) {
Text(label(groups.first { $0.0 == current } ?? groups[0]))
Image(systemName: "chevron.up.chevron.down")
.font(.system(size: 9, weight: .semibold))
}
.foregroundStyle(Palette.text)
.modifier(FieldStyle())
.contentShape(Rectangle())
}
.menuStyle(.button)
.buttonStyle(.plain)
.menuIndicator(.hidden)
.fixedSize()
.help("Which notes to show")
.padding(.bottom, 8)
if shown.isEmpty {
hint("No notes here yet.")
} else {
ForEach(shown, id: \.id) { note in
NoteRow(note: note)
}
}
}
} else if let failure {
hint(failure)
}
}
.padding(.top, 8)
.onAppear {
off = store.events.add { ev in
if ev.kind == "lead.note_saved" || ev.kind == "lead.note_deleted" {
load()
}
}
load()
}
.onDisappear {
off?()
off = nil
loads += 1
}
}
private func hint(_ text: String) -> some View {
Text(text).foregroundStyle(Palette.muted)
}
private func load() {
loads += 1
let n = loads
Task {
do {
let loaded = try await store.api.client.listLeadNotes().ok.body.json
if n == loads {
list = loaded
}
} catch {
failure = errorText(error)
list = nil
}
}
}
}
private struct NoteRow: View {
let note: LeadNote
@Environment(Store.self) private var store
@Environment(Overlays.self) private var overlays
@ViewState private var frame: CGRect = .zero
var body: some View {
HStack(alignment: .firstTextBaseline, spacing: 12) {
Text(note.text)
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
Button("delete") {
Task {
if !(await overlays.showConfirm(["Delete this note? Your lead stops applying it.", note.text], action: "Delete", danger: true, anchor: frame)) {
return
}
do {
_ = try await store.api.client.deleteLeadNote(path: .init(noteId: note.id)).noContent
} catch {
overlays.showAlert(errorText(error))
}
}
}
.buttonStyle(SmallLinkButtonStyle())
.onGeometryChange(for: CGRect.self) { g in
g.frame(in: .named("window"))
} action: { f in
frame = f
}
}
.padding(.vertical, 6)
.overlay(alignment: .top) {
Rectangle().fill(Palette.border).frame(height: 1)
}
}
}