Rebuild the sidebar when things are added or changed
This commit is contained in:
parent
e062ccc67e
commit
5da851f937
|
@ -22,6 +22,12 @@ class SidebarModel: ObservableObject {
|
|||
|
||||
init() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountStateDidChange(_:)), name: .AccountStateDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddAccount(_:)), name: .UserDidAddAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDidDeleteAccount(_:)), name: .UserDidDeleteAccount, object: nil)
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
@ -60,15 +66,9 @@ class SidebarModel: ObservableObject {
|
|||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private extension SidebarModel {
|
||||
|
||||
@objc func unreadCountDidInitialize(_ notification: Notification) {
|
||||
guard notification.object is AccountManager else {
|
||||
return
|
||||
}
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
func sort(_ folders: Set<Folder>) -> [Folder] {
|
||||
return folders.sorted(by: { $0.nameForDisplay.localizedStandardCompare($1.nameForDisplay) == .orderedAscending })
|
||||
}
|
||||
|
@ -77,4 +77,37 @@ private extension SidebarModel {
|
|||
return feeds.sorted(by: { $0.nameForDisplay.localizedStandardCompare($1.nameForDisplay) == .orderedAscending })
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func unreadCountDidInitialize(_ notification: Notification) {
|
||||
guard notification.object is AccountManager else {
|
||||
return
|
||||
}
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func containerChildrenDidChange(_ notification: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func batchUpdateDidPerform(_ notification: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func displayNameDidChange(_ note: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func accountStateDidChange(_ note: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func userDidAddAccount(_ note: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
@objc func userDidDeleteAccount(_ note: Notification) {
|
||||
rebuildSidebarItems()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue