Skip to content

Commit dd89f70

Browse files
committed
add ProfileSettingsView
1 parent 4150067 commit dd89f70

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

NioUIKit/Menu/MenuOwnAccountView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct MenuOwnAccountView: View {
3131
VStack(alignment: .leading) {
3232
ForEach(accounts, id: \.userID) { account in
3333
NavigationLink(destination: {
34-
Text("Account")
34+
ProfileSettingsContainerView(account: account)
3535
}) {
3636
MenuAccountPickerAccountView(account: account)
3737
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//
2+
// ProfileSettingsContainerView.swift
3+
// NioUIKit_iOS
4+
//
5+
// Created by Finn Behrens on 30.03.22.
6+
//
7+
8+
import MatrixCore
9+
import SwiftUI
10+
11+
struct ProfileSettingsContainerView: View {
12+
@ObservedObject var account: MatrixAccount
13+
14+
@Environment(\.dismiss) private var dismiss
15+
16+
var body: some View {
17+
List {
18+
Section(header: Text("USER SETTINGS")) {
19+
// TODO: Profile Picture
20+
21+
// Display Name
22+
HStack {
23+
Text("Display Name")
24+
Spacer(minLength: 20)
25+
26+
TextField("Display Name", text: $account.wrappedDisplayName)
27+
.multilineTextAlignment(.trailing)
28+
}
29+
30+
// Password
31+
Button("Change password", role: .destructive) {
32+
print("TODO: implement change password")
33+
}
34+
}
35+
36+
Section(header: Text("SECURITY")) {
37+
NavigationLink("Security") {
38+
VStack {
39+
Text("Device id's and fun")
40+
}
41+
.navigationTitle("Security")
42+
}
43+
}
44+
45+
ProfileSettingsDangerZone(account: account)
46+
}
47+
.navigationTitle(account.displayName ?? account.userID ?? "Settings")
48+
.navigationBarTitleDisplayMode(.inline)
49+
.toolbar {
50+
ToolbarItem {
51+
Button(action: {
52+
print("saving...")
53+
// TODO: save to CoreData
54+
dismiss()
55+
}) {
56+
Text("Save")
57+
}
58+
.disabled(!account.hasChanges)
59+
}
60+
}
61+
.onDisappear {
62+
print("discarding")
63+
}
64+
}
65+
}
66+
67+
struct ProfileSettingsDangerZone: View {
68+
@ObservedObject var account: MatrixAccount
69+
70+
@Environment(\.dismiss) private var dismiss
71+
72+
@State private var showSignOutDialog: Bool = false
73+
@State private var showDeactivateDialog: Bool = false
74+
75+
var body: some View {
76+
Section(header: Text("DANGER ZONE")) {
77+
Button("Sign Out") {
78+
showSignOutDialog = true
79+
}
80+
.disabled(showSignOutDialog)
81+
.confirmationDialog("Are you sure you want to sign out?", isPresented: $showSignOutDialog, titleVisibility: .visible) {
82+
Button("Sign out", role: .destructive) {
83+
print("TODO: implement sign out")
84+
// TODO:
85+
}
86+
}
87+
88+
Button("Deactivate my account", role: .destructive) {
89+
showDeactivateDialog = true
90+
}
91+
.disabled(showDeactivateDialog)
92+
.confirmationDialog("Are you sure you want to disable your account? This cannot be undone", isPresented: $showDeactivateDialog, titleVisibility: .visible) {
93+
Text("This cannot be undone")
94+
.font(.headline)
95+
.foregroundColor(.red)
96+
Button("Deactivate", role: .destructive) {
97+
print("TODO: deactivate account")
98+
// TODO:
99+
}
100+
}
101+
}
102+
}
103+
}
104+
105+
struct ProfileSettingsContainerView_Previews: PreviewProvider {
106+
static let account: MatrixAccount = MatrixStore.createAmir(context: MatrixStore.preview.viewContext)
107+
108+
static var previews: some View {
109+
Group {
110+
NavigationView {
111+
ProfileSettingsContainerView(account: ProfileSettingsContainerView_Previews.account)
112+
}
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)