Results filter is now search radius in miles (5/10/15); relay fetch scoped to radius, limit 500; changing miles re-fetches; caption shows stations within N miles

This commit is contained in:
FuelBoard Contributor
2026-08-11 18:02:23 +01:00
parent 810cc2c006
commit 213f93aa04
4 changed files with 34 additions and 19 deletions
+12 -2
View File
@@ -39,7 +39,9 @@ struct ContentView: View {
}
private var displayedStations: [FuelStation] {
Array(sortedStations.prefix(stationLimit))
// Relay already returns every station within the selected miles radius
// (sorted nearest-first); no local cap needed.
sortedStations
}
private var sortedStations: [FuelStation] {
@@ -145,6 +147,10 @@ struct ContentView: View {
// No re-fetch needed one response carries E5/E10/DIESEL prices.
WidgetCenter.shared.reloadAllTimelines()
}
.onChange(of: stationLimit) { _, _ in
// Search radius changed (miles) cached stations may not cover it.
Task { await refresh(force: true) }
}
.onChange(of: alertsEnabled) { _, newValue in
FuelStore.saveAlertsEnabled(newValue)
monitor.setEnabled(newValue)
@@ -182,7 +188,11 @@ struct ContentView: View {
isLoading = true
defer { isLoading = false }
do {
let fetched = try await FuelPriceProvider.active.fetchStations(near: location?.lat, lng: location?.lng, fuel: selectedFuel)
let fetched = try await FuelPriceProvider.active.fetchStations(
near: location?.lat, lng: location?.lng,
fuel: selectedFuel,
radiusKM: Double(stationLimit) * 1.60934 // miles km
)
stations = fetched
FuelStore.saveStations(fetched)
FuelStore.saveLastRefresh()