mirror of
https://github.com/yattee/yattee.git
synced 2025-12-23 05:00:13 +00:00
Playlists and channels in the sidebar
This commit is contained in:
35
Model/Playlists.swift
Normal file
35
Model/Playlists.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
final class Playlists: ObservableObject {
|
||||
@Published var playlists = [Playlist]()
|
||||
|
||||
var resource: Resource {
|
||||
InvidiousAPI.shared.playlists
|
||||
}
|
||||
|
||||
init() {
|
||||
load()
|
||||
}
|
||||
|
||||
var all: [Playlist] {
|
||||
playlists.sorted { $0.title.lowercased() < $1.title.lowercased() }
|
||||
}
|
||||
|
||||
func find(id: Playlist.ID) -> Playlist? {
|
||||
all.first { $0.id == id }
|
||||
}
|
||||
|
||||
func reload() {
|
||||
load()
|
||||
}
|
||||
|
||||
fileprivate func load() {
|
||||
resource.load().onSuccess { resource in
|
||||
if let playlists: [Playlist] = resource.typedContent() {
|
||||
self.playlists = playlists
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user