diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index 65e54cff33..da5ab0a90b 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -37,7 +37,21 @@ struct PreferencesView: View { } } } + }.onDelete { (indices: IndexSet) in + var indices = indices + var logoutFromCurrent = false + if let index = indices.first(where: { localData.accounts[$0] == localData.getMostRecentAccount() }) { + logoutFromCurrent = true + indices.remove(index) + } + + localData.accounts.remove(atOffsets: indices) + + if logoutFromCurrent { + self.logoutPressed() + } } + Button(action: { NotificationCenter.default.post(name: .addAccount, object: nil) }) {