From e0a5bb3d5d0eaddab24e03e7bb5773073595e51d Mon Sep 17 00:00:00 2001 From: FuelBoard Contributor Date: Tue, 11 Aug 2026 18:29:20 +0100 Subject: [PATCH] Cheapest reference uses chosen miles radius (same pool as list) in app + widget; header shows 'within N miles' --- FuelBoard/ContentView.swift | 13 ++++++------- FuelBoard/StationsView.swift | 3 +-- FuelBoardWidgets/FuelPriceWidget.swift | 5 +++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/FuelBoard/ContentView.swift b/FuelBoard/ContentView.swift index 2102283..46cdf60 100644 --- a/FuelBoard/ContentView.swift +++ b/FuelBoard/ContentView.swift @@ -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) } diff --git a/FuelBoard/StationsView.swift b/FuelBoard/StationsView.swift index 5dc963d..c4cfadc 100644 --- a/FuelBoard/StationsView.swift +++ b/FuelBoard/StationsView.swift @@ -11,7 +11,6 @@ struct StationsView: View { @Binding var stationLimit: Int let cheapestPrice: Double? let location: Coordinate? - let radiusKM: Double let favouriteIDs: Set 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 { diff --git a/FuelBoardWidgets/FuelPriceWidget.swift b/FuelBoardWidgets/FuelPriceWidget.swift index 845631e..61ee2b5 100644 --- a/FuelBoardWidgets/FuelPriceWidget.swift +++ b/FuelBoardWidgets/FuelPriceWidget.swift @@ -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