70 lines
1.8 KiB
Swift
70 lines
1.8 KiB
Swift
//
|
|
// ContentView.swift
|
|
// gastrack
|
|
//
|
|
// Created by Pradyun Setti on 23/02/2025.
|
|
//
|
|
|
|
import SwiftUI
|
|
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 {
|
|
List {
|
|
ForEach(entries) { e in
|
|
Text("Entry: \(e.odo)")
|
|
}
|
|
}
|
|
.sheet(isPresented: $addEntry) {
|
|
AddEntryView()
|
|
.presentationDetents([.medium])
|
|
.presentationCornerRadius(20)
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .bottomBar) {
|
|
Text("")
|
|
}
|
|
ToolbarItem(placement: .status) {
|
|
Text("Placeholder")
|
|
.frame(alignment: .center)
|
|
}
|
|
ToolbarItem(placement: .bottomBar) {
|
|
Button(action: addItem) {
|
|
Label("Add Item", systemImage: "plus")
|
|
}
|
|
}
|
|
}
|
|
} detail: {
|
|
Text("Select an item")
|
|
}
|
|
}
|
|
|
|
private func addItem() {
|
|
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) {
|
|
withAnimation {
|
|
for index in offsets {
|
|
modelContext.delete(entries[index])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ContentView()
|
|
.modelContainer(for: Entry.self, inMemory: true)
|
|
}
|