Sort toggle (cheapest/closest) + RAG value rating per station with TOP badge
This commit is contained in:
@@ -17,6 +17,36 @@ struct Coordinate: Equatable, Codable {
|
||||
let lng: Double
|
||||
}
|
||||
|
||||
enum SortMode: String, Codable, CaseIterable, Identifiable {
|
||||
case cheapest
|
||||
case closest
|
||||
|
||||
var id: String { rawValue }
|
||||
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .cheapest: return "Cheapest"
|
||||
case .closest: return "Closest"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// RAG value rating for a station's price against the cheapest available.
|
||||
/// Thumb rules: within 1.5p = green (great value), within 4p = amber (okay),
|
||||
/// beyond that = red (pricey). Deliberately coarse so it reads at a glance.
|
||||
enum RAGRating: Int, Codable {
|
||||
case green = 0
|
||||
case amber = 1
|
||||
case red = 2
|
||||
|
||||
static func rating(price: Double, cheapest: Double) -> RAGRating {
|
||||
let delta = price - cheapest
|
||||
if delta <= 1.5 { return .green }
|
||||
if delta <= 4.0 { return .amber }
|
||||
return .red
|
||||
}
|
||||
}
|
||||
|
||||
enum FuelType: String, Codable, CaseIterable, Identifiable {
|
||||
case e10 // Unleaded 95 (E10)
|
||||
case e5 // Premium 97/98 (E5)
|
||||
@@ -72,6 +102,7 @@ struct FuelStore {
|
||||
static let stationsKey = "fuelboard.stations" // [FuelStation] JSON
|
||||
static let locationKey = "fuelboard.lastLocation" // "lat,lng,timestamp"
|
||||
static let fuelKey = "fuelboard.selectedFuel" // FuelType raw value
|
||||
static let sortModeKey = "fuelboard.sortMode" // SortMode raw value
|
||||
|
||||
// MARK: Stations
|
||||
|
||||
@@ -123,6 +154,19 @@ struct FuelStore {
|
||||
saveString(fuel.rawValue, service: fuelKey)
|
||||
}
|
||||
|
||||
// MARK: Sort mode
|
||||
|
||||
static func loadSortMode() -> SortMode {
|
||||
if let raw = loadString(service: sortModeKey), let mode = SortMode(rawValue: raw) {
|
||||
return mode
|
||||
}
|
||||
return .cheapest
|
||||
}
|
||||
|
||||
static func saveSortMode(_ mode: SortMode) {
|
||||
saveString(mode.rawValue, service: sortModeKey)
|
||||
}
|
||||
|
||||
// MARK: Low-level keychain helpers
|
||||
|
||||
private static func keychainData(service: String) -> Data? {
|
||||
|
||||
Reference in New Issue
Block a user