@@ -10,6 +10,7 @@ import SwiftUI
1010struct InitialView : View {
1111 @StateObject private var viewModel = InitialViewModel ( )
1212 @State private var shouldNavigateToMapView = false
13+ @State private var selectedWorkspace : Workspace ? = nil
1314 @StateObject private var locManagerDelegate = LocationManagerDelegate ( )
1415
1516 @State private var isLoading : Bool = false
@@ -48,7 +49,7 @@ struct InitialView: View {
4849 Spacer ( )
4950
5051 if viewModel. workspaces. count > 1 {
51- WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel, isLoading: $isLoading)
52+ WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel, shouldNavigateToMapView : $shouldNavigateToMapView , selectedWorkspace : $selectedWorkspace , isLoading: $isLoading)
5253 }
5354 }
5455 . padding ( )
@@ -58,6 +59,12 @@ struct InitialView: View {
5859
5960 }
6061 }
62+ . navigationDestination ( isPresented: $shouldNavigateToMapView) {
63+ if let workspace = selectedWorkspace {
64+ MapView ( selectedWorkspace: workspace)
65+ . navigationBarBackButtonHidden ( true )
66+ }
67+ }
6168 }
6269 . onAppear {
6370 isLoading = true
@@ -82,8 +89,8 @@ struct InitialView: View {
8289struct WorkspacesListView : View {
8390 let workspaces : [ Workspace ]
8491 var viewModel : InitialViewModel
85- @State private var shouldNavigateToMapView = false
86- @State private var selectedWorkspace : Workspace ?
92+ @Binding var shouldNavigateToMapView : Bool
93+ @Binding var selectedWorkspace : Workspace ?
8794
8895 @Binding var isLoading : Bool
8996
@@ -104,24 +111,21 @@ struct WorkspacesListView: View {
104111 . onAppear {
105112 viewModel. fetchLongQuestsFor ( workspaceId: " \( selectedWorkspace. id) " ) { success, errorMessage in
106113 if success {
114+ self . selectedWorkspace = selectedWorkspace
107115 let workspaceId = " \( selectedWorkspace. id) "
108116 _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
109117 DispatchQueue . main. async {
110- self . shouldNavigateToMapView = true
118+ shouldNavigateToMapView = true
111119 }
112120 } else {
113121 DispatchQueue . main. async {
114122 alertMessage = errorMessage ?? " Something went wrong. Please pick another workspace. "
115123 showAlert = true
116- self . shouldNavigateToMapView = false
124+ shouldNavigateToMapView = false
117125 }
118126 }
119127 }
120128 }
121- . navigationDestination ( isPresented: $shouldNavigateToMapView) {
122- MapView ( selectedWorkspace: selectedWorkspace)
123- . navigationBarBackButtonHidden ( true )
124- }
125129 }
126130 } else if viewModel. workspaces. count == 0 {
127131 VStack {
@@ -151,8 +155,8 @@ struct WorkspacesListView: View {
151155 viewModel. checkAndDeleteWorkspaceDB ( workspaceId: " \( workspace. id) " )
152156 viewModel. fetchLongQuestsFor ( workspaceId: " \( workspace. id) " , completion: { success, errorMessage in
153157 if success {
154- self . shouldNavigateToMapView = true
155- self . selectedWorkspace = workspace
158+ shouldNavigateToMapView = true
159+ selectedWorkspace = workspace
156160
157161 let workspaceId = " \( workspace. id) "
158162 _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
@@ -162,7 +166,7 @@ struct WorkspacesListView: View {
162166
163167 showAlert = true
164168
165- self . shouldNavigateToMapView = false
169+ shouldNavigateToMapView = false
166170 }
167171 }
168172 } )
@@ -188,16 +192,6 @@ struct WorkspacesListView: View {
188192 Button ( " OK " , role: . cancel) { }
189193 }
190194 }
191-
192- if shouldNavigateToMapView, let selectedWorkspace = selectedWorkspace {
193- NavigationLink ( value: selectedWorkspace) {
194- EmptyView ( )
195- }
196- . navigationDestination ( isPresented: $shouldNavigateToMapView) {
197- MapView ( selectedWorkspace: selectedWorkspace)
198- . navigationBarBackButtonHidden ( true )
199- }
200- }
201195 }
202196}
203197
0 commit comments