Add new entry view
This commit is contained in:
parent
078719ef2b
commit
27adc0bc5a
48
gastrack/AddEntryView.swift
Normal file
48
gastrack/AddEntryView.swift
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// AddEntryView.swift
|
||||
// gastrack
|
||||
//
|
||||
// Created by Pradyun Setti on 23/02/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AddEntryView: View {
|
||||
@State private var t1: String = ""
|
||||
@State private var t2: String = ""
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
HStack() {
|
||||
Text("Last: \(72398)")
|
||||
Divider()
|
||||
TextField("Odometer", text: $t1)
|
||||
|
||||
}
|
||||
|
||||
HStack {
|
||||
TextField("Cost/L", text: $t1)
|
||||
Divider()
|
||||
TextField("Litres", text: $t1)
|
||||
Divider()
|
||||
TextField("Total Cost", text: $t1)
|
||||
}
|
||||
|
||||
TextField("Fuel Type", text: $t1)
|
||||
}
|
||||
.navigationTitle("New Entry")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NavigationView {
|
||||
Text("s")
|
||||
.sheet(isPresented: Binding(get: {true}, set: {_ in})) {
|
||||
AddEntryView()
|
||||
.presentationDetents([.medium])
|
||||
.presentationCornerRadius(20)
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ import SwiftData
|
||||
struct ContentView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query private var entries: [Entry]
|
||||
|
||||
@State private var addEntry = false
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
@ -19,11 +21,20 @@ struct ContentView: View {
|
||||
Text("Entry: \(e.odo)")
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $addEntry) {
|
||||
AddEntryView()
|
||||
.presentationDetents([.medium])
|
||||
.presentationCornerRadius(20)
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
EditButton()
|
||||
ToolbarItem(placement: .bottomBar) {
|
||||
Text("")
|
||||
}
|
||||
ToolbarItem {
|
||||
ToolbarItem(placement: .status) {
|
||||
Text("Placeholder")
|
||||
.frame(alignment: .center)
|
||||
}
|
||||
ToolbarItem(placement: .bottomBar) {
|
||||
Button(action: addItem) {
|
||||
Label("Add Item", systemImage: "plus")
|
||||
}
|
||||
@ -35,11 +46,12 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
private func addItem() {
|
||||
withAnimation {
|
||||
let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
||||
modelContext.insert(newItem)
|
||||
try? modelContext.save()
|
||||
}
|
||||
addEntry.toggle()
|
||||
// withAnimation {
|
||||
// let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
||||
// modelContext.insert(newItem)
|
||||
// try? modelContext.save()
|
||||
// }
|
||||
}
|
||||
|
||||
private func deleteItems(offsets: IndexSet) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user