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
|
@Environment(\.modelContext) private var modelContext
|
||||||
@Query private var entries: [Entry]
|
@Query private var entries: [Entry]
|
||||||
|
|
||||||
|
@State private var addEntry = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
List {
|
List {
|
||||||
@ -19,11 +21,20 @@ struct ContentView: View {
|
|||||||
Text("Entry: \(e.odo)")
|
Text("Entry: \(e.odo)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $addEntry) {
|
||||||
|
AddEntryView()
|
||||||
|
.presentationDetents([.medium])
|
||||||
|
.presentationCornerRadius(20)
|
||||||
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .bottomBar) {
|
||||||
EditButton()
|
Text("")
|
||||||
}
|
}
|
||||||
ToolbarItem {
|
ToolbarItem(placement: .status) {
|
||||||
|
Text("Placeholder")
|
||||||
|
.frame(alignment: .center)
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .bottomBar) {
|
||||||
Button(action: addItem) {
|
Button(action: addItem) {
|
||||||
Label("Add Item", systemImage: "plus")
|
Label("Add Item", systemImage: "plus")
|
||||||
}
|
}
|
||||||
@ -35,11 +46,12 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func addItem() {
|
private func addItem() {
|
||||||
withAnimation {
|
addEntry.toggle()
|
||||||
let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
// withAnimation {
|
||||||
modelContext.insert(newItem)
|
// let newItem = Entry(odo: 75239, cost: 92.19, quantity: 36.34, fuelType: "91")
|
||||||
try? modelContext.save()
|
// modelContext.insert(newItem)
|
||||||
}
|
// try? modelContext.save()
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func deleteItems(offsets: IndexSet) {
|
private func deleteItems(offsets: IndexSet) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user