Cleanup PreferencesView
This commit is contained in:
parent
76268e7a14
commit
af8a9faaeb
|
@ -6,11 +6,11 @@
|
|||
//
|
||||
|
||||
import SwiftUI
|
||||
import TTTKit
|
||||
|
||||
struct PreferencesView: View {
|
||||
let mastodonController: MastodonController
|
||||
@ObservedObject var localData = LocalData.shared
|
||||
|
||||
@ObservedObject private var localData = LocalData.shared
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
|
@ -18,10 +18,18 @@ struct PreferencesView: View {
|
|||
}
|
||||
|
||||
var body: some View {
|
||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||
// NavigationView {
|
||||
List {
|
||||
Section(header: Text("Accounts")) {
|
||||
accountsSection
|
||||
preferencesSection
|
||||
aboutSection
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
.navigationBarTitle("Preferences")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
|
||||
private var accountsSection: some View {
|
||||
Section {
|
||||
ForEach(localData.accounts, id: \.accessToken) { (account) in
|
||||
Button(action: {
|
||||
NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account])
|
||||
|
@ -66,7 +74,6 @@ struct PreferencesView: View {
|
|||
}) {
|
||||
Text("Add Account...")
|
||||
}
|
||||
if localData.getMostRecentAccount() != nil {
|
||||
Button(action: {
|
||||
self.showingLogoutConfirmation = true
|
||||
}) {
|
||||
|
@ -74,9 +81,12 @@ struct PreferencesView: View {
|
|||
}.alert(isPresented: $showingLogoutConfirmation) {
|
||||
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
|
||||
}
|
||||
} header: {
|
||||
Text("Accounts")
|
||||
}
|
||||
}
|
||||
|
||||
private var preferencesSection: some View {
|
||||
Section {
|
||||
NavigationLink(destination: AppearancePrefsView()) {
|
||||
Text("Appearance")
|
||||
|
@ -97,7 +107,9 @@ struct PreferencesView: View {
|
|||
Text("Advanced")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var aboutSection: some View {
|
||||
Section {
|
||||
NavigationLink("About") {
|
||||
AboutView()
|
||||
|
@ -110,10 +122,6 @@ struct PreferencesView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
|
||||
// }
|
||||
}
|
||||
|
||||
func logoutPressed() {
|
||||
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import UIKit
|
||||
import Pachyderm
|
||||
import SwiftUI
|
||||
|
||||
class MyProfileViewController: ProfileViewController {
|
||||
|
||||
|
|
Loading…
Reference in New Issue