From bcf4ea4f81899637fab8ea7730aaf60e7109a23d Mon Sep 17 00:00:00 2001 From: FuelBoard Contributor Date: Tue, 11 Aug 2026 18:07:17 +0100 Subject: [PATCH] =?UTF-8?q?Enforce=20chosen=20miles=20radius=20client-side?= =?UTF-8?q?=20(cache=20may=20hold=20larger-radius=20stations);=20monospace?= =?UTF-8?q?d=20=C2=A3=20price=20+=20delta=20for=20decimal=20alignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FuelBoard/ContentView.swift | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/FuelBoard/ContentView.swift b/FuelBoard/ContentView.swift index a979e88..2102283 100644 --- a/FuelBoard/ContentView.swift +++ b/FuelBoard/ContentView.swift @@ -45,9 +45,21 @@ struct ContentView: View { } private var sortedStations: [FuelStation] { - // Full fetch pool — NOT radius-scoped, so the results count picker - // (10/25/50/75/100) is respected. - let available = stations.filter { $0.prices[selectedFuel] != nil } + // Stations selling the selected fuel, scoped to the chosen miles radius + // from the current location. Local enforcement matters: the cache can + // hold stations from a previous, larger radius, and the relay filter + // only applies at fetch time. + let selling = stations.filter { $0.prices[selectedFuel] != nil } + let available: [FuelStation] + if let location { + let radiusKM = Double(stationLimit) * 1.60934 // miles → km + let within = selling.filter { + $0.distanceKM(to: location.lat, lng2: location.lng) <= radiusKM + } + available = within.isEmpty ? selling : within + } else { + available = selling + } switch sortMode { case .closest: guard let location else { return available.sorted { $0.prices[selectedFuel]! < $1.prices[selectedFuel]! } } @@ -294,12 +306,12 @@ struct StationRow: View { .fill(ragColor) .frame(width: 8, height: 8) Text(String(format: "£%.3f", price / 100)) - .font(.title3.bold()) + .font(.title3.bold().monospaced()) .monospacedDigit() } if let deltaText { Text(deltaText) - .font(.caption2.bold()) + .font(.caption2.bold().monospaced()) .foregroundStyle(ragColor) } }