-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileView.swift
66 lines (60 loc) · 1.44 KB
/
ProfileView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import SwiftUI
struct ProfileView: View {
@StateObject var viewModel = ProfileViewViewModel()
var body: some View {
Navigation {
VStack {
if let user = viewModel.user {
profile(user: user)
} else {
Text("Loading user profile")
}
}
.navigationTitle("Profile")
}
.onAppear {
viewModel.fetchUser()
}
}
}
@ViewBuilder
func profile(user: User) -> some View {
Image(systemName: "person.circle")
.resizeable()
.aspectRatio(contentMode: .fit)
.foregroundColor(Color.blue)
.frame(width: 125, height: 125)
.padding()
VStack(alignment: .leading) {
HStack {
Text("Name")
.bold()
Text(user.name)
}
.padding()
HStack {
Text("Email")
.bold()
Text(user.email)
}
.padding()
HStack {
Text("Member Since")
.bold()
Text("\(Date(timeIntervalSince1970: user.joined).formatted(date: .abreviated, time: .shortened))")
}
.padding()
}
.padding()
Button("Log Out") {
viewModel.logout()
}
.tint(.red)
.padding()
Spacer()
}
struct ProfileView_Previews: PreviewProvider {
static var previews: some View {
ProfileView()
}
}