Move error handling to SceneNavigationView

This commit is contained in:
Maurice Parker 2020-07-15 20:06:29 -05:00
parent cf233f4825
commit e34dbd48ee
3 changed files with 18 additions and 8 deletions

View File

@ -22,6 +22,8 @@ final class SceneModel: ObservableObject {
@Published var openInBrowserButtonState: Bool?
@Published var shareButtonState: Bool?
@Published var accountErrorMessage = ""
var selectedArticles: [Article] {
timelineModel.selectedArticles
}

View File

@ -13,6 +13,7 @@ struct SceneNavigationView: View {
@StateObject private var sceneModel = SceneModel()
@State private var showSheet = false
@State private var showShareSheet = false
@State private var showRefreshError = false
@State private var sheetToShow: ToolbarSheets = .none
#if os(iOS)
@ -63,6 +64,19 @@ struct SceneNavigationView: View {
.onChange(of: sheetToShow) { value in
value != .none ? (showSheet = true) : (showSheet = false)
}
.onChange(of: showRefreshError) { value in
if !value {
sceneModel.accountErrorMessage = ""
}
}
.onReceive(sceneModel.$accountErrorMessage) { message in
if !message.isEmpty {
showRefreshError = true
}
}
.alert(isPresented: $showRefreshError) {
Alert(title: Text("Account Error"), message: Text(verbatim: sceneModel.accountErrorMessage), dismissButton: .default(Text("OK")))
}
.toolbar {
#if os(macOS)

View File

@ -14,12 +14,10 @@ struct SidebarView: View {
// I had to comment out SceneStorage because it blows up if used on macOS
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
@StateObject private var expandedContainers = SidebarExpandedContainers()
@EnvironmentObject private var sceneModel: SceneModel
@EnvironmentObject private var sidebarModel: SidebarModel
@State var navigate = false
@State var refreshErrorMessage = ""
@State var showRefreshError: Bool = false
private let threshold: CGFloat = 80
@State private var previousScrollOffset: CGFloat = 0
@State private var scrollOffset: CGFloat = 0
@ -71,9 +69,6 @@ struct SidebarView: View {
ProgressView().offset(y: -40)
}
}
.alert(isPresented: $showRefreshError) {
Alert(title: Text("Account Error"), message: Text(verbatim: refreshErrorMessage), dismissButton: .default(Text("OK")))
}
#endif
// .onAppear {
// expandedContainers.data = expandedContainerData
@ -106,8 +101,7 @@ struct SidebarView: View {
}
func handleRefreshError(_ error: Error) {
refreshErrorMessage = error.localizedDescription
showRefreshError = true
sceneModel.accountErrorMessage = error.localizedDescription
}
struct RefreshFixedView: View {