diff --git a/Model/Applications/VideosApp.swift b/Model/Applications/VideosApp.swift index c4f9b816..32567e99 100644 --- a/Model/Applications/VideosApp.swift +++ b/Model/Applications/VideosApp.swift @@ -39,6 +39,10 @@ enum VideosApp: String, CaseIterable { self == .invidious } + var userPlaylistsUseChannelPlaylistEndpoint: Bool { + self == .piped + } + var userPlaylistsHaveVisibility: Bool { self == .invidious } diff --git a/Shared/Navigation/AppSidebarPlaylists.swift b/Shared/Navigation/AppSidebarPlaylists.swift index a34defb4..20f5c16b 100644 --- a/Shared/Navigation/AppSidebarPlaylists.swift +++ b/Shared/Navigation/AppSidebarPlaylists.swift @@ -32,7 +32,7 @@ struct AppSidebarPlaylists: View { @ViewBuilder func playlistLabel(_ playlist: Playlist) -> some View { let label = Label(playlist.title, systemImage: RecentsModel.symbolSystemImage(playlist.title)) - if player.accounts.app.userPlaylistsEndpointIncludesVideos { + if player.accounts.app.userPlaylistsEndpointIncludesVideos, !playlist.videos.isEmpty { label .backport .badge(Text("\(playlist.videos.count)")) diff --git a/Shared/Playlists/PlaylistsView.swift b/Shared/Playlists/PlaylistsView.swift index f0f36ee2..f680d62d 100644 --- a/Shared/Playlists/PlaylistsView.swift +++ b/Shared/Playlists/PlaylistsView.swift @@ -11,7 +11,8 @@ struct PlaylistsView: View { @State private var showingEditPlaylist = false @State private var editedPlaylist: Playlist? - @StateObject private var store = Store() + @StateObject private var channelPlaylist = Store() + @StateObject private var userPlaylist = Store() @EnvironmentObject private var accounts @EnvironmentObject private var player @@ -23,7 +24,8 @@ struct PlaylistsView: View { var videos = currentPlaylist?.videos ?? [] if videos.isEmpty { - videos = store.item?.videos ?? [] + videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? [] + if !player.accounts.app.userPlaylistsEndpointIncludesVideos { var i = 0 @@ -40,14 +42,15 @@ struct PlaylistsView: View { } private var resource: Resource? { - guard !player.accounts.app.userPlaylistsEndpointIncludesVideos, - let playlist = currentPlaylist - else { - return nil - } + guard let playlist = currentPlaylist else { return nil } let resource = player.accounts.api.playlist(playlist.id) - resource?.addObserver(store) + + if player.accounts.app.userPlaylistsUseChannelPlaylistEndpoint { + resource?.addObserver(channelPlaylist) + } else { + resource?.addObserver(userPlaylist) + } return resource } @@ -118,8 +121,9 @@ struct PlaylistsView: View { } .onChange(of: accounts.current) { _ in model.load(force: true) + resource?.load() } - .onChange(of: selectedPlaylistID) { _ in + .onChange(of: currentPlaylist) { _ in resource?.load() } .onChange(of: model.reloadPlaylists) { _ in diff --git a/Shared/Views/PlaylistVideosView.swift b/Shared/Views/PlaylistVideosView.swift index 33cea394..b7d139f3 100644 --- a/Shared/Views/PlaylistVideosView.swift +++ b/Shared/Views/PlaylistVideosView.swift @@ -7,13 +7,14 @@ struct PlaylistVideosView: View { @EnvironmentObject private var player @EnvironmentObject private var model - @StateObject private var store = Store() + @StateObject private var channelPlaylist = Store() + @StateObject private var userPlaylist = Store() var contentItems: [ContentItem] { var videos = playlist.videos if videos.isEmpty { - videos = store.item?.videos ?? [] + videos = userPlaylist.item?.videos ?? channelPlaylist.item?.videos ?? [] if !player.accounts.app.userPlaylistsEndpointIncludesVideos { var i = 0 @@ -31,7 +32,12 @@ struct PlaylistVideosView: View { private var resource: Resource? { let resource = player.accounts.api.playlist(playlist.id) - resource?.addObserver(store) + + if player.accounts.app.userPlaylistsUseChannelPlaylistEndpoint { + resource?.addObserver(channelPlaylist) + } else { + resource?.addObserver(userPlaylist) + } return resource } @@ -48,9 +54,8 @@ struct PlaylistVideosView: View { BrowserPlayerControls { VerticalCells(items: contentItems) .onAppear { - if !player.accounts.app.userPlaylistsEndpointIncludesVideos { - resource?.load() - } + guard contentItems.isEmpty else { return } + resource?.load() } .onChange(of: model.reloadPlaylists) { _ in resource?.load()