Reimplement Mark All as Read toolbar item
This commit is contained in:
parent
d28a672378
commit
8b1aa3e88a
@ -63,7 +63,7 @@ final class SceneModel: ObservableObject {
|
||||
|
||||
/// Marks all the articles in the Timeline as read
|
||||
func markAllAsRead() {
|
||||
// timelineModel.markAllAsRead()
|
||||
timelineModel.markAllAsReadSubject.send()
|
||||
}
|
||||
|
||||
/// Toggles the read status for the selected articles
|
||||
|
@ -36,6 +36,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||
var selectedArticlesPublisher: AnyPublisher<[Article], Never>?
|
||||
var articleStatusChangePublisher: AnyPublisher<Set<String>, Never>?
|
||||
|
||||
var markAllAsReadSubject = PassthroughSubject<Void, Never>()
|
||||
var toggleReadStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
|
||||
var toggleStarredStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
|
||||
|
||||
@ -258,7 +259,14 @@ private extension TimelineModel {
|
||||
}
|
||||
|
||||
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
|
||||
.withLatestFrom(selectedArticlesPublisher)
|
||||
@ -278,13 +286,12 @@ private extension TimelineModel {
|
||||
if selectedArticles.anyArticleIsUnstarred() {
|
||||
return (selectedArticles, ArticleStatus.Key.starred, true)
|
||||
} else {
|
||||
return (selectedArticles, ArticleStatus.Key.read, false)
|
||||
return (selectedArticles, ArticleStatus.Key.starred, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
toggleReadPublisher
|
||||
.merge(with: toggleStarred)
|
||||
markAllAsReadPublisher
|
||||
.merge(with: toggleReadPublisher, toggleStarred)
|
||||
.sink { [weak self] (articles, key, flag) in
|
||||
if let undoManager = self?.undoManager,
|
||||
let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: key, flag: flag, undoManager: undoManager) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user