Caching for favorites

This commit is contained in:
Arkadiusz Fal
2022-12-16 12:31:43 +01:00
parent a2c69e0fed
commit b8f693e213
4 changed files with 75 additions and 26 deletions

View File

@@ -40,7 +40,7 @@ struct Playlist: Identifiable, Equatable, Hashable {
}
var json: JSON {
return [
[
"id": id,
"title": title,
"visibility": visibility.rawValue,
@@ -51,7 +51,7 @@ struct Playlist: Identifiable, Equatable, Hashable {
}
static func from(_ json: JSON) -> Self {
return .init(
.init(
id: json["id"].stringValue,
title: json["title"].stringValue,
visibility: .init(rawValue: json["visibility"].stringValue) ?? .public,

View File

@@ -38,13 +38,15 @@ final class PlaylistsModel: ObservableObject {
}
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
guard accounts.app.supportsUserPlaylists, accounts.signedIn, let account = accounts.current else {
guard accounts.app.supportsUserPlaylists, let account = accounts.current else {
playlists = []
return
}
loadCachedPlaylists(account)
guard accounts.signedIn else { return }
DispatchQueue.main.async { [weak self] in
guard let self else { return }
let request = force ? self.resource?.load() : self.resource?.loadIfNeeded()