Add loading status to vertical cells

This commit is contained in:
Arkadiusz Fal
2023-05-27 01:14:48 +02:00
parent eaeaa45422
commit c6cff4dee4
12 changed files with 177 additions and 126 deletions

View File

@@ -15,15 +15,14 @@ struct ChannelPlaylistView: View {
var player = PlayerModel.shared
@ObservedObject private var recents = RecentsModel.shared
@State private var isLoading = false
private var items: [ContentItem] {
ContentItem.array(of: store.item?.videos ?? [])
}
private var resource: Resource? {
let resource = accounts.api.channelPlaylist(playlist.id)
resource?.addObserver(store)
return resource
accounts.api.channelPlaylist(playlist.id)
}
var body: some View {
@@ -48,7 +47,7 @@ struct ChannelPlaylistView: View {
.labelStyle(.iconOnly)
}
#endif
VerticalCells(items: items)
VerticalCells(items: items, isLoading: isLoading)
.environment(\.inChannelPlaylistView, true)
}
.environment(\.listingStyle, channelPlaylistListingStyle)
@@ -56,11 +55,16 @@ struct ChannelPlaylistView: View {
if let cache = ChannelPlaylistsCacheModel.shared.retrievePlaylist(playlist) {
store.replace(cache)
}
resource?.loadIfNeeded()?.onSuccess { response in
if let playlist: ChannelPlaylist = response.typedContent() {
ChannelPlaylistsCacheModel.shared.storePlaylist(playlist: playlist)
isLoading = true
resource?
.load()
.onSuccess { response in
if let playlist: ChannelPlaylist = response.typedContent() {
ChannelPlaylistsCacheModel.shared.storePlaylist(playlist: playlist)
store.replace(playlist)
}
}
}
.onCompletion { _ in isLoading = false }
}
#if os(tvOS)
.background(Color.background(scheme: colorScheme))

View File

@@ -65,7 +65,7 @@ struct ChannelVideosView: View {
.frame(maxWidth: .infinity)
#endif
VerticalCells(items: contentItems, edgesIgnoringSafeArea: verticalCellsEdgesIgnoringSafeArea) {
VerticalCells(items: contentItems, isLoading: resource?.isLoading ?? false, edgesIgnoringSafeArea: verticalCellsEdgesIgnoringSafeArea) {
if let description = presentedChannel?.description, !description.isEmpty {
Button {
withAnimation(.spring()) {