Enforce chosen miles radius client-side (cache may hold larger-radius stations); monospaced £ price + delta for decimal alignment
This commit is contained in:
@@ -45,9 +45,21 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
private var sortedStations: [FuelStation] {
|
||||
// Full fetch pool — NOT radius-scoped, so the results count picker
|
||||
// (10/25/50/75/100) is respected.
|
||||
let available = stations.filter { $0.prices[selectedFuel] != nil }
|
||||
// Stations selling the selected fuel, scoped to the chosen miles radius
|
||||
// from the current location. Local enforcement matters: the cache can
|
||||
// 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 {
|
||||
case .closest:
|
||||
guard let location else { return available.sorted { $0.prices[selectedFuel]! < $1.prices[selectedFuel]! } }
|
||||
@@ -294,12 +306,12 @@ struct StationRow: View {
|
||||
.fill(ragColor)
|
||||
.frame(width: 8, height: 8)
|
||||
Text(String(format: "£%.3f", price / 100))
|
||||
.font(.title3.bold())
|
||||
.font(.title3.bold().monospaced())
|
||||
.monospacedDigit()
|
||||
}
|
||||
if let deltaText {
|
||||
Text(deltaText)
|
||||
.font(.caption2.bold())
|
||||
.font(.caption2.bold().monospaced())
|
||||
.foregroundStyle(ragColor)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user