Skip to content

Commit 6fba911

Browse files
committed
Make stock product info view more reliable
This now uses a more reliable state with an update task
1 parent e6671df commit 6fba911

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Shared/Views/Stock/StockProductInfoView.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ struct StockProductInfoView: View {
1616

1717
@Binding var stockElement: StockElement?
1818
@State private var firstOpen: Bool = true
19-
20-
var productDetails: StockProductDetails? {
21-
if let productID = stockElement?.productID {
22-
Task {
23-
try await grocyVM.getStockProductDetails(productID: productID)
24-
}
25-
return grocyVM.stockProductDetails[productID]
26-
} else { return nil }
27-
}
19+
@State private var productDetails: StockProductDetails? = nil
2820

2921
var body: some View {
3022
List {
@@ -101,6 +93,16 @@ struct StockProductInfoView: View {
10193
}
10294
}
10395
})
96+
.task {
97+
do {
98+
if let productID = stockElement?.productID {
99+
try await grocyVM.getStockProductDetails(productID: productID)
100+
productDetails = grocyVM.stockProductDetails[productID]
101+
}
102+
} catch {
103+
grocyVM.postLog("Get stock detail failed. \(error)", type: .error)
104+
}
105+
}
104106
}
105107
}
106108

0 commit comments

Comments
 (0)