mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Less obnoxious error handling
This commit is contained in:
@@ -7,6 +7,8 @@ struct PopularView: View {
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
@State private var error: RequestError?
|
||||
|
||||
@Default(.popularListingStyle) private var popularListingStyle
|
||||
|
||||
var resource: Resource? {
|
||||
@@ -21,7 +23,9 @@ struct PopularView: View {
|
||||
VerticalCells(items: videos)
|
||||
.onAppear {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
resource?.loadIfNeeded()?
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
.environment(\.listingStyle, popularListingStyle)
|
||||
#if !os(tvOS)
|
||||
@@ -29,6 +33,8 @@ struct PopularView: View {
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
resource?.load()
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
@@ -45,14 +51,15 @@ struct PopularView: View {
|
||||
resource?.load().onCompletion { _ in
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
.onFailure { error in
|
||||
NavigationModel.shared.presentAlert(title: "Could not refresh Popular", message: error.userMessage)
|
||||
}
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
.backport
|
||||
.refreshable {
|
||||
DispatchQueue.main.async {
|
||||
resource?.load()
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
}
|
||||
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
||||
@@ -65,7 +72,9 @@ struct PopularView: View {
|
||||
}
|
||||
#else
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
resource?.loadIfNeeded()
|
||||
resource?.loadIfNeeded()?
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
23
Shared/Views/RequestErrorButton.swift
Normal file
23
Shared/Views/RequestErrorButton.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct RequestErrorButton: View {
|
||||
var error: RequestError?
|
||||
|
||||
var body: some View {
|
||||
if let error {
|
||||
Button {
|
||||
NavigationModel.shared.presentRequestErrorAlert(error)
|
||||
} label: {
|
||||
Label("Error", systemImage: "exclamationmark.circle.fill")
|
||||
.foregroundColor(Color("AppRedColor"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RequestErrorButton_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RequestErrorButton()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user