Sources/OrgApp/OverdueBadge.swift

b043ff99fba99e1bab2208d64a2e1cd8fbf80c87
orgstar/Sources/OrgApp/OverdueBadge.swift

22 lines · 1145 bytes

 1import Foundation
 2import OrgPresentation
 3
 4/// The app icon's badge: the entries in the agenda's Overdue section that aren't done.
 5public enum OverdueBadge {
 6    /// The count for each day from `today`, for `days` days, if nothing is done meanwhile: today's
 7    /// overdue entries, then each day's scheduled and deadline entries once their day has passed.
 8    public static func counts(_ groups: [AgendaDayGroup], today: Int, days: Int) -> [Int] {
 9        func key(_ row: AgendaRow) -> String? {
10            guard let item = row.item, !row.isDone, item.habit == nil, row.planningDay != nil else { return nil }
11            return "\(String(describing: item.path)):\(String(describing: item.headingOffset ?? item.markerOffset))"
12        }
13        var overdue = Set(groups.first { $0.day == today }?.overdue.compactMap(key) ?? [])
14        var counts = [overdue.count]
15        for day in today..<(today + days - 1) {
16            let rows = groups.first { $0.day == day }?.rows ?? []
17            overdue.formUnion(rows.filter { $0.planningDay == day }.compactMap(key))
18            counts.append(overdue.count)
19        }
20        return counts
21    }
22}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form