5 // Created by Ruben Beltran del Rio on 2/1/21.
11 struct MapDetailView: View {
12 @Environment(\.managedObjectContext) private var viewContext
13 @Environment(\.colorScheme) var colorScheme
15 @EnvironmentObject var store: AppStore
17 @ObservedObject var map: Map
19 private var mapColor: MapColor {
20 MapColor.colorForScheme(colorScheme)
23 private var title: Binding<String> {
25 get: { map.title ?? "" },
32 private var content: Binding<String> {
34 get: { map.content ?? "" },
49 try? viewContext.save()
51 ).font(.title2).textFieldStyle(PlainTextFieldStyle()).padding(.vertical, 4.0).padding(
53 Button(action: saveText) {
54 Image(systemName: "doc.text")
55 }.padding(.vertical, 4.0).padding(.leading, 4.0)
56 Button(action: saveImage) {
57 Image(systemName: "photo")
58 }.padding(.vertical, 4.0).padding(.leading, 4.0).padding(.trailing, 8.0)
62 ZStack(alignment: .topLeading) {
63 MapTextEditor(text: content, colorScheme: colorScheme).onChange(of: map.content) { _ in
64 try? viewContext.save()
66 .background(mapColor.background)
67 .foregroundColor(mapColor.foreground)
68 .frame(minHeight: 96.0)
69 }.padding(.top, 8.0).padding(.leading, 8.0).background(mapColor.background).cornerRadius(
71 }.padding(.horizontal, 8.0)
72 ScrollView([.horizontal, .vertical]) {
74 content: content.wrappedValue, evolution: Stage.stages(store.state.selectedEvolution))
75 }.background(mapColor.background)
82 private func saveText() {
83 store.send(.exportMapAsText(map: map))
86 private func saveImage() {
87 store.send(.exportMapAsImage(map: map))
91 struct MapDetailView_Previews: PreviewProvider {
92 static var previews: some View {
93 MapDetailView(map: Map()).environment(
94 \.managedObjectContext, PersistenceController.preview.container.viewContext)