twigs-ios/Twigs/Profile/ProfileView.swift

97 lines
2.8 KiB
Swift
Raw Normal View History

//
// ProfileView.swift
// Twigs
//
// Created by Billy Brawner on 10/17/19.
// Copyright © 2019 William Brawner. All rights reserved.
//
import SwiftUI
2022-01-03 17:56:43 +00:00
import TwigsCore
struct ProfileView: View {
@EnvironmentObject var dataStore: DataStore
2022-06-07 00:11:32 +00:00
var username: String {
if case let .success(user) = self.dataStore.currentUser {
return user.username
} else {
return ""
}
}
var email: String {
if case let .success(user) = self.dataStore.currentUser {
return user.email ?? ""
} else {
return ""
}
}
2022-01-03 17:56:43 +00:00
@ViewBuilder
var body: some View {
2022-06-07 00:11:32 +00:00
List {
Section(content: {
NavigationLink(
destination: EditUsernameView(username: username)
.navigationTitle("change_username")
) {
Text("change_username")
}
// NavigationLink(destination: EmptyView()) {
// Text("change_profile_picture")
// }
}, header: {
HStack {
Spacer()
VStack(alignment: .center, spacing: 10.0) {
Image(systemName: "person.circle.fill")
.resizable()
.frame(width: 100, height: 100, alignment: .center)
.scaledToFill()
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 1))
.shadow(radius: 4)
Spacer()
Text(username)
}
Spacer()
}
})
Section {
NavigationLink(
destination: EditPasswordView()
.navigationTitle("change_password")
) {
Text("change_password")
}
NavigationLink(
destination: EditEmailView(email: email)
.navigationTitle("change_email")
) {
Text("change_email")
}
}
2022-06-07 00:11:32 +00:00
Section {
Button("logout", action: {
// TODO: Show some dialog to confirm
dataStore.logout()
})
}
2022-06-07 00:11:32 +00:00
// Section {
// NavigationLink(destination: EmptyView()) {
// Text("delete_account")
// .foregroundColor(.red)
// }
// }
}
}
}
#if DEBUG
struct ProfileView_Previews: PreviewProvider {
static var previews: some View {
ProfileView()
2022-06-07 00:11:32 +00:00
.environmentObject(DataStore(TwigsInMemoryCacheService()))
}
}
#endif