diff --git a/FuelBoardWidgets/WidgetConfigIntent.swift b/FuelBoardWidgets/WidgetConfigIntent.swift index ca69169..c1e4224 100644 --- a/FuelBoardWidgets/WidgetConfigIntent.swift +++ b/FuelBoardWidgets/WidgetConfigIntent.swift @@ -21,48 +21,24 @@ enum WidgetFuel: String, AppEnum, CaseIterable, Codable { ] } -// Per-widget sort order. Modelled as an AppEntity (not an AppEnum) so the -// options can be dynamic: "Favourites" only appears when the user actually -// has favourites — an empty favourite list makes the option dead weight. -struct WidgetSort: AppEntity, Identifiable, Hashable, Codable { - enum Kind: String, Codable { - case cheapest - case closest - case favourites - } - - let id: String - - var kind: Kind { Kind(rawValue: id) ?? .cheapest } - - static let cheapest = WidgetSort(id: "cheapest") - static let closest = WidgetSort(id: "closest") - static let favourites = WidgetSort(id: "favourites") - - var displayRepresentation: DisplayRepresentation { - switch kind { - case .cheapest: return DisplayRepresentation(stringLiteral: "Cheapest") - case .closest: return DisplayRepresentation(stringLiteral: "Closest") - case .favourites: return DisplayRepresentation(stringLiteral: "Favourites") - } - } +// Per-widget sort order. A String-backed AppEnum (NOT an AppEntity): the +// parameterSummary conditionals (When(\.$sort, .equalTo, …)) fall back to the +// otherwise branch for AppEntity parameters (iOS 17+ bug FB13263902), which +// hid the Favourite picker. String AppEnums match reliably. Tradeoff: the +// option set is static — "Favourites" always appears, and picking it with no +// favourites shows the empty state. +enum WidgetSort: String, AppEnum, CaseIterable, Codable { + case cheapest + case closest + case favourites static var typeDisplayRepresentation: TypeDisplayRepresentation = "Sort by" - static var defaultQuery = WidgetSortQuery() -} -struct WidgetSortQuery: EntityQuery { - func entities(for identifiers: [String]) async throws -> [WidgetSort] { - identifiers.map { WidgetSort(id: $0) } - } - - func suggestedEntities() async throws -> [WidgetSort] { - var sorts = [WidgetSort.cheapest, WidgetSort.closest] - if !FuelStore.loadFavourites().isEmpty { - sorts.append(.favourites) - } - return sorts - } + static var caseDisplayRepresentations: [WidgetSort: DisplayRepresentation] = [ + .cheapest: "Cheapest", + .closest: "Closest", + .favourites: "Favourites", + ] } // Per-widget distance filter. Modelled as an AppEntity (not an AppEnum) so