refactor(macos): simplify sessions header

This commit is contained in:
Peter Steinberger
2025-12-20 21:17:24 +01:00
parent a2cf1f98d9
commit aa330350fc

View File

@@ -4,10 +4,7 @@ import SwiftUI
@MainActor @MainActor
struct SessionsSettings: View { struct SessionsSettings: View {
private let isPreview: Bool private let isPreview: Bool
private let state = AppStateStore.shared
@State private var rows: [SessionRow] @State private var rows: [SessionRow]
@State private var storePath: String = SessionLoader.defaultStorePath
@State private var lastLoaded: Date?
@State private var errorMessage: String? @State private var errorMessage: String?
@State private var loading = false @State private var loading = false
@State private var hasLoaded = false @State private var hasLoaded = false
@@ -16,7 +13,6 @@ struct SessionsSettings: View {
self._rows = State(initialValue: rows ?? []) self._rows = State(initialValue: rows ?? [])
self.isPreview = isPreview self.isPreview = isPreview
if isPreview { if isPreview {
self._lastLoaded = State(initialValue: Date())
self._hasLoaded = State(initialValue: true) self._hasLoaded = State(initialValue: true)
} }
} }
@@ -24,8 +20,6 @@ struct SessionsSettings: View {
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 14) { VStack(alignment: .leading, spacing: 14) {
self.header self.header
self.storeMetadata
Divider().padding(.vertical, 4)
self.content self.content
Spacer() Spacer()
} }
@@ -40,67 +34,26 @@ struct SessionsSettings: View {
} }
private var header: some View { private var header: some View {
VStack(alignment: .leading, spacing: 6) { HStack(alignment: .top, spacing: 12) {
Text("Sessions") VStack(alignment: .leading, spacing: 4) {
.font(.title3.weight(.semibold)) Text("Sessions")
Text("Peek at the stored conversation buckets the CLI reuses for context and rate limits.") .font(.headline)
.font(.callout) Text("Peek at the stored conversation buckets the CLI reuses for context and rate limits.")
.foregroundStyle(.secondary) .font(.footnote)
.fixedSize(horizontal: false, vertical: true) .foregroundStyle(.secondary)
} .fixedSize(horizontal: false, vertical: true)
}
private var storeMetadata: some View {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .top, spacing: 10) {
VStack(alignment: .leading, spacing: 4) {
Text("Session store")
.font(.callout.weight(.semibold))
if let lastLoaded {
Text("Updated \(relativeAge(from: lastLoaded))")
.font(.caption)
.foregroundStyle(.secondary)
}
}
Spacer()
if self.state.connectionMode == .local {
Text(self.storePath)
.font(.caption.monospaced())
.foregroundStyle(.secondary)
.multilineTextAlignment(.trailing)
}
} }
Spacer()
HStack(spacing: 10) { if self.loading {
ProgressView()
} else {
Button { Button {
Task { await self.refresh() } Task { await self.refresh() }
} label: { } label: {
Label(self.loading ? "Refreshing..." : "Refresh", systemImage: "arrow.clockwise") Label("Refresh", systemImage: "arrow.clockwise")
.labelStyle(.titleAndIcon)
} }
.disabled(self.loading)
.buttonStyle(.bordered) .buttonStyle(.bordered)
.help("Refresh session store") .help("Refresh")
if self.state.connectionMode == .local {
Button {
self.revealStore()
} label: {
Label("Reveal", systemImage: "folder")
.labelStyle(.titleAndIcon)
}
.disabled(!FileManager.default.fileExists(atPath: self.storePath))
}
if self.loading {
ProgressView().controlSize(.small)
}
}
if let errorMessage {
Text(errorMessage)
.font(.footnote)
.foregroundStyle(.red)
} }
} }
} }
@@ -117,6 +70,15 @@ struct SessionsSettings: View {
self.sessionRow(row) self.sessionRow(row)
} }
.listStyle(.inset) .listStyle(.inset)
.overlay(alignment: .topLeading) {
if let errorMessage {
Text(errorMessage)
.font(.footnote)
.foregroundStyle(.red)
.padding(.leading, 4)
.padding(.top, 4)
}
}
// The view already applies horizontal padding; keep the list aligned with the text above. // The view already applies horizontal padding; keep the list aligned with the text above.
.padding(.horizontal, -12) .padding(.horizontal, -12)
} }
@@ -204,8 +166,6 @@ struct SessionsSettings: View {
do { do {
let snapshot = try await SessionLoader.loadSnapshot() let snapshot = try await SessionLoader.loadSnapshot()
self.rows = snapshot.rows self.rows = snapshot.rows
self.storePath = snapshot.storePath
self.lastLoaded = Date()
} catch { } catch {
self.rows = [] self.rows = []
self.errorMessage = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription self.errorMessage = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription
@@ -214,14 +174,6 @@ struct SessionsSettings: View {
self.loading = false self.loading = false
} }
private func revealStore() {
let url = URL(fileURLWithPath: storePath)
if FileManager.default.fileExists(atPath: self.storePath) {
NSWorkspace.shared.activateFileViewerSelecting([url])
} else {
NSWorkspace.shared.open(url.deletingLastPathComponent())
}
}
} }
private struct SessionKindBadge: View { private struct SessionKindBadge: View {