Enforce chosen miles radius client-side (cache may hold larger-radius stations); monospaced £ price + delta for decimal alignment

This commit is contained in:
FuelBoard Contributor
2026-08-11 18:07:17 +01:00
parent 0fc24eab7c
commit bcf4ea4f81
+17 -5
View File
@@ -45,9 +45,21 @@ struct ContentView: View {
} }
private var sortedStations: [FuelStation] { private var sortedStations: [FuelStation] {
// Full fetch pool NOT radius-scoped, so the results count picker // Stations selling the selected fuel, scoped to the chosen miles radius
// (10/25/50/75/100) is respected. // from the current location. Local enforcement matters: the cache can
let available = stations.filter { $0.prices[selectedFuel] != nil } // hold stations from a previous, larger radius, and the relay filter
// only applies at fetch time.
let selling = stations.filter { $0.prices[selectedFuel] != nil }
let available: [FuelStation]
if let location {
let radiusKM = Double(stationLimit) * 1.60934 // miles km
let within = selling.filter {
$0.distanceKM(to: location.lat, lng2: location.lng) <= radiusKM
}
available = within.isEmpty ? selling : within
} else {
available = selling
}
switch sortMode { switch sortMode {
case .closest: case .closest:
guard let location else { return available.sorted { $0.prices[selectedFuel]! < $1.prices[selectedFuel]! } } guard let location else { return available.sorted { $0.prices[selectedFuel]! < $1.prices[selectedFuel]! } }
@@ -294,12 +306,12 @@ struct StationRow: View {
.fill(ragColor) .fill(ragColor)
.frame(width: 8, height: 8) .frame(width: 8, height: 8)
Text(String(format: "£%.3f", price / 100)) Text(String(format: "£%.3f", price / 100))
.font(.title3.bold()) .font(.title3.bold().monospaced())
.monospacedDigit() .monospacedDigit()
} }
if let deltaText { if let deltaText {
Text(deltaText) Text(deltaText)
.font(.caption2.bold()) .font(.caption2.bold().monospaced())
.foregroundStyle(ragColor) .foregroundStyle(ragColor)
} }
} }