Small widget favourites: fuel row returns to the config sheet (picks the default favourite); pinned favourite wins, fuel-tagged picker rows when favourites span >1 fuel; fallback = selected fuel's cheapest favourite

This commit is contained in:
FuelBoard Contributor
2026-08-13 16:51:21 +01:00
parent 1bdef59d78
commit 7357eb98c3
2 changed files with 35 additions and 22 deletions
+24 -13
View File
@@ -162,20 +162,31 @@ struct FuelPriceTimelineProvider<Configuration: WidgetConfigurationIntent & Widg
.filter { $0.station.prices[$0.fuel] != nil }
// Small widget, pinned favourite: exactly ONE station, its own
// fuel, no radius. Freshen its price when a focused fetch covers it.
if let chosen = configuration.favouriteChoice,
let entry = favourites.first(where: { $0.id == chosen.id }) {
var station = entry.station
if let location,
let fetched = await Self.fetchFocused(near: location, fuel: entry.fuel, radiusKM: radiusKM),
let fresh = fetched.first(where: { $0.id == entry.station.id }) {
station = fresh
// fuel, no radius. Freshen its price when a focused fetch covers
// it. The chosen favourite wins; when it's missing or stale (fresh
// widget, favourite removed, fuel row changed) fall back to the
// Fuel row's cheapest favourite so the face is never blank.
if let chosen = configuration.favouriteChoice {
let pinned = favourites.first { $0.id == chosen.id }
?? favourites
.filter { $0.fuel == fuel && $0.station.prices[fuel] != nil }
.min { lhs, rhs in
(lhs.station.prices[fuel] ?? .infinity) <
(rhs.station.prices[fuel] ?? .infinity)
}
if let pinned {
var station = pinned.station
if let location,
let fetched = await Self.fetchFocused(near: location, fuel: pinned.fuel, radiusKM: radiusKM),
let fresh = fetched.first(where: { $0.id == pinned.station.id }) {
station = fresh
}
return FuelPriceEntry(
date: Date(), stations: [station],
fuel: pinned.fuel, sort: .cheapest, isFavourites: true,
location: location, locationSource: source, unit: unit
)
}
return FuelPriceEntry(
date: Date(), stations: [station],
fuel: entry.fuel, sort: .cheapest, isFavourites: true,
location: location, locationSource: source, unit: unit
)
}
// List mode (medium): pinned stations for THIS fuel, cheapest-first.