From 3e2d3775f2d6c68ceec2171cd6a6750df6788bb7 Mon Sep 17 00:00:00 2001 From: FuelBoard Contributor Date: Thu, 13 Aug 2026 17:48:33 +0100 Subject: [PATCH] =?UTF-8?q?Widget=20config=20sheet:=20revert=20WidgetSort?= =?UTF-8?q?=20to=20String-backed=20AppEnum.=20parameterSummary=20When(\.$s?= =?UTF-8?q?ort,=20.equalTo,=20=E2=80=A6)=20silently=20falls=20back=20to=20?= =?UTF-8?q?the=20otherwise=20branch=20for=20AppEntity=20parameters=20(iOS?= =?UTF-8?q?=2017+=20bug=20FB13263902),=20which=20hid=20the=20Favourite/Fav?= =?UTF-8?q?ourite=20Fuel=20rows=20on=20the=20small=20widget=20=E2=80=94=20?= =?UTF-8?q?the=20metadata=20compared=20against=20a=20literal=20'WidgetSort?= =?UTF-8?q?.favourites'=20string=20instead=20of=20the=20enum=20case.=20Str?= =?UTF-8?q?ing=20AppEnums=20match=20reliably=20(the=20d8506a0=20form).=20T?= =?UTF-8?q?radeoff:=20the=20Sort=20picker=20always=20offers=20Favourites;?= =?UTF-8?q?=20picking=20it=20with=20no=20favourites=20shows=20the=20empty?= =?UTF-8?q?=20state.=20FavouriteFuel=20entity=20+=20IntentParameterDepende?= =?UTF-8?q?ncy=20filtering=20unchanged.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FuelBoardWidgets/WidgetConfigIntent.swift | 54 +++++++---------------- 1 file changed, 15 insertions(+), 39 deletions(-) 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