diff --git a/Tusker/Screens/Preferences/PreferencesNavigationController.swift b/Tusker/Screens/Preferences/PreferencesNavigationController.swift index 910b413f..78d78b3e 100644 --- a/Tusker/Screens/Preferences/PreferencesNavigationController.swift +++ b/Tusker/Screens/Preferences/PreferencesNavigationController.swift @@ -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)) diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index ac876ab1..d01eba3e 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -8,8 +8,13 @@ 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 @@ -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