Skip to content

Commit 0daea0b

Browse files
authored
Merge pull request #266 from TaskarCenterAtUW/bugs-while-testing-1_0_35
Bug fixes while testing 1.0(35)
2 parents 706cc96 + 7e91511 commit 0daea0b

File tree

3 files changed

+70
-89
lines changed

3 files changed

+70
-89
lines changed

GoInfoGame/GoInfoGame/DataBase/DatabaseConnector.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ class DatabaseConnector {
215215
@return StoredNode
216216
*/
217217
func getNode(id:Int) -> StoredNode? {
218-
let compoundId = "\(id)"
219-
return realm.object(ofType: StoredNode.self, forPrimaryKey: compoundId)
218+
return realm.object(ofType: StoredNode.self, forPrimaryKey: id)
220219
}
221220
/**
222221
Fetches single Way from the database
@@ -228,8 +227,7 @@ class DatabaseConnector {
228227
// }
229228

230229
func getWay(id: Int) -> StoredWay? {
231-
let compoundId = "\(id)"
232-
return realm.object(ofType: StoredWay.self, forPrimaryKey: compoundId)
230+
return realm.object(ofType: StoredWay.self, forPrimaryKey: id)
233231
}
234232

235233

GoInfoGame/GoInfoGame/UI/InitialView/InitialView.swift

Lines changed: 63 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 @@ struct InitialView: View {
6761
}
6862
}
6963
.onAppear {
70-
isLoading = true
7164
viewModel.checkBiometricOptInCondition(for: APIConfiguration.shared.environment)
7265
showBiometricPrompt = viewModel.shouldShowBiometricOptInPrompt
7366
}
@@ -82,7 +75,7 @@ struct InitialView: View {
8275
Text("Would you like to use Face ID or Touch ID for faster logins?")
8376
}
8477
.toolbar(.hidden)
85-
}
78+
}
8679
}
8780

8881
// WorkspacesListView - View for displaying a list of workspaces
@@ -97,7 +90,7 @@ struct WorkspacesListView: View {
9790
@State private var showAlert = false
9891

9992
@State private var alertMessage = ""
100-
93+
10194
var body: some View {
10295

10396
if viewModel.workspaces.count == 1 {
@@ -133,58 +126,49 @@ struct WorkspacesListView: View {
133126
.font(.custom("Lato-Bold", size: 20))
134127
.foregroundColor((Color(red: 135/255, green: 62/255, blue: 242/255)))
135128
.multilineTextAlignment(.center)
136-
.onAppear {
137-
isLoading = false
138-
}
139129
Spacer()
140130
}
141-
131+
142132
} else {
143133
VStack {
144134
Text("Pick the workspace you want to contribute to")
145-
.onAppear {
146-
isLoading = false
147-
}
148135
.font(.system(size: 16, design: .rounded))
149136
.foregroundStyle(.gray)
150137

151138
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)
139+
VStack(spacing: 20) {
140+
ForEach(workspaces.filter({$0.type == "osw" && $0.externalAppAccess == 1}), id: \.id) { workspace in
141+
Button {
142+
viewModel.checkAndDeleteWorkspaceDB(workspaceId: "\(workspace.id)")
143+
viewModel.fetchLongQuestsFor(workspaceId: "\(workspace.id)", completion: { success, errorMessage in
144+
if success {
145+
shouldNavigateToMapView = true
146+
selectedWorkspace = workspace
147+
148+
let workspaceId = "\(workspace.id)"
149+
_ = KeychainManager.save(key: "workspaceID", data: workspaceId)
150+
} else {
151+
DispatchQueue.main.async {
152+
alertMessage = errorMessage ?? "Something went wrong."
153+
154+
showAlert = true
155+
156+
shouldNavigateToMapView = false
157+
}
177158
}
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-
}
159+
})
160+
} label: {
161+
Text(workspace.title)
162+
.font(.system(size: 17))
163+
.frame(maxWidth: .infinity, maxHeight: 40)
184164
}
165+
.font(.custom("Lato-Bold", size: 25))
166+
.foregroundColor(Color.white)
167+
.padding()
168+
.background(Color(red: 135/255, green: 62/255, blue: 242/255))
169+
.buttonBorderShape(.roundedRectangle(radius: 10))
185170
}
186-
.onAppear {
187-
171+
}
188172
}
189173
.padding()
190174
}
@@ -202,7 +186,7 @@ struct LocationDisabledView: View {
202186
.font(.custom("Lato-Bold", size: 30))
203187
.foregroundColor((Color(red: 135/255, green: 62/255, blue: 242/255)))
204188
.padding([.bottom], 50)
205-
189+
206190
Text("Location Services Disabled")
207191
.font(.custom("Lato-Bold", size: 25))
208192
.padding()
@@ -227,7 +211,6 @@ struct LocationDisabledView: View {
227211

228212
#Preview {
229213
InitialView()
230-
231214
}
232215

233216

GoInfoGame/GoInfoGame/UI/InitialView/InitialViewModel.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ class InitialViewModel: ObservableObject {
5959

6060
// fetch workspaces list
6161
func fetchWorkspacesList() {
62-
62+
self.isLoading = true
6363
if let accessToken = KeychainManager.load(key: "accessToken") {
6464
ApiManager.shared.performRequest(to: .fetchWorkspaceList(accessToken), setupType: .workspace, modelType: [Workspace].self) { result in
6565

66-
DispatchQueue.main.async {
66+
DispatchQueue.main.async { [weak self] in
67+
self?.isLoading = false
6768
switch result {
6869
case .success(let workspacesResponse):
69-
self.workspaces = workspacesResponse
70-
self.isLoading = false
70+
self?.workspaces = workspacesResponse
7171
case .failure(let error):
72+
self?.workspaces = []
7273
print("Error fetching workspaces: \(error)")
73-
self.isLoading = false
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)