aboutsummaryrefslogtreecommitdiff
path: root/Map/Views/MapDetail.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-05-07 15:22:54 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-05-07 15:22:54 +0200
commitfdb4633d3e9158e457d57e820df6e1efb4df39c2 (patch)
tree176cad99cb9befc0a65a7af02561019e811814de /Map/Views/MapDetail.swift
parent75a0e4509a70055851b085f3f7293ae1cf48164c (diff)
Update to support notes + new style2.0.0
Diffstat (limited to 'Map/Views/MapDetail.swift')
-rw-r--r--Map/Views/MapDetail.swift103
1 files changed, 0 insertions, 103 deletions
diff --git a/Map/Views/MapDetail.swift b/Map/Views/MapDetail.swift
deleted file mode 100644
index bebe3a1..0000000
--- a/Map/Views/MapDetail.swift
+++ /dev/null
@@ -1,103 +0,0 @@
-//
-// ContentView.swift
-// Map
-//
-// Created by Ruben Beltran del Rio on 2/1/21.
-//
-
-import Combine
-import CoreData
-import SwiftUI
-
-class SaveTimer {
- let currentTimePublisher = Timer.TimerPublisher(interval: 1, runLoop: .main, mode: .default)
- let cancellable: AnyCancellable?
-
- init() {
- self.cancellable = currentTimePublisher.connect() as? AnyCancellable
- }
-
- deinit {
- self.cancellable?.cancel()
- }
-}
-
-let timer = SaveTimer()
-
-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)
- }
-
- @State var title: String
- @State var content: String
-
- var body: some View {
- if map.uuid != nil {
- VSplitView {
- VStack {
- HStack {
- TextField(
- "Title", text: $title
- ).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)
- }
- EvolutionPicker()
-
- ZStack(alignment: .topLeading) {
- MapTextEditor(text: $content, colorScheme: colorScheme)
- .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]) {
- SlowMapRender(
- content: content, evolution: Stage.stages(store.state.selectedEvolution),
- colorScheme: colorScheme)
- }.background(mapColor.background)
- }.onReceive(timer.currentTimePublisher) { _ in
- saveModel()
- }.onDisappear {
- saveModel()
- }
- } else {
- DefaultMapView()
- }
- }
-
- private func saveModel() {
- map.content = content
- map.title = title
- try? viewContext.save()
- }
-
- private func saveText() {
- store.send(.exportMapAsText(map: map))
- }
-
- private func saveImage() {
- store.send(.exportMapAsImage(map: map))
- }
-}
-
-struct MapDetailView_Previews: PreviewProvider {
- static var previews: some View {
- MapDetailView(map: Map(), title: "", content: "").environment(
- \.managedObjectContext, PersistenceController.preview.container.viewContext)
- }
-}