Reimplement Mark All as Read toolbar item

This commit is contained in:
Maurice Parker 2020-07-25 16:19:22 -05:00
parent d28a672378
commit 8b1aa3e88a
2 changed files with 15 additions and 8 deletions

View File

@ -63,7 +63,7 @@ final class SceneModel: ObservableObject {
/// Marks all the articles in the Timeline as read /// Marks all the articles in the Timeline as read
func markAllAsRead() { func markAllAsRead() {
// timelineModel.markAllAsRead() timelineModel.markAllAsReadSubject.send()
} }
/// Toggles the read status for the selected articles /// Toggles the read status for the selected articles

View File

@ -36,6 +36,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
var selectedArticlesPublisher: AnyPublisher<[Article], Never>? var selectedArticlesPublisher: AnyPublisher<[Article], Never>?
var articleStatusChangePublisher: AnyPublisher<Set<String>, Never>? var articleStatusChangePublisher: AnyPublisher<Set<String>, Never>?
var markAllAsReadSubject = PassthroughSubject<Void, Never>()
var toggleReadStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>() var toggleReadStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
var toggleStarredStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>() var toggleStarredStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
@ -258,7 +259,14 @@ private extension TimelineModel {
} }
func subscribeToArticleMarkingEvents() { func subscribeToArticleMarkingEvents() {
guard let selectedArticlesPublisher = selectedArticlesPublisher else { return } guard let articlesPublisher = articlesPublisher, let selectedArticlesPublisher = selectedArticlesPublisher else { return }
let markAllAsReadPublisher = markAllAsReadSubject
.withLatestFrom(articlesPublisher)
.filter { !$0.isEmpty }
.map { articles -> ([Article], ArticleStatus.Key, Bool) in
return (articles, ArticleStatus.Key.read, true)
}
let toggleReadPublisher = toggleReadStatusForSelectedArticlesSubject let toggleReadPublisher = toggleReadStatusForSelectedArticlesSubject
.withLatestFrom(selectedArticlesPublisher) .withLatestFrom(selectedArticlesPublisher)
@ -278,13 +286,12 @@ private extension TimelineModel {
if selectedArticles.anyArticleIsUnstarred() { if selectedArticles.anyArticleIsUnstarred() {
return (selectedArticles, ArticleStatus.Key.starred, true) return (selectedArticles, ArticleStatus.Key.starred, true)
} else { } else {
return (selectedArticles, ArticleStatus.Key.read, false) return (selectedArticles, ArticleStatus.Key.starred, false)
} }
} }
markAllAsReadPublisher
toggleReadPublisher .merge(with: toggleReadPublisher, toggleStarred)
.merge(with: toggleStarred)
.sink { [weak self] (articles, key, flag) in .sink { [weak self] (articles, key, flag) in
if let undoManager = self?.undoManager, if let undoManager = self?.undoManager,
let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: key, flag: flag, undoManager: undoManager) { let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: key, flag: flag, undoManager: undoManager) {