Skip to content

Commit

Permalink
Fix the available dates issue. Only dates with available slots displa…
Browse files Browse the repository at this point in the history
…yed in count and message. Notification delay made 1second from 5seconds
  • Loading branch information
Covid19 Chennai committed May 15, 2021
1 parent a5d2899 commit 85207e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions VaccineAvailability/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.statusItem.button?.action = #selector(togglePopover(_:))

self.updateClock()
timer = Timer.scheduledTimer(timeInterval: 15,
timer = Timer.scheduledTimer(timeInterval: 10,
target: self,
selector: #selector(updateClock),
userInfo: nil,
Expand All @@ -74,10 +74,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func addNotification(hospital:Hospital, ageLimit:Int){
let content = UNMutableNotificationContent()
content.title = "\(hospital.hospitalName), \(hospital.districtName)"
content.subtitle = hospital.daysAvailable(ageLimit: ageLimit)
content.body = hospital.formattedDate()

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let daysAvailabe:[String] = hospital.daysAvailable(ageLimit: ageLimit)
let subtitle = "\(daysAvailabe.count) day(s) available (Age \(ageLimit) and above)"

content.subtitle = subtitle
content.body = daysAvailabe.joined(separator: ", ")

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString,
content: content,
trigger: trigger)
Expand Down
12 changes: 6 additions & 6 deletions VaccineAvailability/Hospital.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class Hospital {
return filteredSessions.count > 0
}

func formattedDate() -> String {
return self.sessions.map ({$0.date}).joined(separator: ", ")
}

func daysAvailable(ageLimit: Int) -> String {
return "\(self.sessions.count) days available (Age \(ageLimit) and above)"
func daysAvailable(ageLimit: Int) -> [String] {
let daysWithAvailableSessions = self.sessions
.filter ({$0.isAvailableFor(ageLimit: ageLimit)})
.map({$0.date})
return daysWithAvailableSessions
}
}

0 comments on commit 85207e3

Please sign in to comment.