Skip to content

Commit 407efb7

Browse files
authored
Merge pull request #287 from TaskarCenterAtUW/task-2336-Update-Imagery-picker-to-get-the-imagery-list-from-workspaces-list-API
Task 2336 update imagery picker to get the imagery list from workspaces list api
2 parents 089f7ae + 58ef5cf commit 407efb7

File tree

12 files changed

+80
-197
lines changed

12 files changed

+80
-197
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
C71EB5B72E2100E30009E610 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B22E2100E30009E610 /* NetworkManager.swift */; };
150150
C71EB5B82E2100E30009E610 /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B32E2100E30009E610 /* NetworkMonitor.swift */; };
151151
C71EB5B92E2100E30009E610 /* APIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C71EB5B12E2100E30009E610 /* APIManager.swift */; };
152-
C71EB5BD2E2113500009E610 /* WMTSLayers.json in Resources */ = {isa = PBXBuildFile; fileRef = C71EB5BC2E2113500009E610 /* WMTSLayers.json */; };
153152
C75666D02E0D068900D36C41 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = C75666CF2E0D068900D36C41 /* OHHTTPStubs */; };
154153
C75666D22E0D068900D36C41 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = C75666D12E0D068900D36C41 /* OHHTTPStubsSwift */; };
155154
C75CC5D92E0D22F4008A94A0 /* LongQuestsResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */; };
@@ -505,7 +504,6 @@
505504
C71EB5B22E2100E30009E610 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
506505
C71EB5B32E2100E30009E610 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
507506
C71EB5B42E2100E30009E610 /* ResponseHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResponseHandler.swift; sourceTree = "<group>"; };
508-
C71EB5BC2E2113500009E610 /* WMTSLayers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = WMTSLayers.json; sourceTree = "<group>"; };
509507
C75CC5D62E0D22F4008A94A0 /* Workspaces response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "Workspaces response.json"; sourceTree = "<group>"; };
510508
C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "SCLIO Seattle pins response.json"; sourceTree = "<group>"; };
511509
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = LongQuestsResponse.json; sourceTree = "<group>"; };
@@ -1335,7 +1333,6 @@
13351333
C75CC5D52E0D22E0008A94A0 /* SampleResponses */ = {
13361334
isa = PBXGroup;
13371335
children = (
1338-
C71EB5BC2E2113500009E610 /* WMTSLayers.json */,
13391336
C75CC5D62E0D22F4008A94A0 /* Workspaces response.json */,
13401337
C75CC5D72E0D22F4008A94A0 /* SCLIO Seattle pins response.json */,
13411338
C75CC5D82E0D22F4008A94A0 /* LongQuestsResponse.json */,
@@ -1978,7 +1975,6 @@
19781975
C76B63742E46019D0076A540 /* proximanova_regular.otf in Resources */,
19791976
C76B63752E46019D0076A540 /* proximanova_light.otf in Resources */,
19801977
C76B63762E46019D0076A540 /* proximanova_semibold.otf in Resources */,
1981-
C71EB5BD2E2113500009E610 /* WMTSLayers.json in Resources */,
19821978
C7A922252E45C36D00705E21 /* PrivacyInfo.xcprivacy in Resources */,
19831979
FAD5C4FC2AFCBE720040C61A /* Assets.xcassets in Resources */,
19841980
FAD5C4FA2AFCBE700040C61A /* Main.storyboard in Resources */,

GoInfoGame/GoInfoGame/Helpers/Extensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ extension Double {
207207
(self * 1_000_0000).rounded() / 1_000_0000
208208
}
209209
}
210+
211+
extension URLRequest {
212+
mutating func addAuthorizationHeader() {
213+
if let jwtAccessToken = KeychainManager.load(key: KeychainManager.Keys.accessToken.rawValue) {
214+
self.setValue("Bearer \(jwtAccessToken)", forHTTPHeaderField: "Authorization")
215+
}
216+
}
217+
}

GoInfoGame/GoInfoGame/Helpers/SampleResponses/WMTSLayers.json

Lines changed: 0 additions & 102 deletions
This file was deleted.

GoInfoGame/GoInfoGame/Network/APIHandler/APIManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension APIRequest {
2121
var request: URLRequest = urlRequest
2222
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
2323
if let jwtAccessToken = KeychainManager.load(key: KeychainManager.Keys.accessToken.rawValue) {
24-
request.setValue(jwtAccessToken, forHTTPHeaderField: "Authorization")
24+
request.setValue("Bearer \(jwtAccessToken)", forHTTPHeaderField: "Authorization")
2525
}
2626
return request
2727
}

GoInfoGame/GoInfoGame/Network/ApiManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class ApiManager {
119119
}
120120
debugPrint("set body prepared \(Date())")
121121

122+
request.addAuthorizationHeader()
122123
if let headers = endpoint.headers {
123124
for (key, value) in headers {
124125
request.setValue(value, forHTTPHeaderField: key)

GoInfoGame/GoInfoGame/Network/models/WorkspacesResponse.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ struct Workspace: Codable,Hashable {
2727
let title: String
2828
let type: String?
2929
let externalAppAccess: Int
30+
let imageryList: SatelliteServers?
3031

3132
init(from decoder: Decoder) throws {
32-
let container = try decoder.container(keyedBy: CodingKeys.self)
33-
id = try container.decode(Int.self, forKey: .id)
34-
title = try container.decode(String.self, forKey: .title)
35-
type = try container.decodeIfPresent(String.self, forKey: .type) ?? "osw"
33+
let container = try decoder.container(keyedBy: CodingKeys.self)
34+
id = try container.decode(Int.self, forKey: .id)
35+
title = try container.decode(String.self, forKey: .title)
36+
type = try container.decodeIfPresent(String.self, forKey: .type) ?? "osw"
3637
externalAppAccess = try container.decode(Int.self, forKey: .externalAppAccess)
37-
}
38+
imageryList = try container.decodeIfPresent(SatelliteServers.self, forKey: .imageryList)
39+
}
3840

39-
enum CodingKeys: String, CodingKey {
40-
case id, title, type, externalAppAccess
41-
}
41+
enum CodingKeys: String, CodingKey {
42+
case id, title, type, externalAppAccess, imageryList
43+
}
4244
}
4345

4446
// MARK: - Polygon

GoInfoGame/GoInfoGame/UI/InitialView/InitialView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct InitialView: View {
5656
}
5757
.navigationDestination(isPresented: $shouldNavigateToMapView) {
5858
if let workspace = selectedWorkspace {
59-
MapView(selectedWorkspace: workspace)
59+
MapView(selectedWorkspace: workspace, viewModel: MapViewModel(workspace: workspace))
6060
.navigationBarBackButtonHidden(true)
6161
}
6262
}

GoInfoGame/GoInfoGame/UI/Map/MapRepository.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,3 @@ enum SatelliteOption: Identifiable, Hashable {
3434
hasher.combine(id)
3535
}
3636
}
37-
38-
protocol MapRepositoryProtocol {
39-
func fetchAvailableServers() async throws -> SatelliteServers
40-
}
41-
42-
class MapRepository: MapRepositoryProtocol {
43-
let netowrkClient: NetworkHandler
44-
init(netowrkClient: NetworkHandler = NetworkManager()) {
45-
self.netowrkClient = netowrkClient
46-
}
47-
48-
func fetchAvailableServers() async throws -> SatelliteServers {
49-
return try await netowrkClient.fetchData(request: GetWMTSLayersReqeust())
50-
}
51-
}
52-
53-
struct GetWMTSLayersReqeust: APIRequest {
54-
var urlRequest: URLRequest? {
55-
guard let url = Bundle.main.url(forResource: "WMTSLayers", withExtension: "json") else {
56-
return nil
57-
}
58-
59-
var urlRequest = URLRequest(url: url)
60-
urlRequest.httpMethod = "GET"
61-
return urlRequest
62-
}
63-
}

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import MapKit
1010
import Combine
1111

1212
struct MapView: View {
13-
let selectedWorkspace: Workspace?
13+
let selectedWorkspace: Workspace
1414
@State var trackingMode: MapUserTrackingMode = MapUserTrackingMode.follow
1515
@Environment(\.presentationMode) private var presentationMode
1616
@AppStorage("isMapFromOnboarding") var isMapFromOnboarding: Bool = false
17-
@StateObject private var viewModel = MapViewModel()
17+
@StateObject var viewModel: MapViewModel
1818
@State private var isPresented = false
1919

2020
@State private var shouldShowPolyline = true
@@ -247,7 +247,7 @@ struct MapView: View {
247247
.font(FontFamily.Lato.regular.swiftUIFont(size: 12))
248248
.foregroundStyle(Asset.Colors._83879BTextFiledTitle.swiftUIColor)
249249

250-
Text(selectedWorkspace?.title ?? "")
250+
Text(selectedWorkspace.title)
251251
.font(FontFamily.Lato.bold.swiftUIFont(size: 14))
252252
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
253253
}
@@ -260,47 +260,48 @@ struct MapView: View {
260260
}
261261

262262
ToolbarItem(placement: .navigationBarTrailing) {
263-
QuestSyncButton(badgeCount: viewModel.syncFailedElementsCount, isSyncing: isSyncing, action: {
264-
debugPrint("Sync taped")
265-
guard viewModel.syncFailedElementsCount > 0 else {
266-
alertIcon = "info.bubble"
267-
alertMessage = "No elements to sync"
268-
showAlert = true
269-
return
263+
HStack(spacing: 5.0) {
264+
QuestSyncButton(badgeCount: viewModel.syncFailedElementsCount, isSyncing: isSyncing, action: {
265+
debugPrint("Sync taped")
266+
guard viewModel.syncFailedElementsCount > 0 else {
267+
alertIcon = "info.bubble"
268+
alertMessage = "No elements to sync"
269+
showAlert = true
270+
return
271+
}
272+
isSyncing = true
273+
DatasyncManager.shared.syncDataToOSM(exclude_gig_tags: false) { _ in
274+
isSyncing = false
275+
viewModel.checkSyncStatus()
276+
}
277+
})
278+
279+
Button(action: {
280+
debugPrint("satellite icon tapped")
281+
viewModel.updateOptions(for: mapViewRef?.region.center ?? CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0))
282+
viewModel.showSatellitePicker = true
283+
}) {
284+
Image(systemName: "square.2.layers.3d.bottom.filled")
285+
.resizable()
286+
.padding(8)
287+
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
288+
.background(Asset.Colors.e7E3EELightPurpuleBg.swiftUIColor)
289+
.frame(width: 34, height: 34)
290+
.clipShape(Circle())
270291
}
271-
isSyncing = true
272-
DatasyncManager.shared.syncDataToOSM(exclude_gig_tags: false) { _ in
273-
isSyncing = false
274-
viewModel.checkSyncStatus()
292+
293+
Button(action: {
294+
print("Settings icon tapped")
295+
showUserSettingsSheet = true
296+
}) {
297+
Image(systemName: "gear")
298+
.resizable()
299+
.padding(8)
300+
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
301+
.background(Asset.Colors.e7E3EELightPurpuleBg.swiftUIColor)
302+
.frame(width: 34, height: 34)
303+
.clipShape(Circle())
275304
}
276-
})
277-
}
278-
279-
ToolbarItem(placement: .navigationBarTrailing) {
280-
Button(action: {
281-
debugPrint("satellite icon tapped")
282-
viewModel.updateOptions(for: mapViewRef?.region.center ?? CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0))
283-
viewModel.showSatellitePicker = true
284-
}) {
285-
Image(systemName: "square.2.layers.3d.bottom.filled")
286-
.padding(8)
287-
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
288-
.background(Asset.Colors.e7E3EELightPurpuleBg.swiftUIColor)
289-
.frame(width: 34, height: 34)
290-
.clipShape(Circle())
291-
}
292-
}
293-
ToolbarItem(placement: .navigationBarTrailing) {
294-
Button(action: {
295-
print("Settings icon tapped")
296-
showUserSettingsSheet = true
297-
}) {
298-
Image(systemName: "gear")
299-
.padding(8)
300-
.foregroundStyle(Asset.Colors.huskyPurple.swiftUIColor)
301-
.background(Asset.Colors.e7E3EELightPurpuleBg.swiftUIColor)
302-
.frame(width: 34, height: 34)
303-
.clipShape(Circle())
304305
}
305306
}
306307
}
@@ -342,7 +343,7 @@ struct MapView: View {
342343
.presentationDragIndicator(.visible)
343344
}
344345
.sheet(isPresented: $showUserSettingsSheet) {
345-
UserSettingsView(selectedWorkspace: selectedWorkspace?.title ?? "", options: OptionModel.options, onNavigate: { navigate in
346+
UserSettingsView(selectedWorkspace: selectedWorkspace.title, options: OptionModel.options, onNavigate: { navigate in
346347
showUserSettingsSheet = false
347348
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
348349
// navigateToProfileSettings = true
@@ -506,7 +507,7 @@ struct MapView: View {
506507
})
507508
.onAppear(){
508509
HiddenQuestManager.shared.loadHiddenQuests()
509-
print("selected workspace",selectedWorkspace?.title ?? "")
510+
print("selected workspace",selectedWorkspace.title)
510511
QuestsRepository.shared.loadLongQuests(from: "longQuestJson")
511512
// self.baseUrl = "https://osm.workspaces-stage.sidewalks.washington.edu"
512513
// let original = DatabaseConnector.shared.getNode(id: 43)

0 commit comments

Comments
 (0)