Favourites are fuel-scoped: starring pins the station for one fuel only
Fixing the bug where favouriting an Unleaded entry also created a Diesel favourite. Favourites are now [FavouriteEntry] = (station, fuel) pairs: - Starring a row pins it only for the fuel being viewed - Favourites tabs show only fuels that actually have favourites - Geofence monitor gives priority slots only to favourites matching the monitored fuel - Tests updated + new fuel-scoping test (31/31 passing)
This commit is contained in:
@@ -10,7 +10,7 @@ struct ContentView: View {
|
||||
@State private var sortMode: SortMode = FuelStore.loadSortMode()
|
||||
@State private var stationLimit: Int = FuelStore.loadStationLimit()
|
||||
@State private var distanceUnit: DistanceUnit = FuelStore.loadDistanceUnit()
|
||||
@State private var favourites: [FuelStation] = FuelStore.loadFavourites()
|
||||
@State private var favourites: [FavouriteEntry] = FuelStore.loadFavourites()
|
||||
@State private var alertsEnabled: Bool = FuelStore.loadAlertsEnabled()
|
||||
@State private var alertsRadius: Double = FuelStore.loadAlertsRadius()
|
||||
@State private var location: Coordinate? = {
|
||||
@@ -95,11 +95,13 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Station IDs favourited for the CURRENTLY selected fuel — the star on a
|
||||
/// Stations-tab row reflects the fuel being viewed (fuel-scoped favourites).
|
||||
private var favouriteIDs: Set<String> {
|
||||
Set(favourites.map(\.id))
|
||||
Set(favourites.filter { $0.fuel == selectedFuel }.map(\.station.id))
|
||||
}
|
||||
|
||||
private var refreshedFavourites: [FuelStation] {
|
||||
private var refreshedFavourites: [FavouriteEntry] {
|
||||
FuelStore.refreshedFavourites(favourites, from: stations)
|
||||
}
|
||||
|
||||
@@ -127,7 +129,6 @@ struct ContentView: View {
|
||||
selectedFuel: selectedFuel,
|
||||
location: location,
|
||||
distanceUnit: distanceUnit,
|
||||
favouriteIDs: favouriteIDs,
|
||||
onToggleFavourite: toggleFavourite
|
||||
)
|
||||
.tabItem { Label("Favourites", systemImage: "star.fill") }
|
||||
@@ -222,11 +223,12 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func toggleFavourite(_ station: FuelStation) {
|
||||
if favouriteIDs.contains(station.id) {
|
||||
favourites.removeAll { $0.id == station.id }
|
||||
private func toggleFavourite(_ station: FuelStation, fuel: FuelType) {
|
||||
let key = FavouriteEntry(station: station, fuel: fuel)
|
||||
if favourites.contains(where: { $0.id == key.id }) {
|
||||
favourites.removeAll { $0.id == key.id }
|
||||
} else {
|
||||
favourites.append(station)
|
||||
favourites.append(key)
|
||||
}
|
||||
FuelStore.saveFavourites(favourites)
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
|
||||
Reference in New Issue
Block a user