aboutsummaryrefslogtreecommitdiff
path: root/Map/Views/MapDetail.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2021-02-03 23:53:12 +0100
committerRuben Beltran del Rio <ruben@unlimited.pizza>2021-02-03 23:53:12 +0100
commit5e8ff4850c4827125fe12788dd5b153c4f636f48 (patch)
treef37c90338f33e7ddc84cc855a20dca1ca503476e /Map/Views/MapDetail.swift
parent1b85f723b48d38cf345bb9a4f3fd01aa6039b50b (diff)
Add code for first release
Diffstat (limited to 'Map/Views/MapDetail.swift')
-rw-r--r--Map/Views/MapDetail.swift101
1 files changed, 101 insertions, 0 deletions
diff --git a/Map/Views/MapDetail.swift b/Map/Views/MapDetail.swift
new file mode 100644
index 0000000..a8ea3d1
--- /dev/null
+++ b/Map/Views/MapDetail.swift
@@ -0,0 +1,101 @@
+//
+// ContentView.swift
+// Map
+//
+// Created by Ruben Beltran del Rio on 2/1/21.
+//
+
+import CoreData
+import SwiftUI
+
+struct MapDetailView: View {
+ @Environment(\.managedObjectContext) private var viewContext
+ @Environment(\.colorScheme) var colorScheme
+
+ @EnvironmentObject var store: AppStore
+
+ @ObservedObject var map: Map
+
+ private var mapColor: MapColor {
+ MapColor.colorForScheme(colorScheme)
+ }
+
+ private var title: Binding<String> {
+ Binding(
+ get: { map.title ?? "" },
+ set: { title in
+ map.title = title
+ }
+ )
+ }
+
+ private var content: Binding<String> {
+ Binding(
+ get: { map.content ?? "" },
+ set: { content in
+ map.content = content
+ }
+ )
+ }
+
+ @State private var selectedEvolution = StageType.general
+
+ var body: some View {
+ if map.uuid != nil {
+ VSplitView {
+ VStack {
+ HStack {
+ TextField(
+ "Title", text: title,
+ onCommit: {
+ try? viewContext.save()
+ }
+ ).font(.title2).textFieldStyle(PlainTextFieldStyle()).padding(.vertical, 4.0).padding(
+ .leading, 4.0)
+ Button(action: saveText) {
+ Image(systemName: "doc.text")
+ }.padding(.vertical, 4.0).padding(.leading, 4.0)
+ Button(action: saveImage) {
+ Image(systemName: "photo")
+ }.padding(.vertical, 4.0).padding(.leading, 4.0).padding(.trailing, 8.0)
+ }
+ Picker("Evolution", selection: $selectedEvolution) {
+ ForEach(StageType.allCases) { stage in
+ Text(Stage.title(stage)).tag(stage).padding(4.0)
+ }
+ }.padding(.horizontal, 8.0).padding(.vertical, 4.0)
+
+ ZStack(alignment: .topLeading) {
+ MapTextEditor(text: content).onChange(of: map.content) { _ in
+ try? viewContext.save()
+ }
+ .background(mapColor.background)
+ .foregroundColor(mapColor.foreground)
+ .frame(minHeight: 96.0)
+ }.padding(.top, 8.0).padding(.leading, 8.0).background(mapColor.background).cornerRadius(
+ 5.0)
+ }.padding(.horizontal, 8.0)
+ ScrollView([.horizontal, .vertical]) {
+ MapRenderView(map: map, evolution: Stage.stages(selectedEvolution))
+ }.background(mapColor.background)
+ }
+ } else {
+ DefaultMapView()
+ }
+ }
+
+ private func saveText() {
+ store.send(.exportMapAsText(map: map))
+ }
+
+ private func saveImage() {
+ store.send(.exportMapAsImage(map: map, evolution: selectedEvolution))
+ }
+}
+
+struct MapDetailView_Previews: PreviewProvider {
+ static var previews: some View {
+ MapDetailView(map: Map()).environment(
+ \.managedObjectContext, PersistenceController.preview.container.viewContext)
+ }
+}