]> git.r.bdr.sh - rbdr/map/blobdiff - Map/State/AppState.swift
Make delete a context action
[rbdr/map] / Map / State / AppState.swift
index cbc9ba6223c4329ca107dea8b89205d5c8f75001..f0620512c342a062761979b8f545e90e0b96a544 100644 (file)
@@ -4,13 +4,13 @@ import SwiftUI
 
 struct AppState {
   var selectedEvolution: StageType = .general
-  var mapBeingDeleted: Map? = nil
 }
 
 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) {
@@ -91,6 +91,11 @@ func appStateReducer(state: inout AppState, action: AppAction) {
         print("Cancel")
       }
     }
+  case .deleteMap(map: let map):
+    let context = PersistenceController.shared.container.viewContext
+    context.delete(map)
+
+    try? context.save()
   }
 }