@@ -11,47 +11,57 @@ struct InitialView: View {
1111 @StateObject private var viewModel = InitialViewModel ( )
1212 @State private var shouldNavigateToMapView = false
1313 @StateObject private var locManagerDelegate = LocationManagerDelegate ( )
14-
14+
15+ @State private var isLoading : Bool = false
16+
17+ @AppStorage ( " loggedIn " ) private var loggedIn : Bool = false
18+
1519 var body : some View {
1620 NavigationStack {
17- if locManagerDelegate. isLocationServicesOff || locManagerDelegate. isLocationDenied {
18- LocationDisabledView ( )
19- } else {
20- if viewModel. workspaces. count > 1 {
21- WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel)
22- } else if viewModel. workspaces. count == 1 {
23- if let selectedWorkspace = viewModel. workspaces. first {
24- VStack {
25- if !shouldNavigateToMapView {
26- ActivityView ( activityText: " Fetching workspace data... " )
27- }
28- }
29- . onAppear {
30- viewModel. fetchLongQuestsFor ( workspaceId: " \( selectedWorkspace. id) " ) { success in
31- if success {
32- let workspaceId = " \( selectedWorkspace. id) "
33- _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
34- DispatchQueue . main. async {
35- self . shouldNavigateToMapView = true
36- }
37- }
38- }
39- }
40- . navigationDestination ( isPresented: $shouldNavigateToMapView) {
41- MapView ( selectedWorkspace: selectedWorkspace)
42- . navigationBarBackButtonHidden ( true )
43- }
44- }
45- } else {
46- ActivityView ( activityText: " Looking for workspaces... " )
21+ ZStack {
22+ VStack {
23+ HStack {
24+ NavigationLink ( destination: UserProfileView ( ) ) {
25+ Image ( systemName: " person.crop.circle.fill " )
26+ . resizable ( )
27+ . frame ( width: 27 , height: 27 )
28+ . padding ( [ . leading] , 18 )
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+ if viewModel. workspaces. count > 1 {
49+ WorkspacesListView ( workspaces: viewModel. workspaces, viewModel: viewModel, isLoading: $isLoading)
50+ }
51+ }
52+ . padding ( )
53+
54+ if isLoading {
55+ ActivityView ( activityText: " Fetching workspaces " )
56+
4757 }
4858 }
4959 }
5060 . onAppear {
51- viewModel . locationManagerDelegate . requestLocationAuthorization ( )
61+ isLoading = true
5262 }
53- . navigationBarBackButtonHidden ( true )
54- }
63+ . toolbar ( . hidden )
64+ }
5565}
5666
5767// WorkspacesListView - View for displaying a list of workspaces
@@ -61,51 +71,87 @@ struct WorkspacesListView: View {
6171 @State private var shouldNavigateToMapView = false
6272 @State private var selectedWorkspace : Workspace ?
6373
64- @AppStorage ( " loggedIn " ) private var loggedIn : Bool = false
65-
74+ @Binding var isLoading : Bool
75+
6676 var body : some View {
67- ZStack ( alignment: . topLeading) {
68- VStack ( alignment: . leading) {
69- VStack ( spacing: 30 ) {
70- Image ( " osmlogo " )
71- . resizable ( )
72- . frame ( width: 100 , height: 100 )
73- Text ( " GoInfoGame " )
74- . font ( . system( size: 30 , design: . rounded) )
75- Text ( " Pick the workspace you want to contribute to " )
76- . font ( . system( size: 16 , design: . rounded) )
77- . foregroundStyle ( . gray)
77+
78+ if viewModel. workspaces. count == 1 {
79+ if let selectedWorkspace = viewModel. workspaces. first {
80+ VStack {
81+ if !shouldNavigateToMapView {
82+ ActivityView ( activityText: " Fetching workspace data... " )
83+ Spacer ( )
84+ }
7885 }
79- . padding ( )
86+ . onAppear {
87+ viewModel. fetchLongQuestsFor ( workspaceId: " \( selectedWorkspace. id) " ) { success in
88+ if success {
89+ let workspaceId = " \( selectedWorkspace. id) "
90+ _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
91+ DispatchQueue . main. async {
92+ self . shouldNavigateToMapView = true
93+ }
94+ }
95+ }
96+ }
97+ . navigationDestination ( isPresented: $shouldNavigateToMapView) {
98+ MapView ( selectedWorkspace: selectedWorkspace)
99+ . navigationBarBackButtonHidden ( true )
100+ }
101+ }
102+ } else if viewModel. workspaces. count == 0 {
103+ VStack {
104+ Text ( " No workspaces available for you to work on. " )
105+ . font ( . custom( " Lato-Bold " , size: 20 ) )
106+ . foregroundColor ( ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) ) )
107+ . multilineTextAlignment ( . center)
108+ . onAppear {
109+ isLoading = false
110+ }
111+ Spacer ( )
112+ }
113+
114+ } else {
115+ VStack {
116+ Text ( " Pick the workspace you want to contribute to " )
117+ . onAppear {
118+ isLoading = false
119+ }
120+ . font ( . system( size: 16 , design: . rounded) )
121+ . foregroundStyle ( . gray)
122+
80123 ScrollView {
81- VStack ( spacing: 20 ) {
82- ForEach ( workspaces. filter ( { $0. type == " osw " } ) , id: \. id) { workspace in
83- Button {
84- viewModel. fetchLongQuestsFor ( workspaceId: " \( workspace. id) " , completion: { success in
85- if success {
86- self . shouldNavigateToMapView = true
87- self . selectedWorkspace = workspace
88-
89- let workspaceId = " \( workspace. id) "
90- _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
124+ VStack ( spacing: 20 ) {
125+ ForEach ( workspaces. filter ( { $0. type == " osw " } ) , id: \. id) { workspace in
126+ Button {
127+ viewModel. fetchLongQuestsFor ( workspaceId: " \( workspace. id) " , completion: { success in
128+ if success {
129+ self . shouldNavigateToMapView = true
130+ self . selectedWorkspace = workspace
131+
132+ let workspaceId = " \( workspace. id) "
133+ _ = KeychainManager . save ( key: " workspaceID " , data: workspaceId)
134+ }
135+ } )
136+ } label: {
137+ Text ( workspace. title)
138+ . font ( . system( size: 17 ) )
139+ . frame ( maxWidth: . infinity, maxHeight: 40 )
91140 }
92- } )
93- } label: {
94- Text ( workspace. title)
95- . font ( . system( size: 17 ) )
96- . frame ( maxWidth: . infinity, maxHeight: 40 )
141+ . font ( . custom( " Lato-Bold " , size: 25 ) )
142+ . foregroundColor ( Color . white)
143+ . padding ( )
144+ . background ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
145+ . buttonBorderShape ( . roundedRectangle( radius: 10 ) )
146+ }
97147 }
98- . font ( . custom( " Lato-Bold " , size: 25 ) )
99- . foregroundColor ( Color . white)
100- . padding ( )
101- . background ( Color ( red: 135 / 255 , green: 62 / 255 , blue: 242 / 255 ) )
102- . buttonBorderShape ( . roundedRectangle( radius: 10 ) )
103148 }
104- }
149+ . onAppear {
150+
105151 }
106152 . padding ( )
107153 }
108- . padding ( )
154+ }
109155
110156 if shouldNavigateToMapView, let selectedWorkspace = selectedWorkspace {
111157 NavigationLink ( value: selectedWorkspace) {
@@ -116,19 +162,6 @@ struct WorkspacesListView: View {
116162 . navigationBarBackButtonHidden ( true )
117163 }
118164 }
119-
120- NavigationLink ( destination: UserProfileView ( ) ) {
121- Image ( systemName: " person.crop.circle.fill " )
122- . resizable ( )
123- . frame ( width: 27 , height: 27 )
124- . padding ( [ . leading] , 18 )
125-
126- }
127-
128-
129-
130-
131- }
132165 }
133166}
134167
@@ -163,7 +196,7 @@ struct LocationDisabledView: View {
163196}
164197
165198#Preview {
166- LocationDisabledView ( )
199+ InitialView ( )
167200
168201}
169202
0 commit comments