Skip to content

Commit 1c4e80b

Browse files
author
Achyut Kumar M
committed
note
1 parent f4ec348 commit 1c4e80b

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct CustomMap: UIViewRepresentable {
3838

3939
@Binding var tappedCoordinate: CLLocationCoordinate2D?
4040

41+
@Binding var annotationCoordinate: CLLocationCoordinate2D?
42+
4143
var shadowOverlay: ShadowOverlay
4244

4345
// Creates and configures the UIView
@@ -364,6 +366,7 @@ struct CustomMap: UIViewRepresentable {
364366
}
365367

366368
private func selectedAnAnnotation(selectedQuest: DisplayUnitAnnotation) {
369+
parent.annotationCoordinate = selectedQuest.coordinate
367370
parent.selectedQuest = selectedQuest.displayUnit
368371
parent.isPresented = true
369372
var contextualString = ""

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct MapView: View {
3434

3535
@State private var tappedCoordinate: CLLocationCoordinate2D? = nil
3636

37+
@State private var annotationCoordinate: CLLocationCoordinate2D? = nil
38+
3739
@State private var showMapLongPressedSheet = false
3840

3941
@State private var showAddFeatureSheet = false
@@ -83,7 +85,7 @@ struct MapView: View {
8385
print(contextualInfo)
8486
selectedDetent = .fraction(0.8)
8587
self.setContextualInfo(contextualinfo: contextualInfo)
86-
}, useBingMaps: $useBingMaps, tappedCoordinate: $tappedCoordinate, shadowOverlay: shadowOverlay)
88+
}, useBingMaps: $useBingMaps, tappedCoordinate: $tappedCoordinate, annotationCoordinate: $annotationCoordinate, shadowOverlay: shadowOverlay)
8789
.onChange(of: tappedCoordinate) { _ in
8890
showMapLongPressedSheet = tappedCoordinate != nil
8991
}
@@ -366,10 +368,7 @@ struct MapView: View {
366368
}
367369

368370
.sheet(isPresented: $isPresented, content: {
369-
let selectedQuest = self.viewModel.getSelectedQuest()
370-
CustomSheetView {
371-
selectedQuest?.parent?.form
372-
}
371+
QuestSheetView(viewModel: viewModel, annotationCoordinate: annotationCoordinate)
373372
.onAppear {
374373
shouldShowPolyline = true
375374
}
@@ -435,6 +434,32 @@ struct MapView: View {
435434
}
436435
}
437436

437+
struct QuestSheetView: View {
438+
@ObservedObject var viewModel: MapViewModel
439+
let annotationCoordinate: CLLocationCoordinate2D?
440+
441+
init(viewModel: MapViewModel, annotationCoordinate: CLLocationCoordinate2D?) {
442+
self.viewModel = viewModel
443+
self.annotationCoordinate = annotationCoordinate
444+
445+
if let quest = viewModel.getSelectedQuest(),
446+
let longQuest = quest.parent as? LongElementQuest {
447+
longQuest.annotationCoordinate = annotationCoordinate
448+
}
449+
}
450+
451+
var body: some View {
452+
Group {
453+
if let selectedQuest = viewModel.getSelectedQuest() {
454+
CustomSheetView {
455+
selectedQuest.parent?.form
456+
}
457+
} else {
458+
EmptyView()
459+
}
460+
}
461+
}
462+
}
438463

439464
public class MapViewPublisher: ObservableObject {
440465
public let dismissSheet = PassthroughSubject<SheetDismissalScenario, Never>()

GoInfoGame/GoInfoGame/quests/LongQuests/Classes/LongElementQuest.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99
import osmparser
1010
import SwiftUI
11+
import CoreLocation
1112

1213
class LongElementQuest: QuestBase, Quest {
1314

@@ -75,6 +76,20 @@ class LongElementQuest: QuestBase, Quest {
7576

7677
var questAnswersSelected: (([String:String]) -> Void)? = nil
7778

79+
var annotationCoordinate: CLLocationCoordinate2D? {
80+
didSet {
81+
updateForm()
82+
}
83+
}
84+
85+
private func updateForm() {
86+
self.internalForm = LongForm(
87+
elementName: elementType, questID: questId, query: _internalQueryString, action: { [self] tags in
88+
self.questAnswersSelected?(tags)
89+
}, coordinate: annotationCoordinate ?? CLLocationCoordinate2D(latitude: 0, longitude: 0)
90+
)
91+
}
92+
7893
init(questId: String, questQuery:String, elementType: String) {
7994
super.init()
8095
self._internalQueryString = questQuery

GoInfoGame/GoInfoGame/quests/LongQuests/View/LongForm.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import CoreLocation
910

1011

1112
struct LongForm: View, QuestForm {
@@ -24,6 +25,8 @@ struct LongForm: View, QuestForm {
2425

2526
typealias AnswerClass = [String:String]
2627

28+
var coordinate: CLLocationCoordinate2D?
29+
2730
@Environment(\.presentationMode) var presentationMode
2831

2932
@State private var showSubmitAlert = false
@@ -268,10 +271,17 @@ struct LongForm: View, QuestForm {
268271
}
269272

270273
func submitNote() async throws {
271-
print("Note to be submitted: \(noteText)")
274+
print("Note to be submitted: \(noteText.htmlEscape())")
272275

273276
do {
274-
let notesResult = try await noteViewModel.createNote(note: noteText, lat: 0.0, long: 0.0)
277+
//gt lat long from coordinate
278+
let lat = coordinate?.latitude ?? 0.0
279+
let long = coordinate?.longitude ?? 0.0
280+
print("Latitude: \(lat), Longitude: \(long)")
281+
282+
let noteToBeSubmitted = noteText.htmlEscape()
283+
284+
let notesResult = try await noteViewModel.createNote(note: noteToBeSubmitted, lat: lat, long: long)
275285

276286
if notesResult {
277287
print("Notes composed successfully")

0 commit comments

Comments
 (0)