Sort toggle (cheapest/closest) + RAG value rating per station with TOP badge
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user