Skip to content

Commit

Permalink
Show reminder priority (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah authored Dec 23, 2024
1 parent 360188b commit 072d736
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.7;
MARKETING_VERSION = 1.15.0;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down Expand Up @@ -1535,7 +1535,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.7;
MARKETING_VERSION = 1.15.0;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down
14 changes: 11 additions & 3 deletions Calendr/Events/EventList/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EventView: NSView {

private let birthdayIcon = NSImageView()
private let recurrenceIcon = NSImageView()
private let priority = Label()
private let title = Label()
private let subtitle = Label()
private let subtitleLink = Label()
Expand Down Expand Up @@ -70,6 +71,10 @@ class EventView: NSView {
birthdayIcon.isHidden = false

case .reminder:
priority.textColor = viewModel.color
priority.stringValue = viewModel.priority ?? ""
priority.isHidden = viewModel.priority == nil

completeBtn.contentTintColor = viewModel.color
completeBtn.isHidden = false

Expand Down Expand Up @@ -117,13 +122,16 @@ class EventView: NSView {
hoverLayer.backgroundColor = NSColor.gray.cgColor.copy(alpha: 0.2)
layer?.addSublayer(hoverLayer)

[birthdayIcon, recurrenceIcon, completeBtn, relativeDuration].forEach {
[birthdayIcon, recurrenceIcon, completeBtn, priority, relativeDuration].forEach {
$0.setContentHuggingPriority(.required, for: .horizontal)
$0.setContentCompressionResistancePriority(.required, for: .horizontal)
}

completeBtn.isHidden = true

priority.isHidden = true
priority.font = .systemFont(ofSize: 13)

birthdayIcon.isHidden = true
birthdayIcon.contentTintColor = .systemRed

Expand Down Expand Up @@ -154,8 +162,8 @@ class EventView: NSView {
colorBar.layer?.cornerRadius = 2
colorBar.width(equalTo: 4)

let titleStackView = NSStackView(views: [birthdayIcon, completeBtn, title, recurrenceIcon])
.with(spacing: 4)
let titleStackView = NSStackView(views: [birthdayIcon, completeBtn, priority, title, recurrenceIcon])
.with(spacing: 3)
.with(alignment: .firstBaseline)

let linkStackView = NSStackView(views: [subtitleLink, linkBtn]).with(spacing: 0)
Expand Down
8 changes: 8 additions & 0 deletions Calendr/Events/EventList/EventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EventViewModel {
let type: EventType
let isDeclined: Bool
let link: EventLink?
let priority: String?

let duration: Observable<String>
let isInProgress: Observable<Bool>
Expand Down Expand Up @@ -77,6 +78,13 @@ class EventViewModel {
barStyle = event.status ~= .maybe ? .bordered : .filled
link = event.detectLink(using: workspace)

priority = switch event.priority {
case .high: "!!!"
case .medium: "!!"
case .low: "!"
default: nil
}

linkTapped = .init { [link] _ in
if let link {
workspace.open(link)
Expand Down
6 changes: 4 additions & 2 deletions Calendr/Mocks/Factories/EventModel+Factory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ extension EventModel {
calendar: CalendarModel = .make(),
participants: [Participant] = [],
timeZone: TimeZone? = nil,
hasRecurrenceRules: Bool = false
hasRecurrenceRules: Bool = false,
priority: Priority? = nil
) -> EventModel {

.init(
Expand All @@ -41,7 +42,8 @@ extension EventModel {
calendar: calendar,
participants: participants,
timeZone: timeZone,
hasRecurrenceRules: hasRecurrenceRules
hasRecurrenceRules: hasRecurrenceRules,
priority: priority
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions Calendr/Models/EventModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct EventModel: Equatable {
let participants: [Participant]
let timeZone: TimeZone?
let hasRecurrenceRules: Bool
let priority: Priority?
}

enum EventStatus: Comparable {
Expand Down Expand Up @@ -96,3 +97,9 @@ struct Participant: Hashable {
let isOrganizer: Bool
let isCurrentUser: Bool
}

enum Priority {
case high
case medium
case low
}
23 changes: 21 additions & 2 deletions Calendr/Providers/CalendarServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ private extension Array where Element == Participant {
}
}

private extension Priority {

/// 1-4 are considered "high," a priority of 5 is "medium," and priorities of 6-9 are "low"
init?(from p: Int) {
switch p {
case 1...4:
self = .high
case 5:
self = .medium
case 6...9:
self = .low
default:
return nil
}
}
}

private extension EventModel {

init?(from event: EKEvent, dateProvider: DateProviding) {
Expand All @@ -481,7 +498,8 @@ private extension EventModel {
calendar: .init(from: calendar),
participants: .init(from: event),
timeZone: calendar.isSubscribed || calendar.isDelegate ? nil : event.timeZone,
hasRecurrenceRules: event.hasRecurrenceRules || event.isDetached
hasRecurrenceRules: event.hasRecurrenceRules || event.isDetached,
priority: nil
)
}

Expand All @@ -506,7 +524,8 @@ private extension EventModel {
calendar: .init(from: calendar),
participants: [],
timeZone: calendar.isSubscribed || calendar.isDelegate ? nil : reminder.timeZone,
hasRecurrenceRules: reminder.hasRecurrenceRules
hasRecurrenceRules: reminder.hasRecurrenceRules,
priority: .init(from: reminder.priority)
)
}
}
Expand Down

0 comments on commit 072d736

Please sign in to comment.