Merge pull request #1553 from hartlco/1548-mark-above-below-as-read-should-not-appear-if-nothing-to-mark

Only show mark unread above/below actions if articles above/below contain unread items
This commit is contained in:
Maurice Parker 2020-01-07 16:47:37 -07:00 committed by GitHub
commit 92cfbc767b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 20 deletions

View File

@ -109,5 +109,30 @@ extension Array where Element == Article {
} }
return true return true
} }
func articlesAbove(article: Article) -> [Article] {
guard let position = firstIndex(of: article) else {
return []
}
let articlesAbove = self[..<position]
return Array(articlesAbove)
}
func articlesBelow(article: Article) -> [Article] {
guard let position = firstIndex(of: article) else {
return []
}
var articlesBelow = Array(self[position...])
guard !articlesBelow.isEmpty else {
return []
}
articlesBelow.removeFirst()
return articlesBelow
}
} }

View File

@ -872,7 +872,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func canMarkAboveAsRead(for article: Article) -> Bool { func canMarkAboveAsRead(for article: Article) -> Bool {
return articles.first != article let articlesAboveArray = articles.articlesAbove(article: article)
return articlesAboveArray.canMarkAllAsRead()
} }
func markAboveAsRead() { func markAboveAsRead() {
@ -884,16 +885,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func markAboveAsRead(_ article: Article) { func markAboveAsRead(_ article: Article) {
guard let position = articles.firstIndex(of: article) else { let articlesAboveArray = articles.articlesAbove(article: article)
return markAllAsRead(articlesAboveArray)
}
let articlesAbove = articles[..<position]
markAllAsRead(Array(articlesAbove))
} }
func canMarkBelowAsRead(for article: Article) -> Bool { func canMarkBelowAsRead(for article: Article) -> Bool {
return articles.last != article let articleBelowArray = articles.articlesBelow(article: article)
return articleBelowArray.canMarkAllAsRead()
} }
func markBelowAsRead() { func markBelowAsRead() {
@ -905,18 +903,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
func markBelowAsRead(_ article: Article) { func markBelowAsRead(_ article: Article) {
guard let position = articles.firstIndex(of: article) else { let articleBelowArray = articles.articlesBelow(article: article)
return markAllAsRead(articleBelowArray)
}
var articlesBelow = Array(articles[position...])
guard !articlesBelow.isEmpty else {
return
}
articlesBelow.removeFirst()
markAllAsRead(articlesBelow)
} }
func markAsReadForCurrentArticle() { func markAsReadForCurrentArticle() {