Sort toggle (cheapest/closest) + RAG value rating per station with TOP badge

This commit is contained in:
FuelBoard Contributor
2026-08-11 14:14:07 +01:00
parent 543212a721
commit d9ec2f8c35
3 changed files with 147 additions and 15 deletions
+19 -4
View File
@@ -162,7 +162,8 @@ struct FuelPriceWidgetView: View {
}
private var stationList: some View {
VStack(alignment: .leading, spacing: 6) {
let cheapest = entry.stations.compactMap { $0.prices[entry.fuel] }.min()
return VStack(alignment: .leading, spacing: 6) {
HStack {
Image(systemName: "fuelpump.fill")
.foregroundStyle(.green)
@@ -187,9 +188,14 @@ struct FuelPriceWidgetView: View {
}
Spacer()
if let price = station.prices[entry.fuel] {
Text(String(format: "%.1fp", price))
.font(.caption.weight(.bold))
.foregroundStyle(.green)
HStack(spacing: 4) {
Circle()
.fill(ragColor(for: price, cheapest: cheapest))
.frame(width: 6, height: 6)
Text(String(format: "%.1fp", price))
.font(.caption.weight(.bold))
.foregroundStyle(.primary)
}
}
}
}
@@ -199,4 +205,13 @@ struct FuelPriceWidgetView: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
private func ragColor(for price: Double, cheapest: Double?) -> Color {
guard let cheapest else { return .gray }
switch RAGRating.rating(price: price, cheapest: cheapest) {
case .green: return .green
case .amber: return .orange
case .red: return .red
}
}
}