rheaarchived
- 40 commits
- 1 branch
- 0 tags
- updated
feat: add design-system module and migrate views onto shared tokens/components
SignedGitea couldn't verify the signature.
Showing 10 changed files with 257 additions and 164 deletions.
Rhea/DesignSystem/Card.swiftadded
+52 −0
@@ -0,0 +1,52 @@1import SwiftUI23/// Visual weight of a `Card`'s header and chrome.4enum CardVariant {5 /// Small caption-weight header, tinted fill, no divider — dense in-form cards6 /// (`ReceiptEditForm`).7 case compact8 /// Headline header with a divider, plain background, and a subtle shadow — settings9 /// sections (`SettingsView`).10 case section11}1213/// Shared card chrome: icon + title header (with optional trailing text), optional divider,14/// and rounded-rect background/border. Replaces the separate card builders that used to be15/// duplicated between `ReceiptEditForm` and `SettingsView`.16struct Card<Content: View>: View {17 let title: String18 let systemImage: String19 var variant: CardVariant = .compact20 var trailing: String? = nil21 @ViewBuilder var content: () -> Content2223 var body: some View {24 VStack(alignment: .leading, spacing: variant == .compact ? 10 : 14) {25 header26 if variant == .section {27 Divider()28 }29 content()30 }31 .padding(variant == .compact ? 14 : 18)32 .frame(maxWidth: .infinity, alignment: .leading)33 .background(variant == .compact ? AnyShapeStyle(Color.cardFill) : AnyShapeStyle(.background))34 .clipShape(RoundedRectangle(cornerRadius: 12))35 .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color.cardBorder, lineWidth: 0.5))36 .shadow(color: variant == .section ? .black.opacity(0.04) : .clear,37 radius: variant == .section ? 4 : 0, x: 0, y: 1)38 }3940 private var header: some View {41 HStack {42 Label(title, systemImage: systemImage)43 .font(variant == .compact ? .caption.weight(.semibold) : .headline)44 .foregroundStyle(variant == .compact ? Color.secondary : Color.primary)45 .textCase(nil)46 Spacer()47 if let trailing {48 Text(trailing).font(.caption).foregroundStyle(.tertiary)49 }50 }51 }52}
Rhea/DesignSystem/CategoryDot.swiftadded
+12 −0
@@ -0,0 +1,12 @@1import SwiftUI23/// Small filled dot carrying a line item's category color (see `Color.category(for:)`).4struct CategoryDot: View {5 let category: String67 var body: some View {8 Circle()9 .fill(Color.category(for: category).opacity(0.85))10 .frame(width: 6, height: 6)11 }12}
Rhea/DesignSystem/ColorTokens.swiftadded
+69 −0
@@ -0,0 +1,69 @@1import SwiftUI23/// Semantic color tokens. Every color used more than once for the same *meaning* (confidence4/// tier, processing status, category, card chrome) routes through here instead of a bare5/// system color, so the mapping is defined once and both appearances (light/dark) stay in sync6/// automatically via the underlying dynamic system colors.7extension Color {89 // MARK: - Confidence tiers1011 static let confidenceHigh: Color = .green12 static let confidenceMedium: Color = .orange13 static let confidenceLow: Color = .red1415 static func confidence(for value: Double) -> Color {16 if value >= 0.85 { return .confidenceHigh }17 if value >= 0.60 { return .confidenceMedium }18 return .confidenceLow19 }2021 // MARK: - Receipt status2223 static func status(for status: ReceiptStatus, confirmed: Bool) -> Color {24 switch status {25 case .done: return confirmed ? .statusConfirmed : .statusProcessed26 case .failed: return .statusFailed27 case .inProgress: return .statusProcessing28 case .queued: return .statusQueued29 }30 }3132 static let statusQueued: Color = .secondary33 static let statusProcessing: Color = .orange34 static let statusProcessed: Color = .blue35 static let statusConfirmed: Color = .green36 static let statusFailed: Color = .red3738 // MARK: - Line-item category3940 static func category(for raw: String) -> Color {41 let s = raw.uppercased()42 if s.contains("PRODUCE") { return .green }43 if s.contains("MEAT") || s.contains("SEAFOOD") { return .pink }44 if s.contains("LIQUOR") || s.contains("BEER") || s.contains("WINE") { return .purple }45 if s.contains("DELI") { return .orange }46 if s.contains("BAK") { return .brown }47 if s.contains("FROZEN") || s.contains("REFRIG") { return .teal }48 if s.contains("DAIRY") { return .indigo }49 if s.contains("GROC") { return .mint }50 return .gray51 }5253 // MARK: - Accents5455 /// The blue accent used for the model's read-only suggestions (AI common-name badge).56 static let aiAccent: Color = .blue57 static let csvAccent: Color = .blue58 static let postgresAccent: Color = .indigo5960 /// Success/error banners and destructive affordances (export status, error panes, delete).61 static let successAccent: Color = .green62 static let errorAccent: Color = .red63 static let destructiveAccent: Color = .red6465 // MARK: - Card chrome6667 static let cardFill: Color = Color.primary.opacity(0.045)68 static let cardBorder: Color = Color.primary.opacity(0.08)69}
Rhea/DesignSystem/ConfidencePill.swiftadded
+19 −0
@@ -0,0 +1,19 @@1import SwiftUI23/// Small colored capsule showing a model-confidence percentage. Color comes from the shared4/// `Color.confidence(for:)` token so the red/orange/green thresholds are defined in one place.5struct ConfidencePill: View {6 let confidence: Double78 var body: some View {9 let pct = Int((confidence * 100).rounded())10 let color = Color.confidence(for: confidence)11 Text("\(pct)%")12 .font(.system(size: 9, weight: .semibold).monospacedDigit())13 .foregroundStyle(color)14 .padding(.horizontal, 5)15 .padding(.vertical, 2)16 .background(color.opacity(0.12))17 .clipShape(Capsule())18 }19}
Rhea/DesignSystem/Formatters.swiftadded
+20 −0
@@ -0,0 +1,20 @@1import Foundation23/// Shared currency/date formatting, so display formatting is defined once instead of as local4/// helpers per view.5enum AppFormatters {6 static func currency(_ value: Decimal) -> String {7 let fmt = NumberFormatter()8 fmt.numberStyle = .currency9 fmt.locale = .current10 return fmt.string(from: value as NSDecimalNumber) ?? "\(value)"11 }1213 /// Formats an ISO-8601 date string (as stored on `ExtractedReceipt.date`) for display;14 /// falls back to the raw string if it doesn't parse.15 static func shortDate(fromISO iso: String) -> String {16 let parser = ISO8601DateFormatter()17 guard let date = parser.date(from: iso) else { return iso }18 return date.formatted(date: .abbreviated, time: .omitted)19 }20}
Rhea/DesignSystem/Spacing.swiftadded
+12 −0
@@ -0,0 +1,12 @@1import SwiftUI23/// Shared spacing scale. Use these instead of ad hoc padding/spacing literals wherever the4/// value is generic whitespace rather than layout-specific math (e.g. fixed column widths).5enum Spacing {6 static let xs: CGFloat = 47 static let sm: CGFloat = 88 static let md: CGFloat = 129 static let lg: CGFloat = 1610 static let xl: CGFloat = 2011 static let xxl: CGFloat = 2412}
Rhea/DesignSystem/StatusBadge.swiftadded
+35 −0
@@ -0,0 +1,35 @@1import SwiftUI23/// Capsule pill: a status dot (or spinner) + label, with optional trailing detail text.4/// Shared chrome for `ReceiptListView`'s status column.5struct StatusBadge: View {6 let label: String7 let color: Color8 var showSpinner: Bool = false9 var trailing: String? = nil1011 var body: some View {12 HStack(spacing: 5) {13 if showSpinner {14 ProgressView().controlSize(.small)15 } else {16 Circle()17 .fill(color)18 .frame(width: 6, height: 6)19 .shadow(color: color.opacity(0.6), radius: 2.5, x: 0, y: 0)20 }21 Text(label)22 .font(.system(size: 11, weight: .medium))23 .foregroundStyle(color)24 if let trailing {25 Text(trailing)26 .font(.system(size: 10, weight: .semibold).monospacedDigit())27 .foregroundStyle(.secondary)28 }29 }30 .padding(.horizontal, 8)31 .padding(.vertical, 4)32 .background(color.opacity(0.1))33 .clipShape(Capsule())34 }35}
Rhea/Views/ReceiptEditForm.swift
+17 −78
@@ -143,35 +143,10 @@ struct ReceiptEditForm: View {143143 .frame(maxWidth: .infinity, maxHeight: .infinity)144144 }145145146 // MARK: - Card chrome147148 @ViewBuilder149 private func card<Content: View>(_ title: String, systemImage: String,150 trailing: String? = nil,151 @ViewBuilder content: () -> Content) -> some View {152 VStack(alignment: .leading, spacing: 10) {153 HStack {154 Label(title, systemImage: systemImage)155 .font(.caption.weight(.semibold))156 .foregroundStyle(.secondary)157 .textCase(nil)158 Spacer()159 if let trailing {160 Text(trailing).font(.caption).foregroundStyle(.tertiary)161 }162 }163 content()164 }165 .padding(14)166 .frame(maxWidth: .infinity, alignment: .leading)167 .background(RoundedRectangle(cornerRadius: 12).fill(Color.primary.opacity(0.045)))168 .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color.primary.opacity(0.08), lineWidth: 0.5))169 }170171146 // MARK: - Receipt details172147173148 private var detailsCard: some View {174 card("Receipt Details", systemImage: "doc.text") {149 Card(title: "Receipt Details", systemImage: "doc.text") {175150 VStack(spacing: 7) {176151 idRow("Receipt ID", value: receipt.publicID)177152 idRow("Key", value: receipt.naturalKey)@@ -234,7 +209,7 @@ struct ReceiptEditForm: View {234209 .foregroundStyle(.secondary)235210 .frame(width: 116, alignment: .leading)236211 Spacer()237 confidencePill(confidence)212 ConfidencePill(confidence: confidence)238213 }239214 }240215@@ -272,7 +247,7 @@ struct ReceiptEditForm: View {272247 // MARK: - Line items273248274249 private var lineItemsCard: some View {275 card("Line Items", systemImage: "list.bullet",250 Card(title: "Line Items", systemImage: "list.bullet",276251 trailing: lineItems.isEmpty ? nil : "\(lineItems.count) item\(lineItems.count == 1 ? "" : "s")") {277252 if lineItems.isEmpty && isReadOnly {278253 Text("No line items")@@ -314,7 +289,7 @@ struct ReceiptEditForm: View {314289 .foregroundStyle(.primary)315290 .disabled(isReadOnly)316291 if let conf = item.wrappedValue.confidence {317 confidencePill(conf)292 ConfidencePill(confidence: conf)318293 }319294 }320295@@ -354,7 +329,7 @@ struct ReceiptEditForm: View {354329 lineItems.removeAll { $0.id == id }355330 } label: {356331 Image(systemName: "minus.circle.fill")357 .foregroundStyle(.red.opacity(0.8))332 .foregroundStyle(Color.destructiveAccent.opacity(0.8))358333 .font(.system(size: 14))359334 }360335 .buttonStyle(.plain)@@ -373,22 +348,22 @@ struct ReceiptEditForm: View {373348 HStack(spacing: 5) {374349 Text("AI")375350 .font(.system(size: 8, weight: .bold))376 .foregroundStyle(.blue)351 .foregroundStyle(Color.aiAccent)377352 .padding(.horizontal, 3)378353 .padding(.vertical, 1)379354 .overlay(380355 RoundedRectangle(cornerRadius: 3)381 .strokeBorder(.blue.opacity(0.55), lineWidth: 0.75)356 .strokeBorder(Color.aiAccent.opacity(0.55), lineWidth: 0.75)382357 )383358 Text(ai)384359 .font(.caption)385 .foregroundStyle(.blue)360 .foregroundStyle(Color.aiAccent)386361 .lineLimit(1)387362 if !isReadOnly && item.wrappedValue.userCommonName.isEmpty {388363 Button { item.wrappedValue.userCommonName = ai } label: {389364 Image(systemName: "arrow.up.left")390365 .font(.system(size: 9, weight: .bold))391 .foregroundStyle(.blue)366 .foregroundStyle(Color.aiAccent)392367 }393368 .buttonStyle(.plain)394369 .help("Use this suggestion as your common name")@@ -399,9 +374,8 @@ struct ReceiptEditForm: View {399374400375 /// Category — tertiary: small muted text with a low-key color dot (no heavy fill).401376 private func categoryTag(item: Binding<EditableLineItem>) -> some View {402 let color = categoryColor(item.wrappedValue.category)403 return HStack(spacing: 5) {404 Circle().fill(color.opacity(0.85)).frame(width: 6, height: 6)377 HStack(spacing: 5) {378 CategoryDot(category: item.wrappedValue.category)405379 TextField("category", text: item.category)406380 .textFieldStyle(.plain)407381 .font(.caption2.weight(.medium))@@ -476,41 +450,6 @@ struct ReceiptEditForm: View {476450 .disabled(isReadOnly)477451 }478452479 // MARK: - Confidence badge480481 /// Small colored capsule showing a confidence percentage.482 private func confidencePill(_ confidence: Double) -> some View {483 let pct = Int((confidence * 100).rounded())484 let color = confidenceColor(confidence)485 return Text("\(pct)%")486 .font(.system(size: 9, weight: .semibold).monospacedDigit())487 .foregroundStyle(color)488 .padding(.horizontal, 5)489 .padding(.vertical, 2)490 .background(color.opacity(0.12))491 .clipShape(Capsule())492 }493494 private func confidenceColor(_ c: Double) -> Color {495 if c >= 0.85 { return .green }496 if c >= 0.60 { return .orange }497 return .red498 }499500 /// Muted, low-saturation category palette — carried by a small dot, not a fill.501 private func categoryColor(_ raw: String) -> Color {502 let s = raw.uppercased()503 if s.contains("PRODUCE") { return .green }504 if s.contains("MEAT") || s.contains("SEAFOOD") { return .pink }505 if s.contains("LIQUOR") || s.contains("BEER") || s.contains("WINE") { return .purple }506 if s.contains("DELI") { return .orange }507 if s.contains("BAK") { return .brown }508 if s.contains("FROZEN") || s.contains("REFRIG") { return .teal }509 if s.contains("DAIRY") { return .indigo }510 if s.contains("GROC") { return .mint }511 return .gray512 }513514453 // MARK: - Confirm footer515454516455 @ViewBuilder@@ -519,11 +458,11 @@ struct ReceiptEditForm: View {519458 HStack(spacing: 8) {520459 Image(systemName: "checkmark.circle.fill")521460 .font(.title3)522 .foregroundStyle(.green)461 .foregroundStyle(Color.statusConfirmed)523462 VStack(alignment: .leading, spacing: 1) {524463 Text("Confirmed & Saved")525464 .font(.body.weight(.semibold))526 .foregroundStyle(.green)465 .foregroundStyle(Color.statusConfirmed)527466 Text("Reviewed. Export from Settings to write to CSV or Postgres.")528467 .font(.caption)529468 .foregroundStyle(.secondary)@@ -532,7 +471,7 @@ struct ReceiptEditForm: View {532471 }533472 .padding(14)534473 .frame(maxWidth: .infinity, alignment: .leading)535 .background(RoundedRectangle(cornerRadius: 12).fill(Color.green.opacity(0.08)))474 .background(RoundedRectangle(cornerRadius: 12).fill(Color.statusConfirmed.opacity(0.08)))536475 } else {537476 VStack(spacing: 12) {538477 HStack {@@ -546,7 +485,7 @@ struct ReceiptEditForm: View {546485 Spacer()547486 Button("Confirm") { applyAndConfirm() }548487 .buttonStyle(.borderedProminent)549 .tint(.green)488 .tint(Color.statusConfirmed)550489 .keyboardShortcut(.return, modifiers: .command)551490 .accessibilityIdentifier("confirm-button")552491 }@@ -562,8 +501,8 @@ struct ReceiptEditForm: View {562501 }563502 .padding(14)564503 .frame(maxWidth: .infinity, alignment: .leading)565 .background(RoundedRectangle(cornerRadius: 12).fill(Color.primary.opacity(0.045)))566 .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color.primary.opacity(0.08), lineWidth: 0.5))504 .background(RoundedRectangle(cornerRadius: 12).fill(Color.cardFill))505 .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color.cardBorder, lineWidth: 0.5))567506 }568507 }569508
Rhea/Views/ReceiptListView.swift
+9 −49
@@ -46,7 +46,7 @@ struct ReceiptListView: View {46464747 TableColumn("Total") { receipt in4848 if let total = receipt.extracted?.total {49 Text(formatCurrency(total))49 Text(AppFormatters.currency(total))5050 .font(.subheadline.weight(.semibold))5151 .monospacedDigit()5252 .frame(maxWidth: .infinity, alignment: .trailing)@@ -252,16 +252,7 @@ struct ReceiptListView: View {252252253253 private func dateText(for receipt: Receipt) -> String {254254 guard let iso = receipt.extracted?.date else { return "—" }255 let fmt = ISO8601DateFormatter()256 guard let date = fmt.date(from: iso) else { return iso }257 return date.formatted(date: .abbreviated, time: .omitted)258 }259260 private func formatCurrency(_ value: Decimal) -> String {261 let fmt = NumberFormatter()262 fmt.numberStyle = .currency263 fmt.locale = .current264 return fmt.string(from: value as NSDecimalNumber) ?? "\(value)"255 return AppFormatters.shortDate(fromISO: iso)265256 }266257}267258@@ -326,28 +317,12 @@ struct StatusCell: View {326317 var position: (index: Int, total: Int)? = nil327318328319 var body: some View {329 HStack(spacing: 5) {330 if status == .inProgress {331 ProgressView().controlSize(.small)332 } else {333 Circle()334 .fill(color)335 .frame(width: 6, height: 6)336 .shadow(color: color.opacity(0.6), radius: 2.5, x: 0, y: 0)337 }338 Text(label)339 .font(.system(size: 11, weight: .medium))340 .foregroundStyle(color)341 if let p = position {342 Text("\(p.index)/\(p.total)")343 .font(.system(size: 10, weight: .semibold).monospacedDigit())344 .foregroundStyle(.secondary)345 }346 }347 .padding(.horizontal, 8)348 .padding(.vertical, 4)349 .background(color.opacity(0.1))350 .clipShape(Capsule())320 StatusBadge(321 label: label,322 color: Color.status(for: status, confirmed: confirmed),323 showSpinner: status == .inProgress,324 trailing: position.map { "\($0.index)/\($0.total)" }325 )351326 }352327353328 private var label: String {@@ -358,15 +333,6 @@ struct StatusCell: View {358333 case .failed: return "Failed"359334 }360335 }361362 private var color: Color {363 switch status {364 case .done: return confirmed ? .green : .blue365 case .failed: return .red366 case .inProgress: return .orange367 case .queued: return .secondary368 }369 }370336}371337372338// MARK: - ConfidenceCell@@ -380,7 +346,7 @@ struct ConfidenceCell: View {380346 let pct = Int((c * 100).rounded())381347 Text("\(pct)%")382348 .font(.subheadline.monospacedDigit())383 .foregroundStyle(color(c))349 .foregroundStyle(Color.confidence(for: c))384350 } else {385351 Text("—")386352 .font(.subheadline)@@ -388,12 +354,6 @@ struct ConfidenceCell: View {388354 }389355 }390356 }391392 private func color(_ c: Double) -> Color {393 if c >= 0.85 { return .green }394 if c >= 0.60 { return .orange }395 return .red396 }397357}398358399359// MARK: - TimeCell (counts up while processing, final duration once done/failed)
Rhea/Views/SettingsView.swift
+12 −37
@@ -21,7 +21,7 @@ struct SettingsView: View {2121 // MARK: - Sections22222323 private var extractionSection: some View {24 SettingsCard(title: "AI Extraction", icon: "cpu") {24 Card(title: "AI Extraction", systemImage: "cpu", variant: .section) {2525 VStack(spacing: 14) {2626 ConfigField(2727 label: "LM Studio / oMLX Endpoint",@@ -42,7 +42,7 @@ struct SettingsView: View {4242 }43434444 private var postgresSection: some View {45 SettingsCard(title: "PostgreSQL", icon: "server.rack") {45 Card(title: "PostgreSQL", systemImage: "server.rack", variant: .section) {4646 VStack(spacing: 14) {4747 HStack(alignment: .top, spacing: 12) {4848 ConfigField(@@ -101,24 +101,25 @@ struct SettingsView: View {101101 }102102103103 private var exportSection: some View {104 SettingsCard(title: "Export", icon: "square.and.arrow.up") {104 Card(title: "Export", systemImage: "square.and.arrow.up", variant: .section) {105105 VStack(spacing: 16) {106106 // Status banner107107 if let status = viewModel.exportStatus {108 let color = status.isSuccess ? Color.successAccent : Color.errorAccent108109 HStack(spacing: 8) {109110 Image(systemName: status.isSuccess ? "checkmark.circle.fill" : "exclamationmark.triangle.fill")110 .foregroundStyle(status.isSuccess ? Color.green : Color.red)111 .foregroundStyle(color)111112 Text(status.message)112113 .font(.callout)113 .foregroundStyle(status.isSuccess ? Color.green : Color.red)114 .foregroundStyle(color)114115 .fixedSize(horizontal: false, vertical: true)115116 Spacer()116117 }117118 .padding(12)118 .background((status.isSuccess ? Color.green : Color.red).opacity(0.06))119 .background(color.opacity(0.06))119120 .overlay(120121 RoundedRectangle(cornerRadius: 8)121 .strokeBorder((status.isSuccess ? Color.green : Color.red).opacity(0.2), lineWidth: 0.5)122 .strokeBorder(color.opacity(0.2), lineWidth: 0.5)122123 )123124 .clipShape(RoundedRectangle(cornerRadius: 8))124125 }@@ -128,14 +129,14 @@ struct SettingsView: View {128129 ExportButton(129130 label: "Export to CSV",130131 icon: "doc.text",131 color: .blue,132 color: .csvAccent,132133 loading: viewModel.isExporting133134 ) { Task { await viewModel.exportToCSV() } }134135135136 ExportButton(136137 label: "Export to Postgres",137138 icon: "server.rack",138 color: .indigo,139 color: .postgresAccent,139140 loading: viewModel.isExporting,140141 disabled: !viewModel.postgresConfig.isConfigured141142 ) { Task { await viewModel.exportToPostgres() } }@@ -165,7 +166,7 @@ struct SettingsView: View {165166 }166167167168 private var aboutSection: some View {168 SettingsCard(title: "About", icon: "info.circle") {169 Card(title: "About", systemImage: "info.circle", variant: .section) {169170 VStack(spacing: 8) {170171 InfoRow(label: "Phase", value: "6 — Polish & Integration")171172 InfoRow(label: "Build", value: "Swift Package Manager")@@ -193,7 +194,7 @@ struct SettingsView: View {193194 .background(Color.secondary.opacity(0.06))194195 .overlay(195196 RoundedRectangle(cornerRadius: 6)196 .strokeBorder(Color.primary.opacity(0.08), lineWidth: 0.5)197 .strokeBorder(Color.cardBorder, lineWidth: 0.5)197198 )198199 .clipShape(RoundedRectangle(cornerRadius: 6))199200@@ -229,32 +230,6 @@ struct SettingsView: View {229230230231// MARK: - Reusable components231232232private struct SettingsCard<Content: View>: View {233 let title: String234 let icon: String235 @ViewBuilder var content: () -> Content236237 var body: some View {238 VStack(alignment: .leading, spacing: 14) {239 Label(title, systemImage: icon)240 .font(.headline)241 .foregroundStyle(.primary)242243 Divider()244245 content()246 }247 .padding(18)248 .background(.background)249 .clipShape(RoundedRectangle(cornerRadius: 12))250 .overlay(251 RoundedRectangle(cornerRadius: 12)252 .strokeBorder(Color.primary.opacity(0.08), lineWidth: 0.5)253 )254 .shadow(color: .black.opacity(0.04), radius: 4, x: 0, y: 1)255 }256}257258233private struct ConfigField: View {259234 let label: String260235 let placeholder: String