2019-10-19 22:18:06 +00:00
|
|
|
//
|
|
|
|
// ProfileView.swift
|
2021-09-21 03:10:24 +00:00
|
|
|
// Twigs
|
2019-10-19 22:18:06 +00:00
|
|
|
//
|
|
|
|
// 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
|
2019-10-19 22:18:06 +00:00
|
|
|
|
|
|
|
struct ProfileView: View {
|
2022-05-18 01:04:27 +00:00
|
|
|
@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
|
|
|
|
2022-05-18 01:04:27 +00:00
|
|
|
@ViewBuilder
|
2019-10-19 22:18:06 +00:00
|
|
|
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")
|
|
|
|
}
|
2021-09-15 03:22:14 +00:00
|
|
|
}
|
2022-06-07 00:11:32 +00:00
|
|
|
Section {
|
|
|
|
Button("logout", action: {
|
|
|
|
// TODO: Show some dialog to confirm
|
|
|
|
dataStore.logout()
|
|
|
|
})
|
2019-10-19 22:18:06 +00:00
|
|
|
}
|
2022-06-07 00:11:32 +00:00
|
|
|
// Section {
|
|
|
|
// NavigationLink(destination: EmptyView()) {
|
|
|
|
// Text("delete_account")
|
|
|
|
// .foregroundColor(.red)
|
|
|
|
// }
|
|
|
|
// }
|
2019-10-19 22:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
struct ProfileView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-06 01:26:54 +00:00
|
|
|
ProfileView()
|
2022-06-07 00:11:32 +00:00
|
|
|
.environmentObject(DataStore(TwigsInMemoryCacheService()))
|
2019-10-19 22:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|