Compare commits
2 Commits
078719ef2b
...
953a064de6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
953a064de6 | ||
![]() |
27adc0bc5a |
66
gastrack/AddEntryView.swift
Normal file
66
gastrack/AddEntryView.swift
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// 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 = ""
|
||||
|
||||
@State private var Odometer = ""
|
||||
@State private var CostPerLitre = ""
|
||||
@State private var Litres = ""
|
||||
@State private var TotalCost = ""
|
||||
@State private var FuelType = ""
|
||||
@State private var Location = ""
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
HStack() {
|
||||
Text("Last: \(72398)")
|
||||
Divider()
|
||||
TextField("Odometer", text: $Odometer)
|
||||
|
||||
}
|
||||
|
||||
HStack {
|
||||
TextField("Cost/L", text: $CostPerLitre)
|
||||
Divider()
|
||||
TextField("Litres", text: $Litres)
|
||||
Divider()
|
||||
TextField("Total Cost", text: $TotalCost)
|
||||
}
|
||||
|
||||
TextField("Fuel Type", text: $FuelType)
|
||||
TextField("Location", text: $Location)
|
||||
}
|
||||
.navigationTitle("New Entry")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") {}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Confirm") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NavigationView {
|
||||
Text("s")
|
||||
.sheet(isPresented: Binding(get: {true}, set: {_ in})) {
|
||||
AddEntryView()
|
||||
.presentationDetents([.medium])
|
||||
.presentationCornerRadius(20)
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ struct ContentView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query private var entries: [Entry]
|
||||
|
||||
@State private var addEntry = false
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List {
|
||||
@ -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