Move error handling to SceneNavigationView
This commit is contained in:
parent
cf233f4825
commit
e34dbd48ee
|
@ -22,6 +22,8 @@ final class SceneModel: ObservableObject {
|
||||||
@Published var openInBrowserButtonState: Bool?
|
@Published var openInBrowserButtonState: Bool?
|
||||||
@Published var shareButtonState: Bool?
|
@Published var shareButtonState: Bool?
|
||||||
|
|
||||||
|
@Published var accountErrorMessage = ""
|
||||||
|
|
||||||
var selectedArticles: [Article] {
|
var selectedArticles: [Article] {
|
||||||
timelineModel.selectedArticles
|
timelineModel.selectedArticles
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct SceneNavigationView: View {
|
||||||
@StateObject private var sceneModel = SceneModel()
|
@StateObject private var sceneModel = SceneModel()
|
||||||
@State private var showSheet = false
|
@State private var showSheet = false
|
||||||
@State private var showShareSheet = false
|
@State private var showShareSheet = false
|
||||||
|
@State private var showRefreshError = false
|
||||||
@State private var sheetToShow: ToolbarSheets = .none
|
@State private var sheetToShow: ToolbarSheets = .none
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
@ -63,6 +64,19 @@ struct SceneNavigationView: View {
|
||||||
.onChange(of: sheetToShow) { value in
|
.onChange(of: sheetToShow) { value in
|
||||||
value != .none ? (showSheet = true) : (showSheet = false)
|
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 {
|
.toolbar {
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
|
|
@ -14,12 +14,10 @@ struct SidebarView: View {
|
||||||
// I had to comment out SceneStorage because it blows up if used on macOS
|
// I had to comment out SceneStorage because it blows up if used on macOS
|
||||||
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
|
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
|
||||||
@StateObject private var expandedContainers = SidebarExpandedContainers()
|
@StateObject private var expandedContainers = SidebarExpandedContainers()
|
||||||
|
@EnvironmentObject private var sceneModel: SceneModel
|
||||||
@EnvironmentObject private var sidebarModel: SidebarModel
|
@EnvironmentObject private var sidebarModel: SidebarModel
|
||||||
@State var navigate = false
|
@State var navigate = false
|
||||||
|
|
||||||
@State var refreshErrorMessage = ""
|
|
||||||
@State var showRefreshError: Bool = false
|
|
||||||
|
|
||||||
private let threshold: CGFloat = 80
|
private let threshold: CGFloat = 80
|
||||||
@State private var previousScrollOffset: CGFloat = 0
|
@State private var previousScrollOffset: CGFloat = 0
|
||||||
@State private var scrollOffset: CGFloat = 0
|
@State private var scrollOffset: CGFloat = 0
|
||||||
|
@ -71,9 +69,6 @@ struct SidebarView: View {
|
||||||
ProgressView().offset(y: -40)
|
ProgressView().offset(y: -40)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(isPresented: $showRefreshError) {
|
|
||||||
Alert(title: Text("Account Error"), message: Text(verbatim: refreshErrorMessage), dismissButton: .default(Text("OK")))
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
// .onAppear {
|
// .onAppear {
|
||||||
// expandedContainers.data = expandedContainerData
|
// expandedContainers.data = expandedContainerData
|
||||||
|
@ -106,8 +101,7 @@ struct SidebarView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRefreshError(_ error: Error) {
|
func handleRefreshError(_ error: Error) {
|
||||||
refreshErrorMessage = error.localizedDescription
|
sceneModel.accountErrorMessage = error.localizedDescription
|
||||||
showRefreshError = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RefreshFixedView: View {
|
struct RefreshFixedView: View {
|
||||||
|
|
Loading…
Reference in New Issue