Skip to content

Commit

Permalink
Fix #11 - Once the app has given access, the UI won't refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
betzerra committed Oct 29, 2021
1 parent 1b81abd commit 120c4ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Morty/CalendarPicker/CalendarPickerViewController.swift
Expand Up @@ -18,17 +18,26 @@ class CalendarPickerViewController: NSViewController, NSTableViewDataSource, NST
override func viewDidLoad() {
super.viewDidLoad()

allowButton.title = EventsManager.isAuthorized ? "Granted" : "Allow"
updateAllowButton()

tableView.dataSource = self
tableView.delegate = self
}

private func updateAllowButton() {
allowButton.title = EventsManager.isAuthorized ? "Granted" : "Allow"
}

@IBAction func allowButtonPressed(_ sender: Any) {
AppDelegate
.current
.eventsManager
.requestAccess { _, _ in }
.requestAccess(completion: { [weak self] _, _ in
DispatchQueue.main.async {
self?.updateAllowButton()
self?.tableView.reloadData()
}
})
}

// MARK: NSTableViewDataSource
Expand Down
4 changes: 2 additions & 2 deletions Morty/CalendarPicker/CalendarPickerViewModel.swift
Expand Up @@ -10,7 +10,7 @@ import EventKit
import Foundation

class CalendarPickerViewModel {
lazy var calendars: [EKCalendar] = {
var calendars: [EKCalendar] {
AppDelegate.current.eventsManager
.store.calendars(for: .event)
.sorted { lhs, rhs in
Expand All @@ -28,7 +28,7 @@ class CalendarPickerViewModel {

return lhs.displayTitle < rhs.displayTitle
}
}()
}

func enableCalendar(_ identifier: String, _ enable: Bool) {
AppDelegate
Expand Down
4 changes: 2 additions & 2 deletions Morty/Managers/EventsManager.swift
Expand Up @@ -58,8 +58,8 @@ class EventsManager {
}.store(in: &cancellables)
}

func requestAccess(completion: ((Bool, Error) -> Void)) {
store.requestAccess(to: .event) { _, _ in }
func requestAccess(completion: @escaping ((Bool, Error?) -> Void)) {
store.requestAccess(to: .event, completion: completion)
}

static var isAuthorized: Bool {
Expand Down

0 comments on commit 120c4ee

Please sign in to comment.