mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Less obnoxious error handling
This commit is contained in:
@@ -15,8 +15,9 @@ struct PlaylistsView: View {
|
||||
@StateObject private var userPlaylist = Store<Playlist>()
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
private var player = PlayerModel.shared
|
||||
@ObservedObject private var model = PlaylistsModel.shared
|
||||
|
||||
private var player = PlayerModel.shared
|
||||
private var cache = PlaylistsCacheModel.shared
|
||||
|
||||
@Namespace private var focusNamespace
|
||||
@@ -129,6 +130,10 @@ struct PlaylistsView: View {
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
RequestErrorButton(error: model.error)
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .principal) {
|
||||
playlistsMenu
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import Defaults
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@@ -11,6 +12,7 @@ struct SubscriptionsView: View {
|
||||
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
||||
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
||||
|
||||
var body: some View {
|
||||
SignInRequiredView(title: "Subscriptions".localized()) {
|
||||
@@ -32,6 +34,10 @@ struct SubscriptionsView: View {
|
||||
ToolbarItem(placement: .principal) {
|
||||
subscriptionsMenu
|
||||
}
|
||||
|
||||
ToolbarItem {
|
||||
RequestErrorButton(error: requestError)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if os(macOS)
|
||||
@@ -51,6 +57,10 @@ struct SubscriptionsView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
var requestError: RequestError? {
|
||||
subscriptionsViewPage == .channels ? subscriptions.error : feed.error
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var subscriptionsMenu: some View {
|
||||
Menu {
|
||||
|
@@ -21,6 +21,8 @@ struct TrendingView: View {
|
||||
ContentItem.array(of: store.collection)
|
||||
}
|
||||
|
||||
@State private var error: RequestError?
|
||||
|
||||
init(_ videos: [Video] = [Video]()) {
|
||||
self.videos = videos
|
||||
}
|
||||
@@ -52,6 +54,9 @@ struct TrendingView: View {
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
RequestErrorButton(error: error)
|
||||
}
|
||||
#if os(macOS)
|
||||
ToolbarItemGroup {
|
||||
if let favoriteItem {
|
||||
@@ -68,15 +73,14 @@ struct TrendingView: View {
|
||||
}
|
||||
.onChange(of: resource) { _ in
|
||||
resource.load()
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
updateFavoriteItem()
|
||||
}
|
||||
.onAppear {
|
||||
if videos.isEmpty {
|
||||
resource.addObserver(store)
|
||||
resource.loadIfNeeded()
|
||||
} else {
|
||||
store.replace(videos)
|
||||
}
|
||||
resource.loadIfNeeded()?
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
|
||||
updateFavoriteItem()
|
||||
}
|
||||
@@ -95,6 +99,8 @@ struct TrendingView: View {
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
resource.load()
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
@@ -111,6 +117,8 @@ struct TrendingView: View {
|
||||
.refreshable {
|
||||
DispatchQueue.main.async {
|
||||
resource.load()
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -128,7 +136,9 @@ struct TrendingView: View {
|
||||
}
|
||||
#else
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
resource.loadIfNeeded()
|
||||
resource.loadIfNeeded()?
|
||||
.onFailure { self.error = $0 }
|
||||
.onSuccess { _ in self.error = nil }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -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