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 suggestion: LookupResult.Suggestion?
|
||||||
@State private var suggestedGroupId: Int?
|
@State private var suggestedGroupId: Int?
|
||||||
@State private var suggestedGroupName: String?
|
@State private var suggestedGroupName: String?
|
||||||
|
@State private var suggestedCategoryId: Int?
|
||||||
@State private var suggestedCategoryName: String?
|
@State private var suggestedCategoryName: String?
|
||||||
@State private var unknownCode: String?
|
@State private var unknownCode: String?
|
||||||
@State private var manualCodeShown = false
|
@State private var manualCodeShown = false
|
||||||
@@ -117,8 +118,8 @@ struct CheckInView: View {
|
|||||||
private func groupNote() -> some View {
|
private func groupNote() -> some View {
|
||||||
if let kategorie = suggestedCategoryName {
|
if let kategorie = suggestedCategoryName {
|
||||||
noteRow(symbol: "square.grid.2x2",
|
noteRow(symbol: "square.grid.2x2",
|
||||||
title: "Kategorie „\(kategorie)“ vorgeschlagen",
|
title: "Wird der Kategorie „\(kategorie)“ zugeordnet",
|
||||||
detail: "Aus der Einordnung bei Open Food Facts.")
|
detail: "Aus der Einordnung bei Open Food Facts – im Formular änderbar.")
|
||||||
}
|
}
|
||||||
if let name = suggestedGroupName {
|
if let name = suggestedGroupName {
|
||||||
noteRow(symbol: "tag",
|
noteRow(symbol: "tag",
|
||||||
@@ -151,7 +152,7 @@ struct CheckInView: View {
|
|||||||
groupNote()
|
groupNote()
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
ProductFormView(prefillBarcode: item.barcode, groupId: suggestedGroupId,
|
ProductFormView(prefillBarcode: item.barcode, groupId: suggestedGroupId,
|
||||||
suggestion: item) { created in
|
categoryId: suggestedCategoryId, suggestion: item) { created in
|
||||||
suggestion = nil
|
suggestion = nil
|
||||||
product = created
|
product = created
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,8 @@ struct CheckInView: View {
|
|||||||
.font(.caption).foregroundStyle(.secondary)
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
groupNote()
|
groupNote()
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
ProductFormView(prefillBarcode: code, groupId: suggestedGroupId) { created in
|
ProductFormView(prefillBarcode: code, groupId: suggestedGroupId,
|
||||||
|
categoryId: suggestedCategoryId) { created in
|
||||||
unknownCode = nil
|
unknownCode = nil
|
||||||
product = created
|
product = created
|
||||||
}
|
}
|
||||||
@@ -202,6 +204,7 @@ struct CheckInView: View {
|
|||||||
let result = try await APIClient.shared.lookup(barcode: code)
|
let result = try await APIClient.shared.lookup(barcode: code)
|
||||||
suggestedGroupId = result.groupId
|
suggestedGroupId = result.groupId
|
||||||
suggestedGroupName = result.groupName
|
suggestedGroupName = result.groupName
|
||||||
|
suggestedCategoryId = result.categoryId
|
||||||
suggestedCategoryName = result.categoryName
|
suggestedCategoryName = result.categoryName
|
||||||
if let existing = result.existingProduct {
|
if let existing = result.existingProduct {
|
||||||
product = existing
|
product = existing
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ struct ProductSearchView: View {
|
|||||||
struct ProductFormView: View {
|
struct ProductFormView: View {
|
||||||
let prefillBarcode: String?
|
let prefillBarcode: String?
|
||||||
let groupId: Int?
|
let groupId: Int?
|
||||||
|
/// Aus der Open-Food-Facts-Einordnung vorgeschlagene Kategorie.
|
||||||
|
var categoryId: Int?
|
||||||
var suggestion: LookupResult.Suggestion?
|
var suggestion: LookupResult.Suggestion?
|
||||||
var onCreated: (Product) -> Void
|
var onCreated: (Product) -> Void
|
||||||
|
|
||||||
@@ -153,8 +155,11 @@ struct ProductFormView: View {
|
|||||||
|
|
||||||
private func prefill() {
|
private func prefill() {
|
||||||
barcode = suggestion?.barcode ?? prefillBarcode ?? ""
|
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
|
selectedGroupId = groupId
|
||||||
|
selectedCategoryId = categoryId
|
||||||
if let suggestion {
|
if let suggestion {
|
||||||
name = suggestion.name
|
name = suggestion.name
|
||||||
brand = suggestion.brand ?? ""
|
brand = suggestion.brand ?? ""
|
||||||
|
|||||||
Reference in New Issue
Block a user