Add Sidebar go to next functionality
This commit is contained in:
parent
7f60c69454
commit
3cbb4da788
|
@ -120,6 +120,12 @@ private extension SceneModel {
|
|||
|
||||
// MARK: Subscriptions
|
||||
func subscribeToToolbarChangeEvents() {
|
||||
NotificationCenter.default.publisher(for: .UnreadCountDidChange)
|
||||
.compactMap { $0.object as? AccountManager }
|
||||
.sink { [weak self] accountManager in
|
||||
self?.updateNextUnreadButtonState(accountManager: accountManager)
|
||||
}.store(in: &cancellables)
|
||||
|
||||
let combinedPublisher = timelineModel.$articles.combineLatest(timelineModel.$selectedArticles,
|
||||
NotificationCenter.default.publisher(for: .StatusesDidChange))
|
||||
|
||||
|
@ -131,6 +137,14 @@ private extension SceneModel {
|
|||
|
||||
// MARK: Button State Updates
|
||||
|
||||
func updateNextUnreadButtonState(accountManager: AccountManager) {
|
||||
if accountManager.unreadCount > 0 {
|
||||
self.nextUnreadButtonState = false
|
||||
} else {
|
||||
self.nextUnreadButtonState = nil
|
||||
}
|
||||
}
|
||||
|
||||
func updateMarkAllAsReadButtonsState(articles: [Article]) {
|
||||
if articles.canMarkAllAsRead() {
|
||||
markAllAsReadButtonState = false
|
||||
|
|
|
@ -39,6 +39,21 @@ class SidebarModel: ObservableObject, UndoableCommandRunner {
|
|||
subscribeToSelectedFeedChanges()
|
||||
subscribeToReadFilterChanges()
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
|
||||
func goToNextUnread() {
|
||||
guard let lastSelectedFeed = selectedFeeds.last,
|
||||
let currentSidebarItem = sidebarItems.first(where: { $0.feed?.feedID == lastSelectedFeed.feedID }) else {
|
||||
return
|
||||
}
|
||||
|
||||
if !goToNextUnread(startingAt: currentSidebarItem) {
|
||||
if let firstSidebarItem = sidebarItems.first {
|
||||
goToNextUnread(startingAt: firstSidebarItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -107,16 +122,7 @@ private extension SidebarModel {
|
|||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK:
|
||||
|
||||
func findFeed(_ feedID: FeedIdentifier) -> Feed? {
|
||||
switch feedID {
|
||||
case .smartFeed:
|
||||
return SmartFeedsController.shared.find(by: feedID)
|
||||
default:
|
||||
return AccountManager.shared.existingFeed(with: feedID)
|
||||
}
|
||||
}
|
||||
// MARK: Sidebar Building
|
||||
|
||||
func sort(_ folders: Set<Folder>) -> [Folder] {
|
||||
return folders.sorted(by: { $0.nameForDisplay.localizedStandardCompare($1.nameForDisplay) == .orderedAscending })
|
||||
|
@ -175,4 +181,34 @@ private extension SidebarModel {
|
|||
sidebarItems = items
|
||||
}
|
||||
|
||||
// MARK:
|
||||
|
||||
func findFeed(_ feedID: FeedIdentifier) -> Feed? {
|
||||
switch feedID {
|
||||
case .smartFeed:
|
||||
return SmartFeedsController.shared.find(by: feedID)
|
||||
default:
|
||||
return AccountManager.shared.existingFeed(with: feedID)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func goToNextUnread(startingAt: SidebarItem) -> Bool {
|
||||
guard let startIndex = sidebarItems.firstIndex(where: { $0.id == startingAt.id }) else { return false }
|
||||
|
||||
for i in startIndex..<sidebarItems.count {
|
||||
if sidebarItems[i].unreadCount > 0, let feedID = sidebarItems[i].feed?.feedID {
|
||||
select(feedID)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func select(_ feedID: FeedIdentifier) {
|
||||
selectedFeedIdentifiers = Set([feedID])
|
||||
selectedFeedIdentifier = feedID
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -315,6 +315,14 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
|||
openIndicatedArticleInBrowser(article)
|
||||
}
|
||||
|
||||
func canGoToNextUnread() -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func goToNextUnread() {
|
||||
|
||||
}
|
||||
|
||||
func articleFor(_ articleID: String) -> Article? {
|
||||
return idToArticleDictionary[articleID]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue