diff --git a/ios/Sources/CheckInView.swift b/ios/Sources/CheckInView.swift index 4dc3651..c563854 100644 --- a/ios/Sources/CheckInView.swift +++ b/ios/Sources/CheckInView.swift @@ -12,6 +12,7 @@ struct CheckInView: View { @State private var suggestion: LookupResult.Suggestion? @State private var suggestedGroupId: Int? @State private var suggestedGroupName: String? + @State private var suggestedCategoryId: Int? @State private var suggestedCategoryName: String? @State private var unknownCode: String? @State private var manualCodeShown = false @@ -117,8 +118,8 @@ struct CheckInView: View { private func groupNote() -> some View { if let kategorie = suggestedCategoryName { noteRow(symbol: "square.grid.2x2", - title: "Kategorie „\(kategorie)“ vorgeschlagen", - detail: "Aus der Einordnung bei Open Food Facts.") + title: "Wird der Kategorie „\(kategorie)“ zugeordnet", + detail: "Aus der Einordnung bei Open Food Facts – im Formular änderbar.") } if let name = suggestedGroupName { noteRow(symbol: "tag", @@ -151,7 +152,7 @@ struct CheckInView: View { groupNote() NavigationLink { ProductFormView(prefillBarcode: item.barcode, groupId: suggestedGroupId, - suggestion: item) { created in + categoryId: suggestedCategoryId, suggestion: item) { created in suggestion = nil product = created } @@ -174,7 +175,8 @@ struct CheckInView: View { .font(.caption).foregroundStyle(.secondary) groupNote() NavigationLink { - ProductFormView(prefillBarcode: code, groupId: suggestedGroupId) { created in + ProductFormView(prefillBarcode: code, groupId: suggestedGroupId, + categoryId: suggestedCategoryId) { created in unknownCode = nil product = created } @@ -202,6 +204,7 @@ struct CheckInView: View { let result = try await APIClient.shared.lookup(barcode: code) suggestedGroupId = result.groupId suggestedGroupName = result.groupName + suggestedCategoryId = result.categoryId suggestedCategoryName = result.categoryName if let existing = result.existingProduct { product = existing diff --git a/ios/Sources/ProductViews.swift b/ios/Sources/ProductViews.swift index b311c2c..bbbe041 100644 --- a/ios/Sources/ProductViews.swift +++ b/ios/Sources/ProductViews.swift @@ -53,6 +53,8 @@ struct ProductSearchView: View { struct ProductFormView: View { let prefillBarcode: String? let groupId: Int? + /// Aus der Open-Food-Facts-Einordnung vorgeschlagene Kategorie. + var categoryId: Int? var suggestion: LookupResult.Suggestion? var onCreated: (Product) -> Void @@ -153,8 +155,11 @@ struct ProductFormView: View { private func prefill() { barcode = suggestion?.barcode ?? prefillBarcode ?? "" - // Aus dem gescannten Code vorgeschlagene Gruppe uebernehmen. + // Aus dem gescannten Code vorgeschlagene Gruppe und Kategorie + // uebernehmen. Beides bleibt aenderbar - gespeichert wird erst mit + // "Anlegen & weiter". selectedGroupId = groupId + selectedCategoryId = categoryId if let suggestion { name = suggestion.name brand = suggestion.brand ?? ""