Sort every fuel tab cheapest-first (distance only as tiebreaker) in app + widget

This commit is contained in:
FuelBoard Contributor
2026-08-11 14:09:14 +01:00
parent 4f5f1999a9
commit 543212a721
2 changed files with 13 additions and 12 deletions
+6 -3
View File
@@ -91,9 +91,12 @@ struct FuelPriceTimelineProvider: TimelineProvider {
let sorted: [FuelStation]
if let location {
sorted = filtered.sorted { lhs, rhs in
let lScore = lhs.distanceKM(to: location.lat, lng2: location.lng) * 0.4 + lhs.prices[fuel]! * 0.001
let rScore = rhs.distanceKM(to: location.lat, lng2: location.lng) * 0.4 + rhs.prices[fuel]! * 0.001
return lScore < rScore
// Cheapest first; distance only breaks ties.
let lPrice = lhs.prices[fuel]!
let rPrice = rhs.prices[fuel]!
if lPrice != rPrice { return lPrice < rPrice }
return lhs.distanceKM(to: location.lat, lng2: location.lng) <
rhs.distanceKM(to: location.lat, lng2: location.lng)
}
} else {
sorted = filtered.sorted { $0.prices[fuel]! < $1.prices[fuel]! }