feat(ios): redesign native sidebar

This commit is contained in:
Theo Browne committed 2026-08-09 20:52:49 -07:00
1 parent 27a28907d0
commit d42b8001ec
5 files changed
+913 -357

No files matched your search

+4 -1
View File
@@ -7,12 +7,15 @@ enum T3Colors {
static let input = Color(white: 0.075)
static let border = Color.white.opacity(0.09)
static let separator = Color.white.opacity(0.07)
static let ledgerSurface = Color(white: 0.055)
static let ledgerSelected = Color(white: 0.051)
static let textPrimary = Color.white
static let textSecondary = Color.white.opacity(0.62)
static let textTertiary = Color.white.opacity(0.4)
static let textTertiary = Color.white.opacity(0.5)
static let accent = Color(red: 0.04, green: 0.52, blue: 1)
static let statusRunning = Color(red: 0.13, green: 0.83, blue: 0.93)
static let success = Color(red: 0.19, green: 0.82, blue: 0.35)
static let warning = Color(red: 1, green: 0.62, blue: 0.04)
static let danger = Color(red: 1, green: 0.27, blue: 0.23)
@@ -80,13 +80,22 @@ struct DailyUXSidebarIndex {
let settled: [FeatureThread]
let searchResults: [FeatureThread]
var needsInput: [FeatureThread] {
active.filter {
$0.state == .waitingForApproval || $0.state == .waitingForInput
}
}
var failed: [FeatureThread] {
active.filter { $0.state == .failed }
}
init(
snapshot: FeatureSnapshot,
query: String,
projectID: String? = nil,
now: Date = .now
) {
let projectByID = Dictionary(uniqueKeysWithValues: snapshot.projects.map { ($0.id, $0) })
let visible = snapshot.threads.filter { thread in
guard !thread.isArchived else { return false }
return projectID == nil || thread.projectID == projectID
@@ -122,13 +131,22 @@ struct DailyUXSidebarIndex {
return lhs.id < rhs.id
}
let normalizedQuery = query.trimmingCharacters(in: .whitespacesAndNewlines)
guard !normalizedQuery.isEmpty else {
searchResults = []
return
}
searchResults = Self.matchingThreads(
active + snoozed + settled,
snapshot: snapshot,
query: query
)
}
searchResults = (active + snoozed + settled).filter { thread in
static func matchingThreads(
_ candidates: [FeatureThread],
snapshot: FeatureSnapshot,
query: String
) -> [FeatureThread] {
let normalizedQuery = query.trimmingCharacters(in: .whitespacesAndNewlines)
guard !normalizedQuery.isEmpty else { return [] }
let projectByID = Dictionary(uniqueKeysWithValues: snapshot.projects.map { ($0.id, $0) })
return candidates.filter { thread in
let project = projectByID[thread.projectID]
return [
thread.title,
@@ -140,6 +158,48 @@ struct DailyUXSidebarIndex {
}
}
enum SidebarRelativeAge {
static func compact(since date: Date, now: Date) -> String {
let seconds = max(0, Int(now.timeIntervalSince(date)))
switch seconds {
case ..<60:
return "now"
case ..<3_600:
return "\(seconds / 60)m"
case ..<86_400:
return "\(seconds / 3_600)h"
case ..<604_800:
return "\(seconds / 86_400)d"
case ..<31_536_000:
return "\(seconds / 604_800)w"
default:
return "\(seconds / 31_536_000)y"
}
}
static func accessibility(since date: Date, now: Date) -> String {
let seconds = max(0, Int(now.timeIntervalSince(date)))
switch seconds {
case ..<60:
return "Updated just now"
case ..<3_600:
return "Updated \(unit(seconds / 60, singular: "minute")) ago"
case ..<86_400:
return "Updated \(unit(seconds / 3_600, singular: "hour")) ago"
case ..<604_800:
return "Updated \(unit(seconds / 86_400, singular: "day")) ago"
case ..<31_536_000:
return "Updated \(unit(seconds / 604_800, singular: "week")) ago"
default:
return "Updated \(unit(seconds / 31_536_000, singular: "year")) ago"
}
}
private static func unit(_ value: Int, singular: String) -> String {
"\(value) \(singular)\(value == 1 ? "" : "s")"
}
}
extension FeatureThread {
var needsAttention: Bool {
state == .waitingForApproval || state == .waitingForInput || state == .failed
@@ -53,83 +53,3 @@ public struct AddProjectView: View {
}
}
}
public struct ArchivedThreadsView: View {
@SwiftUI.Environment(\.dismiss) private var dismiss
@Bindable var model: FeatureRootModel
let onSelect: (FeatureThread) -> Void
public init(model: FeatureRootModel, onSelect: @escaping (FeatureThread) -> Void) {
self.model = model
self.onSelect = onSelect
}
public var body: some View {
NavigationStack {
List {
if archived.isEmpty {
ContentUnavailableView(
"No archived threads",
systemImage: "archivebox",
description: Text("Archived work will appear here.")
)
.listRowBackground(Color.clear)
}
ForEach(archived) { thread in
HStack(spacing: 12) {
Button {
onSelect(thread)
} label: {
FeatureThreadRow(
thread: thread,
projectName: projectName(for: thread.projectID)
)
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
Button {
Task { await model.setArchived(thread.id, archived: false) }
} label: {
Image(systemName: "arrow.uturn.backward")
}
.buttonStyle(.borderless)
.accessibilityLabel("Restore \(thread.title)")
}
.swipeActions {
Button(role: .destructive) {
Task { await model.deleteThread(thread.id) }
} label: {
Label("Delete", systemImage: "trash")
}
Button {
Task { await model.setArchived(thread.id, archived: false) }
} label: {
Label("Restore", systemImage: "arrow.uturn.backward")
}
.tint(.blue)
}
}
}
.scrollContentBackground(.hidden)
.background(Color.black)
.navigationTitle("Archived")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Done") { dismiss() }
}
}
}
}
private var archived: [FeatureThread] {
model.snapshot.threads
.filter(\.isArchived)
.sorted { $0.updatedAt > $1.updatedAt }
}
private func projectName(for id: String) -> String {
model.snapshot.projects.first(where: { $0.id == id })?.name ?? "Unknown project"
}
}
File diff suppressed because it is too large. Load diff
@@ -167,6 +167,87 @@ struct DailyUXSidebarTests {
#expect(searched.searchResults.map(\.id) == ["server"])
}
@Test
func attentionScopesRemainFocusedSubsetsOfActive() {
let approval = thread(
id: "approval",
title: "Approve schema",
created: -10,
updated: -5,
state: .waitingForApproval
)
let input = thread(
id: "input",
title: "Answer migration question",
created: -20,
updated: -5,
state: .waitingForInput
)
let failed = thread(
id: "failed",
title: "Failed build",
created: -30,
updated: -5,
state: .failed
)
let working = thread(
id: "working",
title: "Build application",
created: -40,
updated: -5,
state: .working
)
let snapshot = FeatureSnapshot(threads: [approval, input, failed, working])
let index = DailyUXSidebarIndex(snapshot: snapshot, query: "", now: now)
#expect(index.active.map(\.id) == ["approval", "input", "failed", "working"])
#expect(index.needsInput.map(\.id) == ["approval", "input"])
#expect(index.failed.map(\.id) == ["failed"])
#expect(
DailyUXSidebarIndex.matchingThreads(
index.failed,
snapshot: snapshot,
query: "build"
).map(\.id) == ["failed"]
)
#expect(
DailyUXSidebarIndex.matchingThreads(
index.needsInput,
snapshot: snapshot,
query: "build"
).isEmpty
)
}
@Test
func compactRelativeAgeClampsFutureDatesAndUsesStableUnits() {
#expect(
SidebarRelativeAge.compact(
since: now.addingTimeInterval(5),
now: now
) == "now"
)
#expect(
SidebarRelativeAge.compact(
since: now.addingTimeInterval(-125),
now: now
) == "2m"
)
#expect(
SidebarRelativeAge.compact(
since: now.addingTimeInterval(-7_300),
now: now
) == "2h"
)
#expect(
SidebarRelativeAge.accessibility(
since: now.addingTimeInterval(-3_600),
now: now
) == "Updated 1 hour ago"
)
}
private func makeIndex(_ threads: [FeatureThread]) -> DailyUXSidebarIndex {
DailyUXSidebarIndex(
snapshot: FeatureSnapshot(threads: threads),