Scope cheapest/RAG/TOP to alert trigger radius in app + widget; header shows 'within X km'; falls back to full fetch when radius pool empty

This commit is contained in:
FuelBoard Contributor
2026-08-11 17:21:36 +01:00
parent cde51622a3
commit 2d95c4e1d6
3 changed files with 34 additions and 6 deletions
+9 -1
View File
@@ -84,9 +84,17 @@ struct FuelPriceTimelineProvider: TimelineProvider {
FuelStore.saveLocation(lat: location.lat, lng: location.lng)
}
// 3) Load stations, then sort by distance-weighted score.
// 3) Load stations, then sort by price (distance tiebreak), scoped to
// the alert trigger radius so the widget's "cheapest" matches the app.
var stations = FuelStore.loadStations()
if stations.isEmpty { stations = SampleFuelProvider.sampleStations }
let radiusKM = FuelStore.loadAlertsRadius()
if let location {
let within = stations.filter {
$0.distanceKM(to: location.lat, lng2: location.lng) <= radiusKM
}
if !within.isEmpty { stations = within }
}
let filtered = stations.filter { $0.prices[fuel] != nil }
let sorted: [FuelStation]
if let location {