Skip to content

Commit

Permalink
refactor: ReportJunkView native floatingPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Apr 27, 2023
1 parent 046f9ed commit ca9e27c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ActionsPanelViewModifier: ViewModifier {
@StateObject private var moveSheet = MoveSheet()

@Binding var actionsTarget: ActionsTarget?
@State var reportDisplayProblemMessage: Message?
@State var reportJunkActionsTarget: ActionsTarget?

var completionHandler: (() -> Void)?

Expand All @@ -43,7 +43,8 @@ struct ActionsPanelViewModifier: ViewModifier {
ActionsView(mailboxManager: mailboxManager,
target: target,
moveSheet: moveSheet,
messageReply: $navigationStore.messageReply) {
messageReply: $navigationStore.messageReply,
reportJunkActionsTarget: $reportJunkActionsTarget) {
completionHandler?()
}
}
Expand All @@ -52,8 +53,8 @@ struct ActionsPanelViewModifier: ViewModifier {
MoveEmailView.sheetView(from: folderId, moveHandler: handler)
}
}
.floatingPanel(item: $reportDisplayProblemMessage) { message in
ReportJunkView(mailboxManager: mailboxManager, target: .message(message))
.floatingPanel(item: $reportJunkActionsTarget) { target in
ReportJunkView(mailboxManager: mailboxManager, target: target)
}
}
}
2 changes: 2 additions & 0 deletions Mail/Views/Bottom sheets/Actions/ActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct ActionsView: View {
target: ActionsTarget,
moveSheet: MoveSheet? = nil,
messageReply: Binding<MessageReply?>? = nil,
reportJunkActionsTarget: Binding<ActionsTarget?>? = nil,
completionHandler: (() -> Void)? = nil) {
var matomoCategory = MatomoUtils.EventCategory.bottomSheetMessageActions
if case .threads = target {
Expand All @@ -39,6 +40,7 @@ struct ActionsView: View {
target: target,
moveSheet: moveSheet,
messageReply: messageReply,
reportJunkActionsTarget: reportJunkActionsTarget,
matomoCategory: matomoCategory,
completionHandler: completionHandler)
}
Expand Down
11 changes: 7 additions & 4 deletions Mail/Views/Bottom sheets/Actions/ActionsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ enum ActionsTarget: Equatable, Identifiable {
private let mailboxManager: MailboxManager
private let target: ActionsTarget
private let moveSheet: MoveSheet?
private let replyHandler: ((Message, ReplyMode) -> Void)?
private let messageReply: Binding<MessageReply?>?
private let reportJunkActionsTarget: Binding<ActionsTarget?>?
private let completionHandler: (() -> Void)?

private let matomoCategory: MatomoUtils.EventCategory?
Expand All @@ -222,13 +223,15 @@ enum ActionsTarget: Equatable, Identifiable {
init(mailboxManager: MailboxManager,
target: ActionsTarget,
moveSheet: MoveSheet? = nil,
messageReply: Binding<MessageReply?>? = nil,
reportJunkActionsTarget: Binding<ActionsTarget?>? = nil,
matomoCategory: MatomoUtils.EventCategory? = nil,
replyHandler: ((Message, ReplyMode) -> Void)? = nil,
completionHandler: (() -> Void)? = nil) {
self.mailboxManager = mailboxManager
self.target = target.freeze()
self.moveSheet = moveSheet
self.replyHandler = replyHandler
self.messageReply = messageReply
self.reportJunkActionsTarget = reportJunkActionsTarget
self.completionHandler = completionHandler
self.matomoCategory = matomoCategory
setActions()
Expand Down Expand Up @@ -445,7 +448,7 @@ enum ActionsTarget: Equatable, Identifiable {
}

private func displayReportJunk() {
//globalSheet.open(state: .reportJunk(threadBottomSheet: state, target: target))
reportJunkActionsTarget?.wrappedValue = target
}

private func block() async throws {
Expand Down
9 changes: 2 additions & 7 deletions Mail/Views/Bottom sheets/Actions/ReportJunkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ struct ReportJunkView: View {
var actions: [Action] = []

init(mailboxManager: MailboxManager,
target: ActionsTarget,
globalSheet: GlobalBottomSheet,
globalAlert: GlobalAlert) {
target: ActionsTarget) {
viewModel = ActionsViewModel(mailboxManager: mailboxManager,
target: target)
if case .message(let message) = target {
Expand Down Expand Up @@ -58,10 +56,7 @@ struct ReportJunkView: View {

struct ReportJunkView_Previews: PreviewProvider {
static var previews: some View {
ReportJunkView(mailboxManager: PreviewHelper.sampleMailboxManager,
target: .threads([PreviewHelper.sampleThread], false),
globalSheet: GlobalBottomSheet(),
globalAlert: GlobalAlert())
ReportJunkView(mailboxManager: PreviewHelper.sampleMailboxManager, target: .message(PreviewHelper.sampleMessage))
.accentColor(AccentColor.pink.primary.swiftUIColor)
}
}
2 changes: 0 additions & 2 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ extension EnvironmentValues {

class GlobalBottomSheet: DisplayedFloatingPanelState<GlobalBottomSheet.State> {
enum State {
case getMoreStorage
case restoreEmails
case reportJunk(target: ActionsTarget)
}
}

Expand Down

0 comments on commit ca9e27c

Please sign in to comment.