@@ -12,51 +12,45 @@ struct InitialView: View {
1212 @State private var shouldNavigateToMapView = false
1313 @State private var selectedWorkspace : Workspace ? = nil
1414 @StateObject private var locManagerDelegate = LocationManagerDelegate ( )
15-
16- @State private var isLoading : Bool = false
17-
1815 @AppStorage ( " loggedIn " ) private var loggedIn : Bool = false
1916 @State private var showBiometricPrompt = false
2017
2118 var body : some View {
2219 NavigationStack {
2320 ZStack {
2421 VStack {
25- HStack {
26- NavigationLink ( destination: UserProfileView ( ) ) {
27- Image ( systemName: " person.crop.circle.fill " )
28- . resizable ( )
29- . frame ( width: 27 , height: 27 )
30- . padding ( [ . leading] , 18 )
31- . foregroundStyle ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
32-
33- }
34- Spacer ( )
35- }
36- . frame ( maxWidth: . infinity, alignment: . leading)
37-
38- Spacer ( )
39-
40- VStack ( spacing: 30 ) {
41- Image ( " osmlogo " )
42- . resizable ( )
43- . frame ( width: 100 , height: 100 )
44- Text ( " GoInfoGame " )
45- . font ( . system( size: 30 , design: . rounded) )
46- }
47- . padding ( )
48-
49- Spacer ( )
50-
51- if viewModel. workspaces. count > 1 {
52- WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel, shouldNavigateToMapView: $shouldNavigateToMapView, selectedWorkspace: $selectedWorkspace, isLoading: $isLoading)
53- }
54- }
22+ HStack {
23+ NavigationLink ( destination: UserProfileView ( ) ) {
24+ Image ( systemName: " person.crop.circle.fill " )
25+ . resizable ( )
26+ . frame ( width: 27 , height: 27 )
27+ . padding ( [ . leading] , 18 )
28+ . foregroundStyle ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
29+
30+ }
31+ Spacer ( )
32+ }
33+ . frame ( maxWidth: . infinity, alignment: . leading)
34+
35+ Spacer ( )
36+
37+ VStack ( spacing: 30 ) {
38+ Image ( " osmlogo " )
39+ . resizable ( )
40+ . frame ( width: 100 , height: 100 )
41+ Text ( " GoInfoGame " )
42+ . font ( . system( size: 30 , design: . rounded) )
43+ }
44+ . padding ( )
45+
46+ Spacer ( )
47+
48+ WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel, shouldNavigateToMapView: $shouldNavigateToMapView, selectedWorkspace: $selectedWorkspace, isLoading: $viewModel. isLoading)
49+ }
5550 . padding ( )
5651
57- if isLoading {
52+ if viewModel . isLoading {
5853 ActivityView ( activityText: " Fetching workspaces " )
59-
6054 }
6155 }
6256 . navigationDestination ( isPresented: $shouldNavigateToMapView) {
@@ -67,7 +61,7 @@ struct InitialView: View {
6761 }
6862 }
6963 . onAppear {
70- isLoading = true
64+ viewModel . isLoading = true
7165 viewModel. checkBiometricOptInCondition ( for: APIConfiguration . shared. environment)
7266 showBiometricPrompt = viewModel. shouldShowBiometricOptInPrompt
7367 }
@@ -82,7 +76,7 @@ struct InitialView: View {
8276 Text ( " Would you like to use Face ID or Touch ID for faster logins? " )
8377 }
8478 . toolbar ( . hidden)
85- }
79+ }
8680}
8781
8882// WorkspacesListView - View for displaying a list of workspaces
@@ -97,7 +91,7 @@ struct WorkspacesListView: View {
9791 @State private var showAlert = false
9892
9993 @State private var alertMessage = " "
100-
94+
10195 var body : some View {
10296
10397 if viewModel. workspaces. count == 1 {
@@ -133,58 +127,49 @@ struct WorkspacesListView: View {
133127 . font ( . custom( " Lato-Bold " , size: 20 ) )
134128 . foregroundColor ( ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) ) )
135129 . multilineTextAlignment ( . center)
136- . onAppear {
137- isLoading = false
138- }
139130 Spacer ( )
140131 }
141-
132+
142133 } else {
143134 VStack {
144135 Text ( " Pick the workspace you want to contribute to " )
145- . onAppear {
146- isLoading = false
147- }
148136 . font ( . system( size: 16 , design: . rounded) )
149137 . foregroundStyle ( . gray)
150138
151139 ScrollView {
152- VStack ( spacing: 20 ) {
153- ForEach ( workspaces. filter ( { $0. type == " osw " && $0. externalAppAccess == 1 } ) , id: \. id) { workspace in
154- Button {
155- viewModel. checkAndDeleteWorkspaceDB ( workspaceId: " \( workspace. id) " )
156- viewModel. fetchLongQuestsFor ( workspaceId: " \( workspace. id) " , completion: { success, errorMessage in
157- if success {
158- shouldNavigateToMapView = true
159- selectedWorkspace = workspace
160-
161- let workspaceId = " \( workspace. id) "
162- _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
163- } else {
164- DispatchQueue . main. async {
165- alertMessage = errorMessage ?? " Something went wrong. "
166-
167- showAlert = true
168-
169- shouldNavigateToMapView = false
170- }
171- }
172- } )
173- } label: {
174- Text ( workspace. title)
175- . font ( . system( size: 17 ) )
176- . frame ( maxWidth: . infinity, maxHeight: 40 )
140+ VStack ( spacing: 20 ) {
141+ ForEach ( workspaces. filter ( { $0. type == " osw " && $0. externalAppAccess == 1 } ) , id: \. id) { workspace in
142+ Button {
143+ viewModel. checkAndDeleteWorkspaceDB ( workspaceId: " \( workspace. id) " )
144+ viewModel. fetchLongQuestsFor ( workspaceId: " \( workspace. id) " , completion: { success, errorMessage in
145+ if success {
146+ shouldNavigateToMapView = true
147+ selectedWorkspace = workspace
148+
149+ let workspaceId = " \( workspace. id) "
150+ _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
151+ } else {
152+ DispatchQueue . main. async {
153+ alertMessage = errorMessage ?? " Something went wrong. "
154+
155+ showAlert = true
156+
157+ shouldNavigateToMapView = false
158+ }
177159 }
178- . font ( . custom( " Lato-Bold " , size: 25 ) )
179- . foregroundColor ( Color . white)
180- . padding ( )
181- . background ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
182- . buttonBorderShape ( . roundedRectangle( radius: 10 ) )
183- }
160+ } )
161+ } label: {
162+ Text ( workspace. title)
163+ . font ( . system( size: 17 ) )
164+ . frame ( maxWidth: . infinity, maxHeight: 40 )
184165 }
166+ . font ( . custom( " Lato-Bold " , size: 25 ) )
167+ . foregroundColor ( Color . white)
168+ . padding ( )
169+ . background ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
170+ . buttonBorderShape ( . roundedRectangle( radius: 10 ) )
185171 }
186- . onAppear {
187-
172+ }
188173 }
189174 . padding ( )
190175 }
@@ -202,7 +187,7 @@ struct LocationDisabledView: View {
202187 . font ( . custom( " Lato-Bold " , size: 30 ) )
203188 . foregroundColor ( ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) ) )
204189 . padding ( [ . bottom] , 50 )
205-
190+
206191 Text ( " Location Services Disabled " )
207192 . font ( . custom( " Lato-Bold " , size: 25 ) )
208193 . padding ( )
@@ -227,7 +212,6 @@ struct LocationDisabledView: View {
227212
228213#Preview {
229214 InitialView ( )
230-
231215}
232216
233217
0 commit comments