Skip to content

Commit b30e746

Browse files
authored
Merge pull request #248 from TaskarCenterAtUW/feature-switch-workspace
Switch Workspace
2 parents 88be93e + c14b81d commit b30e746

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,20 @@ struct CustomMap: UIViewRepresentable {
162162

163163
// Helper method to update the region
164164
func updateUserRegion(_ mapView: MKMapView) {
165-
// Update the region only if it hasn't been set yet
166-
if self.parent.isPresented {
167-
return
168-
} else if !isRegionSet {
165+
guard !parent.isPresented else { return }
166+
167+
let center = parent.region.center
168+
guard CLLocationCoordinate2DIsValid(center),
169+
!(center.latitude == 0 && center.longitude == 0) else { return }
170+
171+
if parent.selectedAnnotations.isEmpty && !isRegionSet {
169172
mapView.setRegion(parent.region, animated: true)
170173
isRegionSet = true
171174
}
175+
172176
}
177+
178+
173179

174180

175181
// To keep the selected annotation visible at the top
@@ -229,6 +235,9 @@ struct CustomMap: UIViewRepresentable {
229235
// Customizes the view for each annotation
230236
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
231237
self.mapView = mapView
238+
if annotation is MKUserLocation {
239+
return nil
240+
}
232241
if let clusterAnnotation = annotation as? MKClusterAnnotation {
233242
let identifier = "cluster"
234243
var clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct MapView: View {
252252
}
253253

254254
.sheet(isPresented: $showUserSettingsSheet) {
255-
UserSettingsView( options: OptionModel.options, onNavigate: { navigate in
255+
UserSettingsView(selectedWorkspace: selectedWorkspace?.title ?? "", options: OptionModel.options, onNavigate: { navigate in
256256
showUserSettingsSheet = false
257257
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
258258
// navigateToProfileSettings = true
@@ -280,6 +280,10 @@ struct MapView: View {
280280
let extendedVisibleRect = rect.insetBy(dx: -rect.size.width * 0.25, dy: -rect.size.height * 0.25)
281281
shadowOverlay.addVisibleRect(extendedVisibleRect)
282282

283+
case .switchWorkspace:
284+
//navigate to inital view
285+
print("Switch workspace here")
286+
switchToInitialView()
283287
}
284288
}
285289

@@ -422,6 +426,14 @@ struct MapView: View {
422426
}
423427
}
424428

429+
func switchToInitialView() {
430+
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
431+
let window = scene.windows.first {
432+
window.rootViewController = UIHostingController(rootView: InitialView())
433+
window.makeKeyAndVisible()
434+
}
435+
}
436+
425437
private func setContextualInfo(contextualinfo: String) {
426438
contextualInfo.info = contextualinfo
427439

GoInfoGame/GoInfoGame/UI/UserSettingsView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,29 @@ struct OptionModel: Identifiable, Hashable {
1818
static let options: [OptionModel] = [
1919
OptionModel(title: "User Profile", icon: "person.crop.circle.fill", destination: .profile),
2020
OptionModel(title: "Manage Quests", icon: "slider.horizontal.3", destination: .manageQuests),
21-
OptionModel(title: "Download Data", icon: "arrow.down.circle.fill", destination: .downloadData)
21+
OptionModel(title: "Download Data", icon: "arrow.down.circle.fill", destination: .downloadData),
22+
OptionModel(title: "Switch Workspace", icon: "arrow.right.arrow.left.circle.fill", destination: .switchWorkspace)
2223
]
2324
}
2425

2526
enum SettingsDestination: Hashable {
2627
case profile
2728
case manageQuests
2829
case downloadData
30+
case switchWorkspace
2931

3032
}
3133
struct UserSettingsView: View {
3234
@Environment(\.presentationMode) var presentationMode
3335

34-
36+
@State var selectedWorkspace: String = ""
3537
let options: [OptionModel]
3638
let onNavigate: (SettingsDestination) -> Void
3739

3840
var body: some View {
3941
VStack(alignment: .leading, spacing: 12) {
4042
HStack(alignment: .firstTextBaseline) {
41-
Text("")
43+
Text(selectedWorkspace)
4244

4345

4446
Spacer()

0 commit comments

Comments
 (0)