aboutsummaryrefslogtreecommitdiff
path: root/Captura/PreferencesWindow.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-07-24 23:32:41 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-07-24 23:32:41 +0200
commit242203487a56df9edd1aa6eceb106461ef62483c (patch)
treefb055bd148b9586e656f59f8e9297d3d1865f234 /Captura/PreferencesWindow.swift
parentbf063563436a12c003968ae4d00991f49fac226c (diff)
Add drawing
Diffstat (limited to 'Captura/PreferencesWindow.swift')
-rw-r--r--Captura/PreferencesWindow.swift50
1 files changed, 50 insertions, 0 deletions
diff --git a/Captura/PreferencesWindow.swift b/Captura/PreferencesWindow.swift
new file mode 100644
index 0000000..fdb3a6c
--- /dev/null
+++ b/Captura/PreferencesWindow.swift
@@ -0,0 +1,50 @@
+import SwiftUI
+import SwiftData
+
+struct PreferencesWindow: View {
+ @Environment(\.modelContext) private var modelContext
+ @Query private var items: [Item]
+
+ var body: some View {
+ NavigationView {
+ List {
+ ForEach(items) { item in
+ NavigationLink {
+ Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
+ } label: {
+ Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
+ }
+ }
+ .onDelete(perform: deleteItems)
+ }
+ .toolbar {
+ ToolbarItem {
+ Button(action: addItem) {
+ Label("Add Item", systemImage: "plus")
+ }
+ }
+ }
+ Text("Select an item")
+ }
+ }
+
+ private func addItem() {
+ withAnimation {
+ let newItem = Item(timestamp: Date())
+ modelContext.insert(newItem)
+ }
+ }
+
+ private func deleteItems(offsets: IndexSet) {
+ withAnimation {
+ for index in offsets {
+ modelContext.delete(items[index])
+ }
+ }
+ }
+}
+
+#Preview {
+ PreferencesWindow()
+ .modelContainer(for: Item.self, inMemory: true)
+}