Pull to refresh fixes, added alert for playlist error

This commit is contained in:
Arkadiusz Fal 2022-09-04 17:24:07 +02:00
parent 14b0316724
commit dffcfc8b06
5 changed files with 35 additions and 8 deletions

View File

@ -53,8 +53,9 @@ final class PlaylistsModel: ObservableObject {
onSuccess()
}
}
.onFailure { _ in
.onFailure { error in
self.playlists = []
NavigationModel.shared.presentAlert(title: "Could not refresh Playlists", message: error.userMessage)
}
}

View File

@ -129,6 +129,21 @@ struct PlaylistsView: View {
.onChange(of: model.reloadPlaylists) { _ in
resource?.load()
}
#if os(iOS)
.refreshControl { refreshControl in
model.load(force: true) {
model.reloadPlaylists.toggle()
refreshControl.endRefreshing()
}
}
.backport
.refreshable {
DispatchQueue.main.async {
model.load(force: true) { model.reloadPlaylists.toggle() }
}
}
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if os(tvOS)
.fullScreenCover(isPresented: $showingNewPlaylist, onDismiss: selectCreatedPlaylist) {
PlaylistFormView(playlist: $createdPlaylist)
@ -155,15 +170,22 @@ struct PlaylistsView: View {
}
)
#endif
#if os(iOS)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
model.load()
resource?.loadIfNeeded()
}
#endif
#if !os(tvOS)
.background(
Button("Refresh") {
resource?.load()
}
.keyboardShortcut("r")
.opacity(0)
)
#endif
}
#if os(tvOS)

View File

@ -140,10 +140,12 @@ struct TrendingView: View {
}
.backport
.refreshable {
DispatchQueue.main.async {
resource.load().onFailure { error in
NavigationModel.shared.presentAlert(title: "Could not refresh Trending", message: error.userMessage)
}
}
}
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)

View File

@ -50,8 +50,10 @@ struct PopularView: View {
}
.backport
.refreshable {
DispatchQueue.main.async {
resource?.load()
}
}
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
#endif
#if !os(macOS)

View File

@ -32,7 +32,7 @@ struct SubscriptionsView: View {
}
.backport
.refreshable {
loadResources(force: true)
await loadResources(force: true)
}
#endif
}