Add button to save
This commit is contained in:
parent
953a064de6
commit
63eacbb378
@ -8,6 +8,9 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct AddEntryView: View {
|
struct AddEntryView: View {
|
||||||
|
@Environment(\.presentationMode) var presentationMode
|
||||||
|
@Environment(\.modelContext) var ctx
|
||||||
|
|
||||||
@State private var t1: String = ""
|
@State private var t1: String = ""
|
||||||
@State private var t2: String = ""
|
@State private var t2: String = ""
|
||||||
|
|
||||||
@ -42,15 +45,29 @@ struct AddEntryView: View {
|
|||||||
.navigationTitle("New Entry")
|
.navigationTitle("New Entry")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .cancellationAction) {
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
Button("Cancel") {}
|
Button(action: { presentationMode.wrappedValue.dismiss() }) {
|
||||||
|
Text("Cancel")
|
||||||
|
.foregroundStyle(.red)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
Button("Confirm") {
|
Button(action: addItem) {
|
||||||
|
Text("Add")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
func addItem() {
|
||||||
}
|
let newItem = Entry(
|
||||||
}
|
odo: Int(Odometer) ?? 0,
|
||||||
}
|
cost: Double(TotalCost) ?? 0,
|
||||||
|
quantity: Double(Litres) ?? 0,
|
||||||
|
fuelType: Location
|
||||||
|
)
|
||||||
|
ctx.insert(newItem)
|
||||||
|
try? ctx.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user