Make Closest a station label and retire Top

Top and Cheapest were two words for one state: both meant "the lowest price
among the stations on screen", differing only in the candidate set (radius vs
Favourites). Which word a surface used had drifted by device — the phone's
rows said Cheapest while the watch said Top for the identical state. Top is
gone from the enum, the Key legend, the badge and the watch's hand-rolled
label; Cheapest survives because it names the measure and is already the word
the favourites copy uses.

Closest is now a real station label rather than a verdict. StationRecommendationBadge
gains .closest with a total precedence — Best value, then Cheapest, then Closest
— because a row has room for one label and proximity is the weakest claim: a
short drive says nothing about the price, and unlike the other two it reports no
saving at all. The badge sits above the price, where the other two sit. The
closest row's verdict capsule is suppressed: its only word for that state was
"Closest", so printing it below as well would state the same fact twice, three
lines apart. Other rows keep their Saves / Break even / Costs capsules unchanged.

"Closest station" becomes "Closest", read from the single
FuelSavingsResult.baselineHeadline constant so the badge, the verdict and the Key
cannot word it differently. The Key legend renders all three station labels with
the shared StationLabelBadge; the old KeyStationLabelIndicator, which
special-cased the closest station to a wider verdict pill so it read as a
different class of thing from the two above it, is deleted.

One closest icon everywhere. The listing and detail verdict symbols used
location.circle and location.circle.fill for the state the Key taught as
location.north.fill; both now read StationLabelKind.closest.symbol, so the three
surfaces resolve one glyph from one place.

The detail sheet gains the Closest capsule below the map, ordered to match the
Key. Favourites gains the nearest favourite as its Closest, measured on the same
one-way distance its rows print and restricted to favourites with a price for the
active fuel — matching the radius tab, where the closest station is by definition
the savings baseline.

closestStationID flows from the one scaffold baseline the savings lookup already
compares against, so a row's badge and the reference station cannot disagree.
No savings calculation, threshold, ranking, eligibility or station-selection
logic changed.

The Key sheet's detent is now bound rather than fixed, so dragging it up to read
the Station labels section sticks instead of snapping back; a QA launch argument
opens it at full height, since the 0.6 detent puts that section below the fold on
every device. That argument is read unconditionally, unlike the other harness
hooks which are #if DEBUG-gated.

Tests: 278 pass, 9 new — the label precedence ladder across every combination,
capsule order in the sheet, Closest alone, and the retired label pinned absent.
This commit is contained in:
FuelBoard Contributor
2026-10-19 14:59:47 +01:00
parent c69bdb3c5f
commit 8153a36168
13 changed files with 341 additions and 149 deletions
+27 -4
View File
@@ -77,6 +77,26 @@ struct FavouritesView: View {
}
private var cheapestPrice: Double? { cheapest?.prices[activeFuel] }
/// Nearest favourited station for the active fuel — this tab's Closest.
///
/// Measured on the same one-way distance the rows print, so the badge cannot
/// point at a station the list shows as further away than its neighbour. Only
/// favourites with a price for the active fuel are eligible, matching the
/// radius tab, where the closest station is by definition the savings
/// baseline; an unpriced favourite appears last and wears no label. Ties keep
/// the user's own order, which is what `ordered` already encodes.
private var nearest: FuelStation? {
guard let location else { return nil }
var best: (station: FuelStation, km: Double)?
for station in ordered where station.prices[activeFuel] != nil {
let km = FuelStore.stationDistanceDisplay(
station: station, userLat: location.lat, userLng: location.lng
).km
if best == nil || km < best!.km { best = (station, km) }
}
return best?.station
}
/// The baseline note is useful only when at least one visible favourite has
/// an actual savings comparison. An unavailable result (for example, while
/// location is missing) must not leave an orphaned explanation below the list.
@@ -183,7 +203,8 @@ struct FavouritesView: View {
distanceUnit: distanceUnit,
priceDisplayStyle: priceDisplayStyle,
baselinePrice: cheapestPrice,
isTopResult: station.id == cheapest?.id,
isCheapestResult: station.id == cheapest?.id,
isClosestResult: station.id == nearest?.id,
isFavourite: activeFuelFavouriteIDs.contains(station.id),
tapAction: stationTapAction,
fuelSavings: savingsForStation(station),
@@ -261,9 +282,11 @@ struct FavouritesView: View {
fuelSavings: savingsForStation(station),
fuelSavingsAmount: fuelSavingsAmount,
journeyDiagnostics: journeyDiagnosticsForStation(station),
// This tab's cheapest favourite — the station its rows badge,
// and the one the Key calls "Top".
isTopFavourite: station.id == cheapest?.id,
// This tab's cheapest favourite — the same flag its rows get,
// and the same label they wear.
isCheapestInRange: station.id == cheapest?.id,
// This tab's nearest favourite — the same flag its rows get.
isClosestInRange: station.id == nearest?.id,
// Every station listed here IS a favourite for the tab's
// fuel, so the star starts filled; tapping it unstars.
isFavourite: true,