Launch with correct views instead of using placeholder text views

This commit is contained in:
Maurice Parker 2020-07-18 04:35:44 -05:00
parent be60b112d0
commit 40e0a1b676
5 changed files with 39 additions and 40 deletions

View File

@ -43,6 +43,7 @@ final class SceneModel: ObservableObject {
func startup() { func startup() {
sidebarModel.delegate = self sidebarModel.delegate = self
timelineModel.delegate = self timelineModel.delegate = self
timelineModel.startup()
self.articleIconSchemeHandler = ArticleIconSchemeHandler(sceneModel: self) self.articleIconSchemeHandler = ArticleIconSchemeHandler(sceneModel: self)
self.webViewProvider = WebViewProvider(articleIconSchemeHandler: self.articleIconSchemeHandler!) self.webViewProvider = WebViewProvider(articleIconSchemeHandler: self.articleIconSchemeHandler!)
@ -103,6 +104,10 @@ extension SceneModel: SidebarModelDelegate {
extension SceneModel: TimelineModelDelegate { extension SceneModel: TimelineModelDelegate {
var selectedFeeds: Published<[Feed]>.Publisher {
return sidebarModel.$selectedFeeds
}
func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed) { func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed) {
} }

View File

@ -32,22 +32,13 @@ struct SceneNavigationView: View {
#if os(iOS) #if os(iOS)
if horizontalSizeClass != .compact { if horizontalSizeClass != .compact {
Text("Timeline") TimelineContainerView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
} }
#else #else
Text("Timeline") TimelineContainerView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
#endif #endif
#if os(macOS) ArticleContainerView()
Text("None Selected")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.toolbar { Spacer() }
#else
Text("None Selected")
.frame(maxWidth: .infinity, maxHeight: .infinity)
#endif
} }
.environmentObject(sceneModel) .environmentObject(sceneModel)
.onAppear { .onAppear {

View File

@ -46,7 +46,7 @@ struct SidebarView: View {
.help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds") .help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds")
} }
ZStack(alignment: .bottom) { ZStack(alignment: .bottom) {
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), isActive: $navigate) { NavigationLink(destination: TimelineContainerView(), isActive: $navigate) {
EmptyView() EmptyView()
}.hidden() }.hidden()
List(selection: $sidebarModel.selectedFeedIdentifiers) { List(selection: $sidebarModel.selectedFeedIdentifiers) {
@ -194,7 +194,7 @@ struct SidebarView: View {
#else #else
ZStack { ZStack {
SidebarItemView(sidebarItem: sidebarItem) SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), NavigationLink(destination: TimelineContainerView(),
tag: sidebarItem.feed!.feedID!, tag: sidebarItem.feed!.feedID!,
selection: $sidebarModel.selectedFeedIdentifier) { selection: $sidebarModel.selectedFeedIdentifier) {
EmptyView() EmptyView()

View File

@ -13,19 +13,13 @@ struct TimelineContainerView: View {
@Environment(\.undoManager) var undoManager @Environment(\.undoManager) var undoManager
@EnvironmentObject private var sceneModel: SceneModel @EnvironmentObject private var sceneModel: SceneModel
var feeds: [Feed]? = nil
@ViewBuilder var body: some View { @ViewBuilder var body: some View {
if let feeds = feeds {
TimelineView() TimelineView()
.modifier(TimelineToolbarModifier()) .modifier(TimelineToolbarModifier())
.environmentObject(sceneModel.timelineModel) .environmentObject(sceneModel.timelineModel)
.onAppear { .onAppear {
sceneModel.timelineModel.undoManager = undoManager sceneModel.timelineModel.undoManager = undoManager
sceneModel.timelineModel.fetchArticles(feeds: feeds)
}
} else {
EmptyView()
} }
} }

View File

@ -17,6 +17,7 @@ import Account
import Articles import Articles
protocol TimelineModelDelegate: class { protocol TimelineModelDelegate: class {
var selectedFeeds: Published<[Feed]>.Publisher { get }
func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed) func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed)
} }
@ -35,6 +36,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
var undoManager: UndoManager? var undoManager: UndoManager?
var undoableCommands = [UndoableCommand]() var undoableCommands = [UndoableCommand]()
private var selectedFeedsCancellable: AnyCancellable?
private var selectedArticleIDsCancellable: AnyCancellable? private var selectedArticleIDsCancellable: AnyCancellable?
private var selectedArticleIDCancellable: AnyCancellable? private var selectedArticleIDCancellable: AnyCancellable?
private var selectedArticlesCancellable: AnyCancellable? private var selectedArticlesCancellable: AnyCancellable?
@ -66,6 +68,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
} }
} }
} }
private var groupByFeed = AppDefaults.shared.timelineGroupByFeed { private var groupByFeed = AppDefaults.shared.timelineGroupByFeed {
didSet { didSet {
if groupByFeed != oldValue { if groupByFeed != oldValue {
@ -74,10 +77,16 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
} }
} }
init() { func startup() {
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
// TODO: This should be rewritten to use Combine correctly
selectedFeedsCancellable = delegate?.selectedFeeds.sink { [weak self] feeds in
guard let self = self else { return }
self.fetchArticles(feeds: feeds)
}
// TODO: This should be rewritten to use Combine correctly // TODO: This should be rewritten to use Combine correctly
selectedArticleIDsCancellable = $selectedArticleIDs.sink { [weak self] articleIDs in selectedArticleIDsCancellable = $selectedArticleIDs.sink { [weak self] articleIDs in
guard let self = self else { return } guard let self = self else { return }
@ -106,19 +115,6 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
// MARK: API // MARK: API
func fetchArticles(feeds: [Feed]) {
self.feeds = feeds
if feeds.count == 1 {
nameForDisplay = feeds.first!.nameForDisplay
} else {
nameForDisplay = NSLocalizedString("Multiple", comment: "Multiple Feeds")
}
resetReadFilter()
fetchAndReplaceArticlesAsync()
}
func toggleReadFilter() { func toggleReadFilter() {
guard let filter = isReadFiltered, let feedID = feeds.first?.feedID else { return } guard let filter = isReadFiltered, let feedID = feeds.first?.feedID else { return }
readFilterEnabledTable[feedID] = !filter readFilterEnabledTable[feedID] = !filter
@ -383,6 +379,19 @@ private extension TimelineModel {
// MARK: Article Fetching // MARK: Article Fetching
func fetchArticles(feeds: [Feed]) {
self.feeds = feeds
if feeds.count == 1 {
nameForDisplay = feeds.first!.nameForDisplay
} else {
nameForDisplay = NSLocalizedString("Multiple", comment: "Multiple Feeds")
}
resetReadFilter()
fetchAndReplaceArticlesAsync()
}
func fetchAndReplaceArticlesAsync() { func fetchAndReplaceArticlesAsync() {
var fetchers = feeds as [ArticleFetcher] var fetchers = feeds as [ArticleFetcher]
if let fetcher = exceptionArticleFetcher { if let fetcher = exceptionArticleFetcher {