Skip to content

Commit

Permalink
fix: Wrap toolbar actions in tryOrDisplayError
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Sep 13, 2023
1 parent 7d77f66 commit 61069ed
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Mail/Views/Thread/ThreadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ struct ThreadView: View {
.multilineTextAlignment(.leading)
.lineSpacing(8)

let externalTag = thread.displayExternalRecipientState(mailboxManager: mailboxManager, recipientsList: thread.from)
let externalTag = thread.displayExternalRecipientState(
mailboxManager: mailboxManager,
recipientsList: thread.from
)
switch externalTag {
case .many, .one:
Button {
Expand Down Expand Up @@ -121,11 +124,13 @@ struct ThreadView: View {
let messages = thread.messages.freeze().toArray()
let originFolder = thread.folder?.freezeIfNeeded()
Task {
try await actionsManager.performAction(
target: messages,
action: thread.flagged ? .unstar : .star,
origin: .toolbar(originFolder: originFolder)
)
await tryOrDisplayError {
try await actionsManager.performAction(
target: messages,
action: thread.flagged ? .unstar : .star,
origin: .toolbar(originFolder: originFolder)
)
}
}
} label: {
(thread.flagged ? MailResourcesAsset.starFull : MailResourcesAsset.star).swiftUIImage
Expand Down Expand Up @@ -177,7 +182,7 @@ struct ThreadView: View {

private func markThreadAsReadIfNeeded(thread: Thread) async {
guard thread.hasUnseenMessages else { return }

let originFolder = thread.folder?.freezeIfNeeded()
try? await actionsManager.performAction(
target: thread.messages.toArray(),
Expand All @@ -200,13 +205,15 @@ struct ThreadView: View {

let originFolder = thread.folder?.freezeIfNeeded()
Task {
try await actionsManager.performAction(
target: messages,
action: action,
origin: .toolbar(originFolder: originFolder)
)
if action == .archive || action == .delete {
dismiss()
await tryOrDisplayError {
try await actionsManager.performAction(
target: messages,
action: action,
origin: .toolbar(originFolder: originFolder)
)
if action == .archive || action == .delete {
dismiss()
}
}
}
}
Expand Down

0 comments on commit 61069ed

Please sign in to comment.