X-Git-Url: https://git.r.bdr.sh/rbdr/map/blobdiff_plain/5e8ff4850c4827125fe12788dd5b153c4f636f48..75a0e4509a70055851b085f3f7293ae1cf48164c:/Map/State/AppState.swift?ds=inline diff --git a/Map/State/AppState.swift b/Map/State/AppState.swift index e10efea..c261725 100644 --- a/Map/State/AppState.swift +++ b/Map/State/AppState.swift @@ -3,31 +3,24 @@ import Foundation import SwiftUI struct AppState { - var selectedMap: Map? = nil - var mapBeingDeleted: Map? = nil + var selectedEvolution: StageType = .general } 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) + case deleteMap(map: Map) } 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,9 @@ 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: Binding.constant(map.content ?? ""), + evolution: Binding.constant(Stage.stages(state.selectedEvolution))) let view = NSHostingView(rootView: renderView) window.contentView = view @@ -97,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() } }