From 5da851f93794ef4932d62cf092b260e7ac614bd7 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 4 Jul 2020 09:33:27 -0500 Subject: [PATCH] Rebuild the sidebar when things are added or changed --- .../Shared/Sidebar/SidebarModel.swift | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/Multiplatform/Shared/Sidebar/SidebarModel.swift b/Multiplatform/Shared/Sidebar/SidebarModel.swift index 335d6b260..1bbbd92a4 100644 --- a/Multiplatform/Shared/Sidebar/SidebarModel.swift +++ b/Multiplatform/Shared/Sidebar/SidebarModel.swift @@ -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] { 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() + } + }