Subscribe to article selection changes in the Article View
This commit is contained in:
parent
fca35060d5
commit
dabf471db7
@ -32,6 +32,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||
|
||||
var timelineItemsPublisher: AnyPublisher<OrderedDictionary<String, TimelineItem>, Never>?
|
||||
var selectedTimelineItemsPublisher: AnyPublisher<[TimelineItem], Never>?
|
||||
var selectedArticlesPublisher: AnyPublisher<[Article], Never>?
|
||||
|
||||
var readFilterEnabledTable = [FeedIdentifier: Bool]()
|
||||
|
||||
@ -167,6 +168,11 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
|
||||
.merge(with: timelineSelectedIDPublisher)
|
||||
.share(replay: 1)
|
||||
.eraseToAnyPublisher()
|
||||
|
||||
selectedArticlesPublisher = selectedTimelineItemsPublisher!
|
||||
.map { timelineItems in timelineItems.map { $0.article } }
|
||||
.share(replay: 1)
|
||||
.eraseToAnyPublisher()
|
||||
|
||||
// Automatically mark a selected record as read
|
||||
selectedTimelineItemsPublisher!
|
||||
|
@ -72,16 +72,18 @@ struct TimelineView: View {
|
||||
.navigationTitle(Text(verbatim: timelineModel.nameForDisplay))
|
||||
#else
|
||||
ScrollViewReader { scrollViewProxy in
|
||||
List(timelineItems) { timelineItem in
|
||||
ZStack {
|
||||
let selected = timelineModel.selectedTimelineItemID == timelineItem.article.articleID
|
||||
TimelineItemView(selected: selected, width: geometryReaderProxy.size.width, timelineItem: timelineItem)
|
||||
.background(TimelineItemFramePreferenceView(timelineItem: timelineItem))
|
||||
NavigationLink(destination: ArticleContainerView(),
|
||||
tag: timelineItem.article.articleID,
|
||||
selection: $timelineModel.selectedTimelineItemID) {
|
||||
EmptyView()
|
||||
}.buttonStyle(PlainButtonStyle())
|
||||
List(timelineItems.keys, id: \.self) { timelineItemID in
|
||||
if let timelineItem = timelineItems[timelineItemID] {
|
||||
ZStack {
|
||||
let selected = timelineModel.selectedTimelineItemID == timelineItem.article.articleID
|
||||
TimelineItemView(selected: selected, width: geometryReaderProxy.size.width, timelineItem: timelineItem)
|
||||
.background(TimelineItemFramePreferenceView(timelineItem: timelineItem))
|
||||
NavigationLink(destination: ArticleContainerView(),
|
||||
tag: timelineItem.article.articleID,
|
||||
selection: $timelineModel.selectedTimelineItemID) {
|
||||
EmptyView()
|
||||
}.buttonStyle(PlainButtonStyle())
|
||||
}
|
||||
}
|
||||
}
|
||||
.onPreferenceChange(TimelineItemFramePreferenceKey.self) { preferences in
|
||||
|
@ -42,7 +42,7 @@ class ArticleViewController: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private var selectedArticlesCancellable: AnyCancellable?
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -61,9 +61,10 @@ class ArticleViewController: UIViewController {
|
||||
view.bottomAnchor.constraint(equalTo: pageViewController.view.bottomAnchor)
|
||||
])
|
||||
|
||||
// selectedArticlesCancellable = sceneModel?.timelineModel.$selectedArticles.sink { [weak self] articles in
|
||||
// self?.articles = articles
|
||||
// }
|
||||
sceneModel?.timelineModel.selectedArticlesPublisher?.sink { [weak self] articles in
|
||||
self?.articles = articles
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
let controller = createWebViewController(currentArticle, updateView: true)
|
||||
self.pageViewController.setViewControllers([controller], direction: .forward, animated: false, completion: nil)
|
||||
|
@ -55,8 +55,8 @@ class WebViewController: NSViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private var selectedArticlesCancellable: AnyCancellable?
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
override func loadView() {
|
||||
view = NSView()
|
||||
}
|
||||
@ -79,10 +79,11 @@ class WebViewController: NSViewController {
|
||||
self.view.bottomAnchor.constraint(equalTo: statusBarView.bottomAnchor, constant: 2),
|
||||
statusBarView.heightAnchor.constraint(equalToConstant: 20)
|
||||
])
|
||||
|
||||
// selectedArticlesCancellable = sceneModel?.timelineModel.$selectedArticles.sink { [weak self] articles in
|
||||
// self?.articles = articles
|
||||
// }
|
||||
|
||||
sceneModel?.timelineModel.selectedArticlesPublisher?.sink { [weak self] articles in
|
||||
self?.articles = articles
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
Loading…
x
Reference in New Issue
Block a user