Cheapest reference uses chosen miles radius (same pool as list) in app + widget; header shows 'within N miles'

This commit is contained in:
FuelBoard Contributor
2026-08-11 18:29:20 +01:00
parent bcf4ea4f81
commit e0a5bb3d5d
3 changed files with 10 additions and 11 deletions
+6 -7
View File
@@ -21,15 +21,15 @@ struct ContentView: View {
@State private var locationManager = LocationManager()
@StateObject private var monitor = ProximityMonitor()
/// Stations within the alert trigger radius of the current location used
/// ONLY as the "cheapest" reference (RAG, TOP, deltas), so the cheapest
/// label matches what alerts would flag. The list itself shows the full
/// fetch so the count picker works. Falls back to the full fetch when
/// location is unknown or the radius pool is empty.
/// Stations within the CHOSEN search radius (miles) of the current location
/// the same pool the list shows, so "cheapest" (RAG, TOP, deltas) matches
/// exactly what's on screen. Falls back to the full fetch when location is
/// unknown or the radius pool is empty.
private var radiusScopedStations: [FuelStation] {
guard let location else { return stations }
let radiusKM = Double(stationLimit) * 1.60934 // chosen miles km
let within = stations.filter {
$0.distanceKM(to: location.lat, lng2: location.lng) <= alertsRadius
$0.distanceKM(to: location.lat, lng2: location.lng) <= radiusKM
}
return within.isEmpty ? stations : within
}
@@ -102,7 +102,6 @@ struct ContentView: View {
stationLimit: $stationLimit,
cheapestPrice: cheapestPrice,
location: location,
radiusKM: alertsRadius,
favouriteIDs: favouriteIDs,
onToggleFavourite: toggleFavourite,
onRefresh: { await refresh(force: true) }