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