Skip to content

Commit 5dc75a3

Browse files
authored
Merge pull request #246 from TaskarCenterAtUW/fix-ui-known-issues
Fix UI known issues
2 parents f4ec348 + c1e7a8c commit 5dc75a3

File tree

6 files changed

+96
-33
lines changed

6 files changed

+96
-33
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/UserProfile/View/UserProfileView.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ struct UserProfileView: View {
1818
VStack {
1919
Text("My Profile")
2020
.font(.custom("Lato-Bold", size: 25))
21-
HStack {
21+
.padding(.bottom, 50)
22+
HStack(alignment: .center, spacing: 16) {
2223
profileImage
23-
VStack (alignment: .leading,spacing: 0){
24+
25+
VStack(alignment: .leading, spacing: 4) {
2426
Text(userFullName())
2527
.font(.custom("Lato-Bold", size: 20))
2628
Text(viewModel.user?.email ?? "")
2729
.font(.custom("Lato-Regular", size: 18))
2830
}
31+
2932
Spacer()
3033
}
3134
.padding([.bottom], 200)
@@ -51,16 +54,12 @@ struct UserProfileView: View {
5154
}
5255

5356
private var profileImage: some View {
54-
VStack {
55-
Image(systemName: "person.circle.fill")
56-
.resizable()
57-
.frame(width: 50, height: 50, alignment: .center)
58-
.cornerRadius(60)
59-
}
60-
.padding([.top], 50)
61-
62-
57+
Image(systemName: "person.circle.fill")
58+
.resizable()
59+
.frame(width: 50, height: 50)
60+
.clipShape(Circle())
6361
}
62+
6463

6564
private var logOutButton: some View {
6665
Button {

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/Components/QuestOptions.swift

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,19 @@ struct QuestOptions: View {
8989
LazyVGrid(columns: columns, spacing: 16) {
9090
ForEach(options, id: \.id) { option in
9191
Button(action: {
92-
selectedAnswerId = option.id
93-
onChoiceSelected(option)
92+
if selectedAnswerId == option.id {
93+
// Deselect
94+
selectedAnswerId = nil
95+
currentAnswer = nil
96+
selectedImageURL = nil
97+
selectedImageText = nil
98+
// Don't call onChoiceSelected if you want to ignore blank assignment
99+
} else {
100+
// Select
101+
selectedAnswerId = option.id
102+
currentAnswer = option.value
103+
onChoiceSelected(option)
104+
}
94105
}) {
95106
VStack(spacing: 8) {
96107
if let imageUrl = option.imageURL, !imageUrl.isEmpty {
@@ -104,7 +115,6 @@ struct QuestOptions: View {
104115
.onLongPressGesture {
105116
selectedImageURL = imageUrl
106117
selectedImageText = option.choiceText
107-
108118
}
109119
} else {
110120
ZStack {
@@ -113,18 +123,17 @@ struct QuestOptions: View {
113123
.scaledToFill()
114124
.frame(width: 100, height: 100)
115125
.clipped()
116-
//add grey border to image
117126
.overlay(
118127
RoundedRectangle(cornerRadius: 8)
119128
.stroke(Color.gray, lineWidth: 1)
120129
)
121130

122131
ZStack {
123132
let strokeOffsets: [(CGFloat, CGFloat)] = [
124-
(-1, -1), (1, -1),
125-
(-1, 1), (1, 1),
126-
(0, -1), (0, 1),
127-
(-1, 0), (1, 0)
133+
(-1, -1), (1, -1),
134+
(-1, 1), (1, 1),
135+
(0, -1), (0, 1),
136+
(-1, 0), (1, 0)
128137
]
129138

130139
ForEach(0..<strokeOffsets.count, id: \.self) { i in
@@ -141,20 +150,22 @@ struct QuestOptions: View {
141150
.shadow(color: Color.black.opacity(0.7), radius: 4, x: 0, y: 2)
142151
}
143152
}
144-
145153
}
146154
}
147155
}
148-
.overlay(
149-
RoundedRectangle(cornerRadius: 8)
150-
.stroke(currentAnswer == option.value ? Color.blue : Color.clear, lineWidth: 3)
151-
)
156+
.overlay(
157+
RoundedRectangle(cornerRadius: 8)
158+
.stroke(currentAnswer == option.value ? Color.blue : Color.clear, lineWidth: 3)
159+
)
160+
152161
}
153162
}
163+
154164

155165
// Place follow-up button separately after the grid
156-
if let selected = options.first(where: { $0.id == selectedAnswerId }),
157-
selected.choiceFollowUp != nil {
166+
if let selected = selectedAnswerId.flatMap({ id in
167+
options.first(where: { $0.id == id && $0.choiceFollowUp != nil })
168+
}) {
158169
Button(action: {
159170
uploadPhoto(true)
160171
}) {

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)