Skip to content

Commit 312d24a

Browse files
feat: Update filter method
1 parent b9ef0db commit 312d24a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Mail/Views/Schedule/ScheduleFloatingPanel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct ScheduleFloatingPanel: ViewModifier {
8282
isShowingCustomScheduleAlert: $isShowingCustomScheduleAlert,
8383
isShowingMyKSuiteUpgrade: $isShowingMyKSuiteUpgrade,
8484
type: type,
85+
initialDate: initialDate,
8586
completionHandler: completionHandler
8687
)
8788
.environmentObject(mailboxManager)

Mail/Views/Schedule/ScheduleFloatingPanelView.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,32 @@ struct ScheduleFloatingPanelView: View {
2727
@Binding var isShowingMyKSuiteUpgrade: Bool
2828

2929
let type: ScheduleType
30+
let initialDate: Date?
3031
let completionHandler: (Date) -> Void
3132

3233
private var scheduleOptions: [ScheduleOption] {
34+
var seenDateOptions = Set<Date>()
35+
if let initialDate {
36+
seenDateOptions.insert(initialDate)
37+
}
38+
39+
var filteredOptions = ScheduleOption.allPresetOptions.filter { option in
40+
guard option.canBeDisplayed, let date = option.date else { return false }
41+
if seenDateOptions.contains(date) {
42+
return false
43+
} else {
44+
seenDateOptions.insert(date)
45+
return true
46+
}
47+
}
48+
3349
let lastScheduledDate = UserDefaults.shared[keyPath: type.lastCustomScheduleDateKeyPath]
50+
let lastScheduledOption = ScheduleOption.lastSchedule(value: lastScheduledDate)
51+
if lastScheduledOption.canBeDisplayed, !seenDateOptions.contains(lastScheduledDate) {
52+
filteredOptions.insert(.lastSchedule(value: lastScheduledDate), at: 0)
53+
}
3454

35-
var allSimpleCases = ScheduleOption.allPresetOptions
36-
allSimpleCases.insert(ScheduleOption.lastSchedule(value: lastScheduledDate), at: 0)
37-
return allSimpleCases.filter { $0.canBeDisplayed }
55+
return filteredOptions
3856
}
3957

4058
var body: some View {
@@ -58,6 +76,7 @@ struct ScheduleFloatingPanelView: View {
5876
ScheduleFloatingPanelView(
5977
isShowingCustomScheduleAlert: .constant(false),
6078
isShowingMyKSuiteUpgrade: .constant(false),
61-
type: .scheduledDraft
79+
type: .scheduledDraft,
80+
initialDate: nil
6281
) { _ in }
6382
}

0 commit comments

Comments
 (0)