Distance picker disabled in Closest mode; whole-country pool for nearest-first (radius never empties Closest)

This commit is contained in:
FuelBoard Contributor
2026-08-11 19:49:26 +01:00
parent 3cff677729
commit 3bc795317a
2 changed files with 39 additions and 33 deletions
+24 -6
View File
@@ -27,9 +27,15 @@ struct StationsView: View {
List {
Section {
if let location {
Text("\(sortMode == .closest ? "Closest" : "Cheapest") \(selectedFuel.displayName) within \(stationLimit) miles — tap a station for directions.")
.font(.footnote)
.foregroundStyle(.secondary)
if sortMode == .closest {
Text("Closest \(selectedFuel.displayName) stations — tap a station for directions.")
.font(.footnote)
.foregroundStyle(.secondary)
} else {
Text("Cheapest \(selectedFuel.displayName) within \(stationLimit) miles — tap a station for directions.")
.font(.footnote)
.foregroundStyle(.secondary)
}
} else {
Text("\(sortMode == .closest ? "Closest" : "Cheapest") \(selectedFuel.displayName) — tap a station for directions.")
.font(.footnote)
@@ -57,13 +63,25 @@ struct StationsView: View {
}
}
.pickerStyle(.segmented)
// In Closest mode the whole country is the pool the
// radius is meaningless ("nearest" must never return an
// empty state), so the picker is disabled but its value is
// kept for when the user switches back to Cheapest.
.disabled(sortMode == .closest)
.opacity(sortMode == .closest ? 0.5 : 1)
.onChange(of: stationLimit) { _, newValue in
FuelStore.saveStationLimit(newValue)
}
.padding(.vertical, 2)
Text("\(totalCount) stations within \(stationLimit) miles")
.font(.caption2)
.foregroundStyle(.secondary)
if sortMode == .closest {
Text("Distance only applies to Cheapest")
.font(.caption2)
.foregroundStyle(.secondary)
} else {
Text("\(totalCount) stations within \(stationLimit) miles")
.font(.caption2)
.foregroundStyle(.secondary)
}
}
Section("Stations") {