mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Channel playlists cache
This commit is contained in:
@@ -94,19 +94,19 @@ struct PlaylistsView: View {
|
||||
}
|
||||
.onAppear {
|
||||
model.load()
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
model.load(force: true)
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
.onChange(of: currentPlaylist) { _ in
|
||||
channelPlaylist.clear()
|
||||
userPlaylist.clear()
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
.onChange(of: model.reloadPlaylists) { _ in
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
@@ -154,7 +154,7 @@ struct PlaylistsView: View {
|
||||
#if !os(macOS)
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
model.load()
|
||||
resource?.loadIfNeeded()
|
||||
loadResource()
|
||||
}
|
||||
#endif
|
||||
#if !os(tvOS)
|
||||
@@ -168,6 +168,26 @@ struct PlaylistsView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
func loadResource() {
|
||||
loadCachedResource()
|
||||
resource?.load()
|
||||
.onSuccess { response in
|
||||
if let playlist: Playlist = response.typedContent() {
|
||||
ChannelPlaylistsCacheModel.shared.storePlaylist(playlist: playlist.channelPlaylist)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadCachedResource() {
|
||||
if !selectedPlaylistID.isEmpty,
|
||||
let cache = ChannelPlaylistsCacheModel.shared.retrievePlaylist(selectedPlaylistID)
|
||||
{
|
||||
DispatchQueue.main.async {
|
||||
self.channelPlaylist.replace(cache)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var playlistsMenu: some View {
|
||||
Menu {
|
||||
|
@@ -2,7 +2,7 @@ import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct PlaylistVideosView: View {
|
||||
let playlist: Playlist
|
||||
var playlist: Playlist
|
||||
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
var player = PlayerModel.shared
|
||||
@@ -43,6 +43,24 @@ struct PlaylistVideosView: View {
|
||||
return resource
|
||||
}
|
||||
|
||||
func loadResource() {
|
||||
loadCachedResource()
|
||||
resource?.load()
|
||||
.onSuccess { response in
|
||||
if let playlist: Playlist = response.typedContent() {
|
||||
ChannelPlaylistsCacheModel.shared.storePlaylist(playlist: playlist.channelPlaylist)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadCachedResource() {
|
||||
if let cache = ChannelPlaylistsCacheModel.shared.retrievePlaylist(playlist.id) {
|
||||
DispatchQueue.main.async {
|
||||
self.channelPlaylist.replace(cache)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var videos: [Video] {
|
||||
contentItems.compactMap(\.video)
|
||||
}
|
||||
@@ -55,10 +73,10 @@ struct PlaylistVideosView: View {
|
||||
VerticalCells(items: contentItems)
|
||||
.onAppear {
|
||||
guard contentItems.isEmpty else { return }
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
.onChange(of: model.reloadPlaylists) { _ in
|
||||
resource?.load()
|
||||
loadResource()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
|
Reference in New Issue
Block a user