Cleanup PreferencesView
This commit is contained in:
parent
76268e7a14
commit
af8a9faaeb
|
@ -6,11 +6,11 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import TTTKit
|
|
||||||
|
|
||||||
struct PreferencesView: View {
|
struct PreferencesView: View {
|
||||||
let mastodonController: MastodonController
|
let mastodonController: MastodonController
|
||||||
@ObservedObject var localData = LocalData.shared
|
|
||||||
|
@ObservedObject private var localData = LocalData.shared
|
||||||
@State private var showingLogoutConfirmation = false
|
@State private var showingLogoutConfirmation = false
|
||||||
|
|
||||||
init(mastodonController: MastodonController) {
|
init(mastodonController: MastodonController) {
|
||||||
|
@ -18,101 +18,109 @@ struct PreferencesView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
List {
|
||||||
// NavigationView {
|
accountsSection
|
||||||
List {
|
preferencesSection
|
||||||
Section(header: Text("Accounts")) {
|
aboutSection
|
||||||
ForEach(localData.accounts, id: \.accessToken) { (account) in
|
}
|
||||||
Button(action: {
|
.listStyle(.insetGrouped)
|
||||||
NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account])
|
.navigationBarTitle("Preferences")
|
||||||
}) {
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
HStack {
|
}
|
||||||
LocalAccountAvatarView(localAccountInfo: account)
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text(verbatim: account.username)
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
Text(verbatim: account.instanceURL.host!)
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundColor(.primary)
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
if account == mastodonController.accountInfo! {
|
|
||||||
Image(systemName: "checkmark")
|
|
||||||
.renderingMode(.template)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.onDrag {
|
|
||||||
let activity = UserActivityManager.mainSceneActivity(accountID: account.id)
|
|
||||||
return NSItemProvider(object: activity)
|
|
||||||
}
|
|
||||||
}.onDelete { (indices: IndexSet) in
|
|
||||||
var indices = indices
|
|
||||||
var logoutFromCurrent = false
|
|
||||||
if let index = indices.first(where: { localData.accounts[$0] == mastodonController.accountInfo! }) {
|
|
||||||
logoutFromCurrent = true
|
|
||||||
indices.remove(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
indices.forEach { LogoutService(accountInfo: localData.accounts[$0]).run() }
|
private var accountsSection: some View {
|
||||||
|
Section {
|
||||||
if logoutFromCurrent {
|
ForEach(localData.accounts, id: \.accessToken) { (account) in
|
||||||
self.logoutPressed()
|
Button(action: {
|
||||||
}
|
NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account])
|
||||||
}
|
}) {
|
||||||
|
HStack {
|
||||||
Button(action: {
|
LocalAccountAvatarView(localAccountInfo: account)
|
||||||
NotificationCenter.default.post(name: .addAccount, object: nil)
|
VStack(alignment: .leading) {
|
||||||
}) {
|
Text(verbatim: account.username)
|
||||||
Text("Add Account...")
|
.foregroundColor(.primary)
|
||||||
}
|
Text(verbatim: account.instanceURL.host!)
|
||||||
if localData.getMostRecentAccount() != nil {
|
.font(.caption)
|
||||||
Button(action: {
|
.foregroundColor(.primary)
|
||||||
self.showingLogoutConfirmation = true
|
}
|
||||||
}) {
|
Spacer()
|
||||||
Text("Logout from current")
|
if account == mastodonController.accountInfo! {
|
||||||
}.alert(isPresented: $showingLogoutConfirmation) {
|
Image(systemName: "checkmark")
|
||||||
Alert(title: Text("Are you sure you want to logout?"), message: nil, primaryButton: .destructive(Text("Logout"), action: self.logoutPressed), secondaryButton: .cancel())
|
.renderingMode(.template)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.onDrag {
|
||||||
|
let activity = UserActivityManager.mainSceneActivity(accountID: account.id)
|
||||||
|
return NSItemProvider(object: activity)
|
||||||
|
}
|
||||||
|
}.onDelete { (indices: IndexSet) in
|
||||||
|
var indices = indices
|
||||||
|
var logoutFromCurrent = false
|
||||||
|
if let index = indices.first(where: { localData.accounts[$0] == mastodonController.accountInfo! }) {
|
||||||
|
logoutFromCurrent = true
|
||||||
|
indices.remove(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
indices.forEach { LogoutService(accountInfo: localData.accounts[$0]).run() }
|
||||||
NavigationLink(destination: AppearancePrefsView()) {
|
|
||||||
Text("Appearance")
|
|
||||||
}
|
|
||||||
NavigationLink(destination: ComposingPrefsView()) {
|
|
||||||
Text("Composing")
|
|
||||||
}
|
|
||||||
NavigationLink(destination: MediaPrefsView()) {
|
|
||||||
Text("Media")
|
|
||||||
}
|
|
||||||
NavigationLink(destination: BehaviorPrefsView()) {
|
|
||||||
Text("Behavior")
|
|
||||||
}
|
|
||||||
NavigationLink(destination: WellnessPrefsView()) {
|
|
||||||
Text("Digital Wellness")
|
|
||||||
}
|
|
||||||
NavigationLink(destination: AdvancedPrefsView()) {
|
|
||||||
Text("Advanced")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Section {
|
if logoutFromCurrent {
|
||||||
NavigationLink("About") {
|
self.logoutPressed()
|
||||||
AboutView()
|
|
||||||
}
|
|
||||||
NavigationLink("Tip Jar") {
|
|
||||||
TipJarView()
|
|
||||||
}
|
|
||||||
NavigationLink("Acknowledgements") {
|
|
||||||
AcknowledgementsView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(InsetGroupedListStyle())
|
|
||||||
.navigationBarTitle(Text("Preferences"), displayMode: .inline)
|
Button(action: {
|
||||||
// }
|
NotificationCenter.default.post(name: .addAccount, object: nil)
|
||||||
|
}) {
|
||||||
|
Text("Add Account...")
|
||||||
|
}
|
||||||
|
Button(action: {
|
||||||
|
self.showingLogoutConfirmation = true
|
||||||
|
}) {
|
||||||
|
Text("Logout from current")
|
||||||
|
}.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")
|
||||||
|
}
|
||||||
|
NavigationLink(destination: ComposingPrefsView()) {
|
||||||
|
Text("Composing")
|
||||||
|
}
|
||||||
|
NavigationLink(destination: MediaPrefsView()) {
|
||||||
|
Text("Media")
|
||||||
|
}
|
||||||
|
NavigationLink(destination: BehaviorPrefsView()) {
|
||||||
|
Text("Behavior")
|
||||||
|
}
|
||||||
|
NavigationLink(destination: WellnessPrefsView()) {
|
||||||
|
Text("Digital Wellness")
|
||||||
|
}
|
||||||
|
NavigationLink(destination: AdvancedPrefsView()) {
|
||||||
|
Text("Advanced")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var aboutSection: some View {
|
||||||
|
Section {
|
||||||
|
NavigationLink("About") {
|
||||||
|
AboutView()
|
||||||
|
}
|
||||||
|
NavigationLink("Tip Jar") {
|
||||||
|
TipJarView()
|
||||||
|
}
|
||||||
|
NavigationLink("Acknowledgements") {
|
||||||
|
AcknowledgementsView()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func logoutPressed() {
|
func logoutPressed() {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
class MyProfileViewController: ProfileViewController {
|
class MyProfileViewController: ProfileViewController {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue