diff --git a/gastrack/AddEntryView.swift b/gastrack/AddEntryView.swift new file mode 100644 index 0000000..9183bb7 --- /dev/null +++ b/gastrack/AddEntryView.swift @@ -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) + } + } +} diff --git a/gastrack/ContentView.swift b/gastrack/ContentView.swift index 11b2f54..1d5ddca 100644 --- a/gastrack/ContentView.swift +++ b/gastrack/ContentView.swift @@ -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) {