]> git.r.bdr.sh - rbdr/map/blobdiff - Map/State/AppState.swift
Release 1.1.0
[rbdr/map] / Map / State / AppState.swift
index e10efea00ab5ec1eeed8989fae02345d436c3789..cbc9ba6223c4329ca107dea8b89205d5c8f75001 100644 (file)
@@ -3,14 +3,13 @@ import Foundation
 import SwiftUI
 
 struct AppState {
-  var selectedMap: Map? = nil
+  var selectedEvolution: StageType = .general
   var mapBeingDeleted: Map? = nil
 }
 
 enum AppAction {
-  case selectMap(map: Map?)
-  case deleteMap(map: Map)
-  case exportMapAsImage(map: Map, evolution: StageType)
+  case selectEvolution(evolution: StageType)
+  case exportMapAsImage(map: Map)
   case exportMapAsText(map: Map)
 }
 
@@ -18,16 +17,10 @@ func appStateReducer(state: inout AppState, action: AppAction) {
 
   switch action {
 
-  case .selectMap(let map):
-    state.selectedMap = map
+  case .selectEvolution(let evolution):
+    state.selectedEvolution = evolution
 
-  case .deleteMap(let map):
-    let context = PersistenceController.shared.container.viewContext
-
-    context.delete(map)
-    try? context.save()
-
-  case .exportMapAsImage(let map, let evolution):
+  case .exportMapAsImage(let map):
     let window = NSWindow(
       contentRect: .init(
         origin: .zero,
@@ -44,7 +37,8 @@ func appStateReducer(state: inout AppState, action: AppAction) {
     window.isMovableByWindowBackground = true
     window.makeKeyAndOrderFront(nil)
 
-    let renderView = MapRenderView(map: map, evolution: Stage.stages(evolution))
+    let renderView = MapRenderView(
+      content: map.content ?? "", evolution: Stage.stages(state.selectedEvolution))
 
     let view = NSHostingView(rootView: renderView)
     window.contentView = view