Skip to content

Commit

Permalink
add ProfileSettingsView
Browse files Browse the repository at this point in the history
  • Loading branch information
kloenk committed Mar 30, 2022
1 parent 2361540 commit 9f087fa
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NioUIKit/Menu/MenuOwnAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct MenuOwnAccountView: View {
VStack(alignment: .leading) {
ForEach(accounts, id: \.userID) { account in
NavigationLink(destination: {
Text("Account")
ProfileSettingsContainerView(account: account)
}) {
MenuAccountPickerAccountView(account: account)
}
Expand Down
115 changes: 115 additions & 0 deletions NioUIKit/ProfileSettings/ProfileSettingsContainerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// ProfileSettingsContainerView.swift
// NioUIKit_iOS
//
// Created by Finn Behrens on 30.03.22.
//

import MatrixCore
import SwiftUI

struct ProfileSettingsContainerView: View {
@ObservedObject var account: MatrixAccount

@Environment(\.dismiss) private var dismiss

var body: some View {
List {
Section(header: Text("USER SETTINGS")) {
// TODO: Profile Picture

// Display Name
HStack {
Text("Display Name")
Spacer(minLength: 20)

TextField("Display Name", text: $account.wrappedDisplayName)
.multilineTextAlignment(.trailing)
}

// Password
Button("Change password", role: .destructive) {
print("TODO: implement change password")
}
}

Section(header: Text("SECURITY")) {
NavigationLink("Security") {
VStack {
Text("Device id's and fun")
}
.navigationTitle("Security")
}
}

ProfileSettingsDangerZone(account: account)
}
.navigationTitle(account.displayName ?? account.userID ?? "Settings")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem {
Button(action: {
print("saving...")
// TODO: save to CoreData
dismiss()
}) {
Text("Save")
}
.disabled(!account.hasChanges)
}
}
.onDisappear {
print("discarding")
}
}
}

struct ProfileSettingsDangerZone: View {
@ObservedObject var account: MatrixAccount

@Environment(\.dismiss) private var dismiss

@State private var showSignOutDialog: Bool = false
@State private var showDeactivateDialog: Bool = false

var body: some View {
Section(header: Text("DANGER ZONE")) {
Button("Sign Out") {
showSignOutDialog = true
}
.disabled(showSignOutDialog)
.confirmationDialog("Are you sure you want to sign out?", isPresented: $showSignOutDialog, titleVisibility: .visible) {
Button("Sign out", role: .destructive) {
print("TODO: implement sign out")
// TODO:
}
}

Button("Deactivate my account", role: .destructive) {
showDeactivateDialog = true
}
.disabled(showDeactivateDialog)
.confirmationDialog("Are you sure you want to disable your account? This cannot be undone", isPresented: $showDeactivateDialog, titleVisibility: .visible) {
Text("This cannot be undone")
.font(.headline)
.foregroundColor(.red)
Button("Deactivate", role: .destructive) {
print("TODO: deactivate account")
// TODO:
}
}
}
}
}

struct ProfileSettingsContainerView_Previews: PreviewProvider {
static let account: MatrixAccount = MatrixStore.createAmir(context: MatrixStore.preview.viewContext)

static var previews: some View {
Group {
NavigationView {
ProfileSettingsContainerView(account: ProfileSettingsContainerView_Previews.account)
}
}
}
}

0 comments on commit 9f087fa

Please sign in to comment.