From ee90b20f7fa405b0e5b8d946053cb6e7d2da79b3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 16 Sep 2020 22:17:20 -0400 Subject: [PATCH] Add swipe to remove accounts in Preferences --- Tusker/Screens/Preferences/PreferencesView.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) }) {