]> git.r.bdr.sh - rbdr/map/commitdiff
Make delete a context action
authorRuben Beltran del Rio <redacted>
Thu, 4 Feb 2021 23:23:05 +0000 (00:23 +0100)
committerRuben Beltran del Rio <redacted>
Thu, 4 Feb 2021 23:23:05 +0000 (00:23 +0100)
Map/State/AppState.swift
Map/Views/ContentView.swift

index cbc9ba6223c4329ca107dea8b89205d5c8f75001..f0620512c342a062761979b8f545e90e0b96a544 100644 (file)
@@ -4,13 +4,13 @@ import SwiftUI
 
 struct AppState {
   var selectedEvolution: StageType = .general
 
 struct AppState {
   var selectedEvolution: StageType = .general
-  var mapBeingDeleted: Map? = nil
 }
 
 enum AppAction {
   case selectEvolution(evolution: StageType)
   case exportMapAsImage(map: Map)
   case exportMapAsText(map: Map)
 }
 
 enum AppAction {
   case selectEvolution(evolution: StageType)
   case exportMapAsImage(map: Map)
   case exportMapAsText(map: Map)
+  case deleteMap(map: Map)
 }
 
 func appStateReducer(state: inout AppState, action: AppAction) {
 }
 
 func appStateReducer(state: inout AppState, action: AppAction) {
@@ -91,6 +91,11 @@ func appStateReducer(state: inout AppState, action: AppAction) {
         print("Cancel")
       }
     }
         print("Cancel")
       }
     }
+  case .deleteMap(map: let map):
+    let context = PersistenceController.shared.container.viewContext
+    context.delete(map)
+
+    try? context.save()
   }
 }
 
   }
 }
 
index cf1f145ab46c3d840d94fcfd65750269f8c71244..f439026249988f669b78b118f7d9b4116db2ed10 100644 (file)
@@ -37,6 +37,11 @@ struct ContentView: View {
                 .foregroundColor(Color.black)
                 .cornerRadius(2.0)
             }.padding(.leading, 8.0)
                 .foregroundColor(Color.black)
                 .cornerRadius(2.0)
             }.padding(.leading, 8.0)
+          }.contextMenu {
+            Button(action: { store.send(.deleteMap(map: map))}) {
+              Image(systemName: "trash")
+              Text("Delete")
+            }
           }
         }
         .onDelete(perform: deleteMaps)
           }
         }
         .onDelete(perform: deleteMaps)
@@ -51,6 +56,7 @@ struct ContentView: View {
             }
           }
         }
             }
           }
         }
+        DefaultMapView()
     }
   }
 
     }
   }