Reimplement toggle read/unread for selected toolbar item.
This commit is contained in:
parent
479562b47f
commit
f793e1b02d
@ -68,7 +68,7 @@ final class SceneModel: ObservableObject {
|
|||||||
|
|
||||||
/// Toggles the read status for the selected articles
|
/// Toggles the read status for the selected articles
|
||||||
func toggleReadStatusForSelectedArticles() {
|
func toggleReadStatusForSelectedArticles() {
|
||||||
// timelineModel.toggleReadStatusForSelectedArticles()
|
timelineModel.toggleReadStatusForSelectedArticlesSubject.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggles the star status for the selected articles
|
/// Toggles the star status for the selected articles
|
||||||
|
@ -36,6 +36,9 @@ 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 toggleReadStatusForSelectedArticlesSubject = PassthroughSubject<Void, Never>()
|
||||||
|
|
||||||
|
|
||||||
var readFilterEnabledTable = [FeedIdentifier: Bool]()
|
var readFilterEnabledTable = [FeedIdentifier: Bool]()
|
||||||
|
|
||||||
var undoManager: UndoManager?
|
var undoManager: UndoManager?
|
||||||
@ -56,8 +59,67 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
|||||||
subscribeToSelectedArticleSelectionChanges()
|
subscribeToSelectedArticleSelectionChanges()
|
||||||
subscribeToArticleStatusChanges()
|
subscribeToArticleStatusChanges()
|
||||||
// subscribeToAccountDidDownloadArticles()
|
// subscribeToAccountDidDownloadArticles()
|
||||||
|
subscribeToArticleMarkingEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: API
|
||||||
|
|
||||||
|
func toggleReadFilter() {
|
||||||
|
// guard let filter = isReadFiltered, let feedID = feeds.first?.feedID else { return }
|
||||||
|
// readFilterEnabledTable[feedID] = !filter
|
||||||
|
// isReadFiltered = !filter
|
||||||
|
// self.fetchArticles()
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
func goToNextUnread() -> Bool {
|
||||||
|
// var startIndex: Int
|
||||||
|
// if let firstArticle = selectedArticles.first, let index = timelineItems.firstIndex(where: { $0.article == firstArticle }) {
|
||||||
|
// startIndex = index
|
||||||
|
// } else {
|
||||||
|
// startIndex = 0
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for i in startIndex..<timelineItems.count {
|
||||||
|
// if !timelineItems[i].article.status.read {
|
||||||
|
// select(timelineItems[i].article.articleID)
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func articleFor(_ articleID: String) -> Article? {
|
||||||
|
return timelineItems[articleID]?.article
|
||||||
|
}
|
||||||
|
|
||||||
|
func findPrevArticle(_ article: Article) -> Article? {
|
||||||
|
return nil
|
||||||
|
// guard let index = articles.firstIndex(of: article), index > 0 else {
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
// return articles[index - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func findNextArticle(_ article: Article) -> Article? {
|
||||||
|
return nil
|
||||||
|
// guard let index = articles.firstIndex(of: article), index + 1 != articles.count else {
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
// return articles[index + 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectArticle(_ article: Article) {
|
||||||
|
// TODO: Implement me!
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Private
|
||||||
|
|
||||||
|
private extension TimelineModel {
|
||||||
|
|
||||||
// MARK: Subscriptions
|
// MARK: Subscriptions
|
||||||
|
|
||||||
func subscribeToArticleStatusChanges() {
|
func subscribeToArticleStatusChanges() {
|
||||||
@ -194,82 +256,32 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
|||||||
.sink { markArticles(Set([$0]), statusKey: .read, flag: true) }
|
.sink { markArticles(Set([$0]), statusKey: .read, flag: true) }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: API
|
|
||||||
|
|
||||||
func toggleReadFilter() {
|
|
||||||
// guard let filter = isReadFiltered, let feedID = feeds.first?.feedID else { return }
|
|
||||||
// readFilterEnabledTable[feedID] = !filter
|
|
||||||
// isReadFiltered = !filter
|
|
||||||
// self.fetchArticles()
|
|
||||||
}
|
|
||||||
|
|
||||||
func toggleReadStatusForSelectedArticles() {
|
|
||||||
// guard !selectedArticles.isEmpty else {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if selectedArticles.anyArticleIsUnread() {
|
|
||||||
// markSelectedArticlesAsRead()
|
|
||||||
// } else {
|
|
||||||
// markSelectedArticlesAsUnread()
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@discardableResult
|
func subscribeToArticleMarkingEvents() {
|
||||||
func goToNextUnread() -> Bool {
|
guard let selectedArticlesPublisher = selectedArticlesPublisher else { return }
|
||||||
// var startIndex: Int
|
|
||||||
// if let firstArticle = selectedArticles.first, let index = timelineItems.firstIndex(where: { $0.article == firstArticle }) {
|
let toggleReadPublisher = toggleReadStatusForSelectedArticlesSubject
|
||||||
// startIndex = index
|
.withLatestFrom(selectedArticlesPublisher)
|
||||||
// } else {
|
.filter { !$0.isEmpty }
|
||||||
// startIndex = 0
|
.map {selectedArticles -> ([Article], ArticleStatus.Key, Bool) in
|
||||||
// }
|
if selectedArticles.anyArticleIsUnread() {
|
||||||
//
|
return (selectedArticles, ArticleStatus.Key.read, true)
|
||||||
// for i in startIndex..<timelineItems.count {
|
} else {
|
||||||
// if !timelineItems[i].article.status.read {
|
return (selectedArticles, ArticleStatus.Key.read, false)
|
||||||
// select(timelineItems[i].article.articleID)
|
}
|
||||||
// return true
|
}
|
||||||
// }
|
|
||||||
// }
|
toggleReadPublisher
|
||||||
//
|
.sink { [weak self] (articles, key, flag) in
|
||||||
return false
|
if let undoManager = self?.undoManager,
|
||||||
}
|
let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: key, flag: flag, undoManager: undoManager) {
|
||||||
|
self?.runCommand(markReadCommand)
|
||||||
func articleFor(_ articleID: String) -> Article? {
|
} else {
|
||||||
return timelineItems[articleID]?.article
|
markArticles(Set(articles), statusKey: key, flag: flag)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
func findPrevArticle(_ article: Article) -> Article? {
|
.store(in: &cancellables)
|
||||||
return nil
|
|
||||||
// guard let index = articles.firstIndex(of: article), index > 0 else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// return articles[index - 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func findNextArticle(_ article: Article) -> Article? {
|
|
||||||
return nil
|
|
||||||
// guard let index = articles.firstIndex(of: article), index + 1 != articles.count else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// return articles[index + 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func selectArticle(_ article: Article) {
|
|
||||||
// TODO: Implement me!
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Private
|
|
||||||
|
|
||||||
private extension TimelineModel {
|
|
||||||
|
|
||||||
func markArticlesWithUndo(_ articles: [Article], statusKey: ArticleStatus.Key, flag: Bool) {
|
|
||||||
if let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, statusKey: statusKey, flag: flag, undoManager: undoManager) {
|
|
||||||
runCommand(markReadCommand)
|
|
||||||
} else {
|
|
||||||
markArticles(Set(articles), statusKey: statusKey, flag: flag)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Timeline Management
|
// MARK: Timeline Management
|
||||||
|
Loading…
x
Reference in New Issue
Block a user