| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import SwiftUI
- import GoogleSignIn
- struct UserProfileView: View {
- @EnvironmentObject var authViewModel: AuthenticationViewModel
- @StateObject var birthdayViewModel = BirthdayViewModel()
- private var user: GIDGoogleUser? {
- return GIDSignIn.sharedInstance.currentUser
- }
- var body: some View {
- return Group {
- if let userProfile = user?.profile {
- VStack(spacing: 10) {
- HStack(alignment: .top) {
- UserProfileImageView(userProfile: userProfile)
- .padding(.leading)
- VStack(alignment: .leading) {
- Text(userProfile.name)
- .font(.headline)
- Text(userProfile.email)
- }
- }
- Button(NSLocalizedString("Sign Out", comment: "Sign out button"), action: signOut)
- .background(Color.blue)
- .foregroundColor(Color.white)
- .cornerRadius(5)
- Button(NSLocalizedString("Disconnect", comment: "Disconnect button"), action: disconnect)
- .background(Color.blue)
- .foregroundColor(Color.white)
- .cornerRadius(5)
- Spacer()
- NavigationLink(NSLocalizedString("View Days Until Birthday", comment: "View birthday days"),
- destination: BirthdayView(birthdayViewModel: birthdayViewModel).onAppear {
- guard self.birthdayViewModel.birthday != nil else {
- if !self.authViewModel.hasBirthdayReadScope {
- self.authViewModel.addBirthdayReadScope {
- self.birthdayViewModel.fetchBirthday()
- }
- } else {
- self.birthdayViewModel.fetchBirthday()
- }
- return
- }
- })
- .background(Color.blue)
- .foregroundColor(Color.white)
- .cornerRadius(5)
- Spacer()
- }
- } else {
- Text(NSLocalizedString("Failed to get user profile!", comment: "Empty user profile text"))
- }
- }
- }
- func disconnect() {
- authViewModel.disconnect()
- }
- func signOut() {
- authViewModel.signOut()
- }
- }
|