forked from shadowfacts/Tusker
Fix preferences not checking current account correctly when multiple scenes open
This commit is contained in:
parent
a13d5d5a82
commit
77c9fac3ce
|
@ -14,7 +14,7 @@ class PreferencesNavigationController: UINavigationController {
|
|||
private var isSwitchingAccounts = false
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
let view = PreferencesView()
|
||||
let view = PreferencesView(mastodonController: mastodonController)
|
||||
let hostingController = UIHostingController(rootView: view)
|
||||
super.init(rootViewController: hostingController)
|
||||
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
||||
|
|
|
@ -8,9 +8,14 @@
|
|||
import SwiftUI
|
||||
|
||||
struct PreferencesView: View {
|
||||
let mastodonController: MastodonController
|
||||
@ObservedObject var localData = LocalData.shared
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||
// NavigationView {
|
||||
|
@ -30,7 +35,7 @@ struct PreferencesView: View {
|
|||
.foregroundColor(.primary)
|
||||
}
|
||||
Spacer()
|
||||
if account == self.localData.getMostRecentAccount() {
|
||||
if account == mastodonController.accountInfo! {
|
||||
Image(systemName: "checkmark")
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(.secondary)
|
||||
|
@ -43,7 +48,7 @@ struct PreferencesView: View {
|
|||
}.onDelete { (indices: IndexSet) in
|
||||
var indices = indices
|
||||
var logoutFromCurrent = false
|
||||
if let index = indices.first(where: { localData.accounts[$0] == localData.getMostRecentAccount() }) {
|
||||
if let index = indices.first(where: { localData.accounts[$0] == mastodonController.accountInfo! }) {
|
||||
logoutFromCurrent = true
|
||||
indices.remove(index)
|
||||
}
|
||||
|
@ -102,10 +107,10 @@ struct PreferencesView: View {
|
|||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct PreferencesView_Previews : PreviewProvider {
|
||||
static var previews: some View {
|
||||
return PreferencesView()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//#if DEBUG
|
||||
//struct PreferencesView_Previews : PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// return PreferencesView()
|
||||
// }
|
||||
//}
|
||||
//#endif
|
||||
|
|
Loading…
Reference in New Issue