Cheapest reference uses chosen miles radius (same pool as list) in app + widget; header shows 'within N miles'
This commit is contained in:
@@ -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) }
|
||||
|
||||
@@ -11,7 +11,6 @@ struct StationsView: View {
|
||||
@Binding var stationLimit: Int
|
||||
let cheapestPrice: Double?
|
||||
let location: Coordinate?
|
||||
let radiusKM: Double
|
||||
let favouriteIDs: Set<String>
|
||||
var onToggleFavourite: (FuelStation) -> Void = { _ in }
|
||||
var onRefresh: () async -> Void = {}
|
||||
@@ -21,7 +20,7 @@ struct StationsView: View {
|
||||
List {
|
||||
Section {
|
||||
if let location {
|
||||
Text("\(sortMode == .closest ? "Closest" : "Cheapest") \(selectedFuel.displayName) within \(Int(radiusKM)) km — tap a station for directions.")
|
||||
Text("\(sortMode == .closest ? "Closest" : "Cheapest") \(selectedFuel.displayName) within \(stationLimit) miles — tap a station for directions.")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
} else {
|
||||
|
||||
@@ -85,10 +85,11 @@ struct FuelPriceTimelineProvider: TimelineProvider {
|
||||
}
|
||||
|
||||
// 3) Load stations, then sort by price (distance tiebreak), scoped to
|
||||
// the alert trigger radius so the widget's "cheapest" matches the app.
|
||||
// the chosen search radius (miles) so the widget's "cheapest" matches
|
||||
// the app's list.
|
||||
var stations = FuelStore.loadStations()
|
||||
if stations.isEmpty { stations = SampleFuelProvider.sampleStations }
|
||||
let radiusKM = FuelStore.loadAlertsRadius()
|
||||
let radiusKM = Double(FuelStore.loadStationLimit()) * 1.60934 // miles → km
|
||||
if let location {
|
||||
let within = stations.filter {
|
||||
$0.distanceKM(to: location.lat, lng2: location.lng) <= radiusKM
|
||||
|
||||
Reference in New Issue
Block a user