Skip to content

Commit f3b2ead

Browse files
Added placeholder image and profile url
1 parent a80d373 commit f3b2ead

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@
589589
children = (
590590
FA87A80E2B681416000A6BEA /* Utils */,
591591
970D5BD02B62B61300C20BE7 /* MapViewController.swift */,
592-
B0CCB98B2B8626AE00AA73DE /* ProfileView.swift */,
593-
B0CCB98D2B8626C600AA73DE /* ProfileViewVM.swift */,
592+
B0CBEA902B88980A00C430F3 /* Profile */,
594593
971575152B5FFD5F0044797C /* Map */,
595594
973FC0152B4D562200878269 /* CustomComponents */,
596595
973FBFFF2B46CD4100878269 /* QuestsList */,
@@ -1083,6 +1082,15 @@
10831082
path = StepsIncline;
10841083
sourceTree = "<group>";
10851084
};
1085+
B0CBEA902B88980A00C430F3 /* Profile */ = {
1086+
isa = PBXGroup;
1087+
children = (
1088+
B0CCB98B2B8626AE00AA73DE /* ProfileView.swift */,
1089+
B0CCB98D2B8626C600AA73DE /* ProfileViewVM.swift */,
1090+
);
1091+
path = Profile;
1092+
sourceTree = "<group>";
1093+
};
10861094
FA5853BF2B21E3E000301CDA /* Onboarding */ = {
10871095
isa = PBXGroup;
10881096
children = (
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// ProfileView.swift
3+
// GoInfoGame
4+
//
5+
// Created by Sudula Murali Krishna on 2/21/24.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct ProfileView: View {
12+
@ObservedObject private var viewModel = ProfileViewVM()
13+
@Environment(\.dismiss) var dismiss
14+
@Environment(\.openURL) var openURL
15+
16+
var body: some View {
17+
return NavigationView {
18+
VStack {
19+
HStack {
20+
profileImage
21+
VStack (alignment: .leading,spacing: 0){
22+
Text(viewModel.user?.displayName ?? "")
23+
.font(.system(size: 20, weight: .semibold))
24+
HStack {
25+
Image(systemName: "star.fill")
26+
.resizable()
27+
.frame(width: 25, height: 25)
28+
Text("0")
29+
.font(.title)
30+
}
31+
}
32+
Spacer()
33+
}
34+
HStack {
35+
profileButton
36+
Spacer()
37+
logOutButton
38+
}
39+
Divider().padding()
40+
Spacer()
41+
}
42+
.padding(20)
43+
.navigationBarItems(leading: backButton)
44+
.navigationBarTitleDisplayMode(.inline)
45+
.navigationTitle("My Profile")
46+
}
47+
48+
}
49+
50+
private var profileImage: some View {
51+
AsyncImage(url: URL(string: "https://picsum.photos/200/300")) { phase in
52+
if let image = phase.image {
53+
image.resizable()
54+
} else if phase.error != nil {
55+
Image(systemName: "person.circle.fill")
56+
.resizable()
57+
} else {
58+
ProgressView().progressViewStyle(.circular)
59+
}
60+
}
61+
.frame(width: 120, height: 120, alignment: .center)
62+
.cornerRadius(60)
63+
}
64+
65+
private var profileButton: some View {
66+
Button {
67+
if let url = viewModel.profileUrl {
68+
openURL(url)
69+
}
70+
} label: {
71+
HStack {
72+
Image(systemName: "tray.and.arrow.up.fill")
73+
Text("OSM Profile")
74+
}
75+
.foregroundColor(.white)
76+
.font(.system(size: 16, weight: .semibold))
77+
.frame(width: 180, height: 50)
78+
.background(.black)
79+
.cornerRadius(5)
80+
}
81+
}
82+
83+
private var logOutButton: some View {
84+
Button {
85+
//LOGOUT
86+
} label: {
87+
Text("LOGOUT")
88+
.foregroundColor(.black)
89+
.font(.system(size: 16, weight: .semibold))
90+
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 50)
91+
.cornerRadius(15)
92+
.overlay {
93+
RoundedRectangle(cornerRadius: 5)
94+
.stroke(Color.black)
95+
}
96+
}
97+
}
98+
99+
private var backButton: some View {
100+
Button {
101+
dismiss()
102+
} label: {
103+
Image(systemName: "arrow.left")
104+
.font(.system(size: 24, weight: .semibold))
105+
.foregroundColor(.black)
106+
.cornerRadius(15)
107+
}
108+
}
109+
}
110+
111+
#Preview {
112+
ProfileView()
113+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// ProfileViewVM.swift
3+
// GoInfoGame
4+
//
5+
// Created by Sudula Murali Krishna on 2/21/24.
6+
//
7+
8+
import Foundation
9+
import osmapi
10+
11+
class ProfileViewVM: ObservableObject {
12+
@Published var user: OSMUserData?
13+
init() {
14+
let posmConnection = OSMConnection(config: OSMConfig.testOSM,userCreds: OSMLogin.testOSM)
15+
posmConnection.getUserDetails() { [weak self]result in
16+
switch result {
17+
case .success(let userDataResponse):
18+
let user = userDataResponse.user
19+
print(userDataResponse)
20+
DispatchQueue.main.async {
21+
self?.user = user
22+
}
23+
case .failure(let error):
24+
print("---error", error)
25+
}
26+
}
27+
}
28+
29+
var profileUrl: URL? {
30+
if let userName = self.user?.displayName {
31+
return URL(string:OSMConfig.url.appending("user/").appending(userName))
32+
}
33+
return nil
34+
}
35+
}

GoInfoGame/osmapi/OSMConfig.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99
public struct OSMConfig {
10-
let baseUrl: String
10+
public let baseUrl: String
1111
//https://waylyticsposm.westus2.cloudapp.azure.com/api/0.6/
1212
// For testing data upload
1313

@@ -21,6 +21,10 @@ public struct OSMConfig {
2121
}
2222

2323
public static var testOSM : OSMConfig {
24-
OSMConfig(baseUrl: "https://master.apis.dev.openstreetmap.org/api/0.6/")
24+
OSMConfig(baseUrl: "\(url)api/0.6/")
25+
}
26+
27+
public static var url: String {
28+
"https://master.apis.dev.openstreetmap.org/"
2529
}
2630
}

0 commit comments

Comments
 (0)