From e2e2c4e2b9f346192e7c1154ebc062f2fbb33208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qian=20Qian=20=22Cubik=22=E2=80=8E?= Date: Thu, 27 Apr 2023 22:49:59 -0400 Subject: [PATCH 1/4] refactor(AccountsSettingsDetailsView): Replace Deprecated `Alert` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Qian Qian "Cubik"‎ --- .../AccountsSettingsDetailsView.swift | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift index 78d6e35c86..9cbe9c4a14 100644 --- a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift +++ b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift @@ -55,14 +55,21 @@ struct AccountsSettingsDetailsView: View { Button("Delete Account...") { deleteConfirmationIsPresented.toggle() } - .alert(isPresented: $deleteConfirmationIsPresented) { - Alert( - title: Text("Are you sure you want to delete the account “\(account.description)”?"), - message: Text("Deleting this account will remove it from CodeEdit."), - primaryButton: .default(Text("OK")), - secondaryButton: .default(Text("Cancel")) - ) + .alert( + Text("Are you sure you want to delete the account “\(account.description)”?"), + isPresented: $deleteConfirmationIsPresented + ) { + Button("OK") { + // Handle the account delete + } + Button("Cancel") { + // Handle the cancel, dismiss the alert + deleteConfirmationIsPresented.toggle() + } + } message: { + Text("Deleting this account will remove it from CodeEdit.") } + Spacer() } .padding(.top, 10) From 5a522a08da160cc4dce016bbf773c9365a8fb18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qian=20Qian=20=22Cubik=22=E2=80=8E?= Date: Thu, 27 Apr 2023 23:01:49 -0400 Subject: [PATCH 2/4] fix(AccountsSettingsDetailsView): Handle properly account delete --- .../AccountsSettings/AccountsSettingsDetailsView.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift index 9cbe9c4a14..6ec561fcc1 100644 --- a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift +++ b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift @@ -61,6 +61,7 @@ struct AccountsSettingsDetailsView: View { ) { Button("OK") { // Handle the account delete + handleAccountDelete() } Button("Cancel") { // Handle the cancel, dismiss the alert @@ -77,4 +78,11 @@ struct AccountsSettingsDetailsView: View { } } } + + private func handleAccountDelete() { + let gitAccounts = settings.accounts.sourceControlAccounts.gitAccounts + // Delete account by finding the position of the account and remove by position + // We can abort if it is `nil` because account should exist + settings.accounts.sourceControlAccounts.gitAccounts.remove(at: gitAccounts.firstIndex(of: account)!) + } } From 05c1e09b6eedf5c6f6f3e9dcfbdcd58308036633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qian=20Qian=20=22Cubik=22=E2=80=8E?= Date: Thu, 27 Apr 2023 23:26:42 -0400 Subject: [PATCH 3/4] feat(AccountsSettingsDetailsView): Redirects user back to the accounts list after account delete --- .../Pages/AccountsSettings/AccountsSettingsDetailsView.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift index 6ec561fcc1..d0275aeeac 100644 --- a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift +++ b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift @@ -12,6 +12,8 @@ struct AccountsSettingsDetailsView: View { @Binding var account: SourceControlAccount + @Environment(\.presentationMode) var presentationMode: Binding + @State var cloneUsing: Bool = false @State var deleteConfirmationIsPresented: Bool = false @@ -84,5 +86,6 @@ struct AccountsSettingsDetailsView: View { // Delete account by finding the position of the account and remove by position // We can abort if it is `nil` because account should exist settings.accounts.sourceControlAccounts.gitAccounts.remove(at: gitAccounts.firstIndex(of: account)!) + self.presentationMode.wrappedValue.dismiss() } } From 3ab495eaa202d391a9e8a04973fa0c73ba121984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qian=20Qian=20=22Cubik=22=E2=80=8E?= Date: Thu, 27 Apr 2023 23:31:18 -0400 Subject: [PATCH 4/4] refactor(AccountsSettingsDetailsView): Use `dismiss` instead of deprecated PresentationMode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Qian Qian "Cubik"‎ --- .../Pages/AccountsSettings/AccountsSettingsDetailsView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift index d0275aeeac..cc682d7832 100644 --- a/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift +++ b/CodeEdit/Features/Settings/Pages/AccountsSettings/AccountsSettingsDetailsView.swift @@ -12,7 +12,7 @@ struct AccountsSettingsDetailsView: View { @Binding var account: SourceControlAccount - @Environment(\.presentationMode) var presentationMode: Binding + @Environment(\.dismiss) private var dismiss @State var cloneUsing: Bool = false @State var deleteConfirmationIsPresented: Bool = false @@ -64,6 +64,7 @@ struct AccountsSettingsDetailsView: View { Button("OK") { // Handle the account delete handleAccountDelete() + dismiss() } Button("Cancel") { // Handle the cancel, dismiss the alert @@ -86,6 +87,5 @@ struct AccountsSettingsDetailsView: View { // Delete account by finding the position of the account and remove by position // We can abort if it is `nil` because account should exist settings.accounts.sourceControlAccounts.gitAccounts.remove(at: gitAccounts.firstIndex(of: account)!) - self.presentationMode.wrappedValue.dismiss() } }