diff --git a/Mail/Components/Buttons/ModalButtonsView.swift b/Mail/Components/Buttons/ModalButtonsView.swift index e79f5d0ef..fc9fb6afa 100644 --- a/Mail/Components/Buttons/ModalButtonsView.swift +++ b/Mail/Components/Buttons/ModalButtonsView.swift @@ -23,10 +23,12 @@ import SwiftUI struct ModalButtonsView: View { @Environment(\.dismiss) private var dismiss + @State var isButtonLoading = false + let primaryButtonTitle: String var secondaryButtonTitle: String? = MailResourcesStrings.Localizable.buttonCancel var primaryButtonEnabled = true - let primaryButtonAction: () -> Void + let primaryButtonAction: () async -> Void var secondaryButtonAction: (() -> Void)? var body: some View { @@ -40,10 +42,15 @@ struct ModalButtonsView: View { } MailButton(label: primaryButtonTitle) { - primaryButtonAction() - dismiss() + Task { + isButtonLoading = true + await primaryButtonAction() + isButtonLoading = false + dismiss() + } } .disabled(!primaryButtonEnabled) + .mailButtonLoading(isButtonLoading) } .frame(maxWidth: .infinity, alignment: .trailing) } diff --git a/Mail/Views/Alerts/CreateFolderView.swift b/Mail/Views/Alerts/CreateFolderView.swift index d4aca25c9..79551adc0 100644 --- a/Mail/Views/Alerts/CreateFolderView.swift +++ b/Mail/Views/Alerts/CreateFolderView.swift @@ -92,13 +92,11 @@ struct CreateFolderView: View { ModalButtonsView(primaryButtonTitle: mode.buttonTitle, primaryButtonEnabled: buttonIsEnabled) { @InjectService var matomo: MatomoUtils matomo.track(eventWithCategory: .createFolder, name: "confirm") - Task { - await tryOrDisplayError { - let folder = try await mailboxManager.createFolder(name: folderName) - if case .move(let moveHandler) = mode { - moveHandler(folder) - NotificationCenter.default.post(Notification(name: .dismissMoveSheetNotificationName)) - } + await tryOrDisplayError { + let folder = try await mailboxManager.createFolder(name: folderName) + if case .move(let moveHandler) = mode { + moveHandler(folder) + NotificationCenter.default.post(Notification(name: .dismissMoveSheetNotificationName)) } } } diff --git a/Mail/Views/Alerts/DetachMailboxConfirmationView.swift b/Mail/Views/Alerts/DetachMailboxConfirmationView.swift index 75a68b1c2..7be4284dd 100644 --- a/Mail/Views/Alerts/DetachMailboxConfirmationView.swift +++ b/Mail/Views/Alerts/DetachMailboxConfirmationView.swift @@ -56,15 +56,12 @@ struct DetachMailboxConfirmationView: View { } } - private func detach() { + private func detach() async { @InjectService var matomo: MatomoUtils matomo.track(eventWithCategory: .invalidPasswordMailbox, name: "detachMailboxConfirm") - - Task { - await tryOrDisplayError { - try await accountManager.detachMailbox(mailbox: mailbox) - navigationState.transitionToRootViewDestination(.mainView) - } + await tryOrDisplayError { + try await accountManager.detachMailbox(mailbox: mailbox) + navigationState.transitionToRootViewDestination(.mainView) } } } diff --git a/Mail/Views/Alerts/LogoutConfirmationView.swift b/Mail/Views/Alerts/LogoutConfirmationView.swift index d8b674247..4c3b224a5 100644 --- a/Mail/Views/Alerts/LogoutConfirmationView.swift +++ b/Mail/Views/Alerts/LogoutConfirmationView.swift @@ -41,19 +41,17 @@ struct LogoutConfirmationView: View { } } - private func logout() { + private func logout() async { @InjectService var matomo: MatomoUtils matomo.track(eventWithCategory: .account, name: "logOutConfirm") - Task { - @InjectService var notificationService: InfomaniakNotifications - await notificationService.removeStoredTokenFor(userId: account.userId) + @InjectService var notificationService: InfomaniakNotifications + await notificationService.removeStoredTokenFor(userId: account.userId) - accountManager.removeTokenAndAccount(account: account) - if let nextAccount = accountManager.accounts.first { - accountManager.switchAccount(newAccount: nextAccount) - } - accountManager.saveAccounts() + accountManager.removeTokenAndAccount(account: account) + if let nextAccount = accountManager.accounts.first { + accountManager.switchAccount(newAccount: nextAccount) } + accountManager.saveAccounts() } } diff --git a/Mail/Views/Alerts/ReportPhishingView.swift b/Mail/Views/Alerts/ReportPhishingView.swift index 9a037023f..245c83700 100644 --- a/Mail/Views/Alerts/ReportPhishingView.swift +++ b/Mail/Views/Alerts/ReportPhishingView.swift @@ -40,16 +40,14 @@ struct ReportPhishingView: View { } } - private func report() { - Task { - await tryOrDisplayError { - let response = try await mailboxManager.apiFetcher.reportPhishing(message: message) - if response { - var messages = [message.freezeIfNeeded()] - messages.append(contentsOf: message.duplicates) - _ = try await mailboxManager.move(messages: messages, to: .spam) - await snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarReportPhishingConfirmation) - } + private func report() async { + await tryOrDisplayError { + let response = try await mailboxManager.apiFetcher.reportPhishing(message: message) + if response { + var messages = [message.freezeIfNeeded()] + messages.append(contentsOf: message.duplicates) + _ = try await mailboxManager.move(messages: messages, to: .spam) + snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarReportPhishingConfirmation) } } } diff --git a/Mail/Views/Bottom sheets/ReportDisplayProblemView.swift b/Mail/Views/Bottom sheets/ReportDisplayProblemView.swift index fd964c324..9660d3c76 100644 --- a/Mail/Views/Bottom sheets/ReportDisplayProblemView.swift +++ b/Mail/Views/Bottom sheets/ReportDisplayProblemView.swift @@ -45,20 +45,18 @@ struct ReportDisplayProblemView: View { .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "ReportDisplayProblemView"]) } - private func report() { - Task { - await tryOrDisplayError { - // Download message - let fileURL = try await mailboxManager.apiFetcher.download(message: message) - // Send it via Sentry - let fileAttachment = Attachment(path: fileURL.path, - filename: fileURL.lastPathComponent, - contentType: "message/rfc822") - _ = SentrySDK.capture(message: "Message display problem reported") { scope in - scope.add(fileAttachment) - } - snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarDisplayProblemReported) + private func report() async { + await tryOrDisplayError { + // Download message + let fileURL = try await mailboxManager.apiFetcher.download(message: message) + // Send it via Sentry + let fileAttachment = Attachment(path: fileURL.path, + filename: fileURL.lastPathComponent, + contentType: "message/rfc822") + _ = SentrySDK.capture(message: "Message display problem reported") { scope in + scope.add(fileAttachment) } + snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarDisplayProblemReported) } } } diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index 7832c7090..2fc7a94bf 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -71,13 +71,11 @@ struct RestoreEmailsView: View { .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } - private func restoreEmails() { + private func restoreEmails() async { matomo.track(eventWithCategory: .restoreEmailsBottomSheet, name: "restore") - Task { - await tryOrDisplayError { - try await mailboxManager.apiFetcher.restoreBackup(mailbox: mailboxManager.mailbox, date: selectedDate) - snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarRestorationLaunched) - } + await tryOrDisplayError { + try await mailboxManager.apiFetcher.restoreBackup(mailbox: mailboxManager.mailbox, date: selectedDate) + snackbarPresenter.show(message: MailResourcesStrings.Localizable.snackbarRestorationLaunched) } } diff --git a/Mail/Views/Thread List/FlushFolderAlertView.swift b/Mail/Views/Thread List/FlushFolderAlertView.swift index f976fae90..d9fdec074 100644 --- a/Mail/Views/Thread List/FlushFolderAlertView.swift +++ b/Mail/Views/Thread List/FlushFolderAlertView.swift @@ -60,9 +60,7 @@ struct FlushFolderAlertView: View { @InjectService var matomo: MatomoUtils matomo.track(eventWithCategory: .threadList, name: "empty\(folder.matomoName.capitalized)Confirm") } - Task { - await flushAlert.completion() - } + await flushAlert.completion() } } } diff --git a/Mail/Views/Unavailable Mailbox/UpdateMailboxPasswordView.swift b/Mail/Views/Unavailable Mailbox/UpdateMailboxPasswordView.swift index 2e29f6dc8..56c68a9bd 100644 --- a/Mail/Views/Unavailable Mailbox/UpdateMailboxPasswordView.swift +++ b/Mail/Views/Unavailable Mailbox/UpdateMailboxPasswordView.swift @@ -99,6 +99,7 @@ struct UpdateMailboxPasswordView: View { } .mailButtonFullWidth(true) .disabled(disableButton) + .mailButtonLoading(isLoading) MailButton(label: MailResourcesStrings.Localizable.buttonRequestPassword) { matomo.track(eventWithCategory: .invalidPasswordMailbox, name: "requestPassword")