From d3399e8632c9b58af43a6a09de1da43c2990d52e Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 25 Jul 2020 13:15:00 -0500 Subject: [PATCH] Enable article lookups --- Multiplatform/Shared/Timeline/TimelineModel.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Multiplatform/Shared/Timeline/TimelineModel.swift b/Multiplatform/Shared/Timeline/TimelineModel.swift index 78e6d3285..135d80c2f 100644 --- a/Multiplatform/Shared/Timeline/TimelineModel.swift +++ b/Multiplatform/Shared/Timeline/TimelineModel.swift @@ -44,6 +44,8 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { private var sortDirectionSubject = ReplaySubject(bufferSize: 1) private var groupByFeedSubject = ReplaySubject(bufferSize: 1) + + private var timelineItems = OrderedDictionary() init(delegate: TimelineModelDelegate) { self.delegate = delegate @@ -134,10 +136,18 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { .share(replay: 1) .eraseToAnyPublisher() + timelineItemsPublisher! + .sink { [weak self] timelineItems in + self?.timelineItems = timelineItems + } + .store(in: &cancellables) + + // Transform to articles for those that just need articles articlesPublisher = timelineItemsPublisher! .map { timelineItems in timelineItems.values.values.map { $0.article } } + .share() .eraseToAnyPublisher() // Set the timeline name for display @@ -231,8 +241,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { } func articleFor(_ articleID: String) -> Article? { - return nil -// return idToArticleDictionary[articleID] + return timelineItems[articleID]?.article } func findPrevArticle(_ article: Article) -> Article? {