Vorgeschlagene Kategorie wird uebernommen, nicht nur angezeigt
Beim Scannen stand auf der Karte "Kategorie ... vorgeschlagen", im Formular war das Feld danach trotzdem leer - man musste dieselbe Kategorie von Hand nochmal auswaehlen. Der Vorschlag war damit wertlos: Wer weiss, dass Pesto eine Sosse ist, gewinnt nichts daraus, es dem Formular noch einmal zu erzaehlen. Die Ursache lag nicht am Server. Der Lookup liefert category_id und category_name; die App merkte sich aber nur den Namen fuer die Anzeige und warf die ID weg. ProductFormView bekam sie gar nicht erst gereicht - anders als die Gruppe, die schon immer uebernommen wurde. Die Web-Oberflaeche macht es seit jeher richtig (setNewCategoryId in pages/CheckIn.jsx), nur die App nicht. Jetzt wird die ID durchgereicht und wie die Gruppe vorbelegt. Aenderbar bleibt sie: Gespeichert wird ohnehin erst mit "Anlegen & weiter". Der Hinweis auf der Karte heisst deshalb nicht mehr "vorgeschlagen", sondern "wird zugeordnet" - das war vorher richtig und waere es jetzt nicht mehr. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ?? ""
|
||||
|
||||
Reference in New Issue
Block a user