]> git.r.bdr.sh - rbdr/map/blobdiff - Map/Views/ContentView.swift
Fix performance and undo
[rbdr/map] / Map / Views / ContentView.swift
index 4f55c27c0680623d2a9be6724fe18c5d64fd0c79..534c14c41761453e6666776ae58100d51943b9ef 100644 (file)
@@ -11,6 +11,8 @@ import SwiftUI
 struct ContentView: View {
   @Environment(\.managedObjectContext) private var viewContext
 
+  @EnvironmentObject var store: AppStore
+
   @FetchRequest(
     sortDescriptors: [NSSortDescriptor(keyPath: \Map.createdAt, ascending: true)],
     animation: .default)
@@ -23,7 +25,9 @@ struct ContentView: View {
           DefaultMapView()
         }
         ForEach(maps) { map in
-          NavigationLink(destination: MapDetailView(map: map)) {
+          NavigationLink(
+            destination: MapDetailView(map: map, title: map.title ?? "", content: map.content ?? "")
+          ) {
             HStack {
               Text(map.title ?? "Untitled Map")
               Spacer()
@@ -35,6 +39,13 @@ struct ContentView: View {
                 .foregroundColor(Color.black)
                 .cornerRadius(2.0)
             }.padding(.leading, 8.0)
+          }.contextMenu {
+            Button(
+              action: { store.send(.deleteMap(map: map)) },
+              label: {
+                Image(systemName: "trash")
+                Text("Delete")
+              })
           }
         }
         .onDelete(perform: deleteMaps)
@@ -49,6 +60,7 @@ struct ContentView: View {
             }
           }
         }
+      DefaultMapView()
     }
   }