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:
@@ -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()
|
||||
|
||||
@@ -80,9 +80,9 @@ struct StationsView: View {
|
||||
|
||||
if !stations.isEmpty {
|
||||
Divider()
|
||||
Picker("Show", selection: $stationLimit) {
|
||||
ForEach([10, 25, 50, 75, 100], id: \.self) { count in
|
||||
Text("\(count)").tag(count)
|
||||
Picker("Within", selection: $stationLimit) {
|
||||
ForEach(FuelStore.stationRadiusOptions, id: \.self) { miles in
|
||||
Text("\(miles) miles").tag(miles)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
@@ -90,7 +90,7 @@ struct StationsView: View {
|
||||
FuelStore.saveStationLimit(newValue)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
Text("Showing \(stations.count) of \(totalCount) stations")
|
||||
Text("\(totalCount) stations within \(stationLimit) miles")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user