Skip to content

Commit

Permalink
feat: Add loader when save in kdrive
Browse files Browse the repository at this point in the history
  • Loading branch information
lebojo committed Nov 14, 2024
1 parent 2338a8b commit 4417180
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
27 changes: 20 additions & 7 deletions Mail/Views/Bottom sheets/Actions/ActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ struct MessageActionView: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject private var actionsManager: ActionsManager

@State private var isLoading = false

let targetMessages: [Message]
let action: Action
let origin: ActionOrigin
var completionHandler: ((Action) -> Void)?

var body: some View {
Button {
dismiss()
if action.shouldDismiss {
dismiss()
} else {
isLoading = true
}
Task {
await tryOrDisplayError {
try await actionsManager.performAction(
Expand All @@ -156,16 +162,18 @@ struct MessageActionView: View {
)
completionHandler?(action)
}
isLoading = false
}
} label: {
ActionButtonLabel(action: action)
ActionButtonLabel(action: action, isLoading: isLoading)
}
.accessibilityIdentifier(action.accessibilityIdentifier)
}
}

struct ActionButtonLabel: View {
let action: Action
var isLoading = false

var iconColor: MailResourcesColors {
switch action {
Expand All @@ -191,11 +199,16 @@ struct ActionButtonLabel: View {

var body: some View {
HStack(spacing: IKPadding.medium) {
action.icon
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
.foregroundStyle(iconColor)
if isLoading {
ProgressView()
.frame(width: 24, height: 24)
} else {
action.icon
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
.foregroundStyle(iconColor)
}
Text(action.title)
.foregroundStyle(titleColor)
.textStyle(.body)
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Thread List/ThreadListModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct ThreadListToolbar: ViewModifier {
panelSource: .threadList,
popoverArrowEdge: .bottom
) { action in
guard action != .openMovePanel else { return }
guard action.shouldDisableMultipleSelection else { return }
multipleSelectionViewModel.disable()
}
}
Expand Down
8 changes: 8 additions & 0 deletions MailCore/Cache/Actions/Action+List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ extension Action: CaseIterable {
}
}

public var shouldDismiss: Bool {
return ![.saveThreadInkDrive].contains(self)
}

public var shouldDisableMultipleSelection: Bool {
return ![.openMovePanel, .saveThreadInkDrive].contains(self)
}

private static func actionsForMessage(_ message: Message, origin: ActionOrigin,
userIsStaff: Bool) -> (quickActions: [Action], listActions: [Action]) {
@LazyInjectService var platformDetector: PlatformDetectable
Expand Down
4 changes: 2 additions & 2 deletions MailCore/Cache/Actions/ActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ public class ActionsManager: ObservableObject {
guard !platformDetector.isMac else {
return
}
Task { @MainActor in
await Task { @MainActor in
do {
let filesURL = try await mailboxManager.apiFetcher.download(messages: messages)
try DeeplinkService().shareFilesToKdrive(filesURL)
} catch {
SentrySDK.capture(error: error)
}
}
}.value
case .shareMailLink:
guard let message = messagesWithDuplicates.first else { return }
let result = try await mailboxManager.apiFetcher.shareMailLink(message: message)
Expand Down

0 comments on commit 4417180

Please sign in to comment.