5 // Created by Ruben Beltran del Rio on 2/1/21.
13 let currentTimePublisher = Timer.TimerPublisher(interval: 1, runLoop: .main, mode: .default)
14 let cancellable: AnyCancellable?
17 self.cancellable = currentTimePublisher.connect() as? AnyCancellable
21 self.cancellable?.cancel()
25 let timer = SaveTimer()
27 struct MapDetailView: View {
28 @Environment(\.managedObjectContext) private var viewContext
29 @Environment(\.colorScheme) var colorScheme
31 @EnvironmentObject var store: AppStore
33 @ObservedObject var map: Map
35 private var mapColor: MapColor {
36 MapColor.colorForScheme(colorScheme)
39 @State var title: String
40 @State var content: String
49 ).font(.title2).textFieldStyle(PlainTextFieldStyle()).padding(.vertical, 4.0).padding(
51 Button(action: saveText) {
52 Image(systemName: "doc.text")
53 }.padding(.vertical, 4.0).padding(.leading, 4.0)
54 Button(action: saveImage) {
55 Image(systemName: "photo")
56 }.padding(.vertical, 4.0).padding(.leading, 4.0).padding(.trailing, 8.0)
60 ZStack(alignment: .topLeading) {
61 MapTextEditor(text: $content, colorScheme: colorScheme)
62 .background(mapColor.background)
63 .foregroundColor(mapColor.foreground)
64 .frame(minHeight: 96.0)
65 }.padding(.top, 8.0).padding(.leading, 8.0).background(mapColor.background).cornerRadius(
67 }.padding(.horizontal, 8.0)
68 ScrollView([.horizontal, .vertical]) {
70 content: content, evolution: Stage.stages(store.state.selectedEvolution),
71 colorScheme: colorScheme)
72 }.background(mapColor.background)
73 }.onReceive(timer.currentTimePublisher) { _ in
83 private func saveModel() {
86 try? viewContext.save()
89 private func saveText() {
90 store.send(.exportMapAsText(map: map))
93 private func saveImage() {
94 store.send(.exportMapAsImage(map: map))
98 struct MapDetailView_Previews: PreviewProvider {
99 static var previews: some View {
100 MapDetailView(map: Map(), title: "", content: "").environment(
101 \.managedObjectContext, PersistenceController.preview.container.viewContext)