Manual Entry kinda works
This commit is contained in:
@@ -2,7 +2,12 @@ import SwiftUI
|
||||
import LabWiseKit
|
||||
|
||||
struct ChemicalDetailView: View {
|
||||
let chemical: Chemical
|
||||
@State private var chemical: Chemical
|
||||
@State private var showEdit = false
|
||||
|
||||
init(chemical: Chemical) {
|
||||
self._chemical = State(initialValue: chemical)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
@@ -57,6 +62,9 @@ struct ChemicalDetailView: View {
|
||||
if let barcode = chemical.barcode {
|
||||
LabeledContent("Barcode", value: barcode)
|
||||
}
|
||||
if let contact = chemical.contact {
|
||||
LabeledContent("Contact", value: contact)
|
||||
}
|
||||
}
|
||||
|
||||
if let comments = chemical.comments, !comments.isEmpty {
|
||||
@@ -77,5 +85,30 @@ struct ChemicalDetailView: View {
|
||||
}
|
||||
.navigationTitle(chemical.chemicalName)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button {
|
||||
showEdit = true
|
||||
} label: {
|
||||
Image(systemName: "pencil")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showEdit) {
|
||||
AddChemicalView(editing: chemical) { saved in
|
||||
showEdit = false
|
||||
if saved {
|
||||
Task { await reloadChemical() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reload from server so the detail view reflects the saved changes.
|
||||
private func reloadChemical() async {
|
||||
let updated = try? await ChemicalsClient().list()
|
||||
if let match = updated?.first(where: { $0.id == chemical.id }) {
|
||||
chemical = match
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user