Skip to content

Commit

Permalink
feat: Snackbar take boolean to display
Browse files Browse the repository at this point in the history
  • Loading branch information
lebojo committed Nov 20, 2024
1 parent 6799bc6 commit 0cfaff3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
22 changes: 7 additions & 15 deletions MailCore/Cache/DraftManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ public final class DraftManager {
// show error if needed
else {
guard error.shouldDisplay else { return }
if showSnackbar {
alertDisplayable.show(message: error.localizedDescription)
}
alertDisplayable.show(message: error.localizedDescription, shouldShow: showSnackbar)
}
}
await draftQueue.endBackgroundTask(uuid: draft.localUUID)
Expand Down Expand Up @@ -131,12 +129,10 @@ public final class DraftManager {

public func sendOrSchedule(draft initialDraft: Draft, mailboxManager: MailboxManager, retry: Bool = true,
showSnackbar: Bool, changeFolderAction: ((Folder) -> Void)?) async -> Date? {
if showSnackbar {
if initialDraft.action == .schedule {
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarScheduling)
} else {
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSending)
}
if initialDraft.action == .schedule {
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarScheduling, shouldShow: showSnackbar)
} else {
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSending, shouldShow: showSnackbar)
}

var sendDate: Date?
Expand All @@ -149,9 +145,7 @@ public final class DraftManager {
if draft.action == .send {
let sendResponse = try await mailboxManager.send(draft: draft)
sendDate = sendResponse.scheduledDate
if showSnackbar {
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSent)
}
alertDisplayable.show(message: MailResourcesStrings.Localizable.snackbarEmailSent, shouldShow: showSnackbar)
} else if draft.action == .schedule {
let draft = removeDelay(draft: draft)
let scheduleResponse = try await mailboxManager.schedule(draft: draft)
Expand Down Expand Up @@ -182,9 +176,7 @@ public final class DraftManager {
)
}

if showSnackbar {
alertDisplayable.show(message: error.localizedDescription)
}
alertDisplayable.show(message: error.localizedDescription, shouldShow: showSnackbar)
}
await draftQueue.endBackgroundTask(uuid: draft.localUUID)
return sendDate
Expand Down
11 changes: 11 additions & 0 deletions MailCore/Utils/UserAlertDisplayable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public protocol UserAlertDisplayable {
/// - message: The message to display
/// - action: Title and closure associated with the action
func show(message: String, action: UserAlertAction)

/// Will present a snackbar while main app is opened, a local notification in Extension or Background.
/// - Parameters:
/// - message: The message to display
/// - shouldShow: The boolean to show or not the snackbar
func show(message: String, shouldShow: Bool)
}

public typealias UserAlertAction = (name: String, closure: () -> Void)
Expand All @@ -59,6 +65,11 @@ public final class UserAlertDisplayer: UserAlertDisplayable {
showInContext(message: message, action: action)
}

public func show(message: String, shouldShow: Bool) {
guard shouldShow else { return }
show(message: message)
}

// MARK: - private

private func showInContext(message: String, action: UserAlertAction?) {
Expand Down

0 comments on commit 0cfaff3

Please sign in to comment.