Enable article lookups

This commit is contained in:
Maurice Parker 2020-07-25 13:15:00 -05:00
parent 5c8aaed54c
commit d3399e8632
1 changed files with 11 additions and 2 deletions

View File

@ -45,6 +45,8 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
private var sortDirectionSubject = ReplaySubject<Bool, Never>(bufferSize: 1) private var sortDirectionSubject = ReplaySubject<Bool, Never>(bufferSize: 1)
private var groupByFeedSubject = ReplaySubject<Bool, Never>(bufferSize: 1) private var groupByFeedSubject = ReplaySubject<Bool, Never>(bufferSize: 1)
private var timelineItems = OrderedDictionary<String, TimelineItem>()
init(delegate: TimelineModelDelegate) { init(delegate: TimelineModelDelegate) {
self.delegate = delegate self.delegate = delegate
subscribeToUserDefaultsChanges() subscribeToUserDefaultsChanges()
@ -134,10 +136,18 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
.share(replay: 1) .share(replay: 1)
.eraseToAnyPublisher() .eraseToAnyPublisher()
timelineItemsPublisher!
.sink { [weak self] timelineItems in
self?.timelineItems = timelineItems
}
.store(in: &cancellables)
// Transform to articles for those that just need articles
articlesPublisher = timelineItemsPublisher! articlesPublisher = timelineItemsPublisher!
.map { timelineItems in .map { timelineItems in
timelineItems.values.values.map { $0.article } timelineItems.values.values.map { $0.article }
} }
.share()
.eraseToAnyPublisher() .eraseToAnyPublisher()
// Set the timeline name for display // Set the timeline name for display
@ -231,8 +241,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
} }
func articleFor(_ articleID: String) -> Article? { func articleFor(_ articleID: String) -> Article? {
return nil return timelineItems[articleID]?.article
// return idToArticleDictionary[articleID]
} }
func findPrevArticle(_ article: Article) -> Article? { func findPrevArticle(_ article: Article) -> Article? {