]> git.r.bdr.sh - rbdr/map/blobdiff - Map/State/AppState.swift
Fix performance and undo
[rbdr/map] / Map / State / AppState.swift
index cbc9ba6223c4329ca107dea8b89205d5c8f75001..c261725fbae1eb22c893f9d8c886489ab0febab5 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) {
@@ -38,7 +38,8 @@ func appStateReducer(state: inout AppState, action: AppAction) {
     window.makeKeyAndOrderFront(nil)
 
     let renderView = MapRenderView(
-      content: map.content ?? "", evolution: Stage.stages(state.selectedEvolution))
+      content: Binding.constant(map.content ?? ""),
+      evolution: Binding.constant(Stage.stages(state.selectedEvolution)))
 
     let view = NSHostingView(rootView: renderView)
     window.contentView = view
@@ -91,6 +92,11 @@ func appStateReducer(state: inout AppState, action: AppAction) {
         print("Cancel")
       }
     }
+  case .deleteMap(let map):
+    let context = PersistenceController.shared.container.viewContext
+    context.delete(map)
+
+    try? context.save()
   }
 }