Favourites: drag-and-drop reorder per fuel; stored order drives single-widget favourite
This commit is contained in:
@@ -208,16 +208,17 @@ struct FuelPriceTimelineProvider<Configuration: WidgetConfigurationIntent & Widg
|
||||
let favourites = FuelStore.loadFavourites()
|
||||
.filter { $0.station.prices[$0.fuel] != nil }
|
||||
|
||||
// Pinned stations for THIS fuel, cheapest-first. Not
|
||||
// radius-bound — a favourite in Edinburgh shows on a widget in
|
||||
// London. Prices come from the keychain snapshot (the app
|
||||
// refreshes favourite prices into keychain after every fetch), or
|
||||
// fresher from a focused relay fetch when a favourite happens to
|
||||
// be in range. The small face renders the first of this list —
|
||||
// the cheapest favourite of the chosen fuel. (The old per-widget
|
||||
// pinned-favourite picker was removed: its AppEntity params made
|
||||
// fresh-widget default-config resolution fail at the system level
|
||||
// — the merged widget uses the minimal fuel/sort/distance intent.)
|
||||
// Pinned stations for THIS fuel, in the USER'S manual order (the
|
||||
// Favourites tab drag-to-reorder). Not radius-bound — a favourite
|
||||
// in Edinburgh shows on a widget in London. Prices come from the
|
||||
// keychain snapshot (the app refreshes favourite prices into
|
||||
// keychain after every fetch), or fresher from a focused relay
|
||||
// fetch when a favourite happens to be in range. The small face
|
||||
// renders the FIRST of this list — the user's top favourite for
|
||||
// the chosen fuel. (The old per-widget pinned-favourite picker
|
||||
// was removed: its AppEntity params made fresh-widget
|
||||
// default-config resolution fail at the system level — the merged
|
||||
// widget uses the minimal fuel/sort/distance intent.)
|
||||
let fuelFavourites = favourites
|
||||
.filter { $0.fuel == fuel && $0.station.prices[fuel] != nil }
|
||||
.map(\.station)
|
||||
@@ -227,16 +228,10 @@ struct FuelPriceTimelineProvider<Configuration: WidgetConfigurationIntent & Widg
|
||||
let freshByID = Dictionary(uniqueKeysWithValues: fetched.map { ($0.id, $0) })
|
||||
refreshed = fuelFavourites.map { freshByID[$0.id] ?? $0 }
|
||||
}
|
||||
ordered = refreshed.sorted { lhs, rhs in
|
||||
let lPrice = lhs.prices[fuel]!
|
||||
let rPrice = rhs.prices[fuel]!
|
||||
if lPrice != rPrice { return lPrice < rPrice }
|
||||
if let location {
|
||||
return lhs.distanceKM(to: location.lat, lng2: location.lng) <
|
||||
rhs.distanceKM(to: location.lat, lng2: location.lng)
|
||||
}
|
||||
return false
|
||||
}
|
||||
// Stored order IS the widget order — the user's manual ranking,
|
||||
// NOT a price sort (cheapest-first would override the top
|
||||
// favourite that the Favourites tab sets for single widgets).
|
||||
ordered = refreshed
|
||||
} else {
|
||||
// 3a) Load stations. The widget prefers its OWN focused fetch from the
|
||||
// relay so it shows real prices even when the app-group cache isn't
|
||||
|
||||
Reference in New Issue
Block a user