mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Playlists and channels in the sidebar
This commit is contained in:
@@ -3,7 +3,7 @@ import Defaults
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
struct Channel: Codable, Defaults.Serializable {
|
||||
struct Channel: Codable, Identifiable, Defaults.Serializable {
|
||||
var id: String
|
||||
var name: String
|
||||
var subscriptionsCount: String
|
||||
|
@@ -54,6 +54,10 @@ final class InvidiousAPI: Service {
|
||||
content.json.arrayValue.map(Playlist.init)
|
||||
}
|
||||
|
||||
configureTransformer("/auth/playlists/*", requestMethods: [.get]) { (content: Entity<JSON>) -> Playlist in
|
||||
Playlist(content.json)
|
||||
}
|
||||
|
||||
configureTransformer("/auth/playlists", requestMethods: [.post, .patch]) { (content: Entity<Data>) -> Playlist in
|
||||
// hacky, to verify if possible to get it in easier way
|
||||
Playlist(JSON(parseJSON: String(data: content.content, encoding: .utf8)!))
|
||||
|
@@ -2,6 +2,10 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class NavigationState: ObservableObject {
|
||||
enum TabSelection: Hashable {
|
||||
case subscriptions, popular, trending, playlists, channel(String), playlist(String), search
|
||||
}
|
||||
|
||||
@Published var tabSelection: TabSelection = .subscriptions
|
||||
|
||||
@Published var showingChannel = false
|
||||
@@ -13,6 +17,12 @@ final class NavigationState: ObservableObject {
|
||||
|
||||
@Published var returnToDetails = false
|
||||
|
||||
@Published var presentingPlaylistForm = false
|
||||
@Published var editedPlaylist: Playlist!
|
||||
|
||||
@Published var presentingUnsubscribeAlert = false
|
||||
@Published var channelToUnsubscribe: Channel!
|
||||
|
||||
func openChannel(_ channel: Channel) {
|
||||
returnToDetails = false
|
||||
self.channel = channel
|
||||
@@ -54,4 +64,21 @@ final class NavigationState: ObservableObject {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func presentEditPlaylistForm(_ playlist: Playlist?) {
|
||||
editedPlaylist = playlist
|
||||
presentingPlaylistForm = editedPlaylist != nil
|
||||
}
|
||||
|
||||
func presentNewPlaylistForm() {
|
||||
editedPlaylist = nil
|
||||
presentingPlaylistForm = true
|
||||
}
|
||||
|
||||
func presentUnsubscribeAlert(_ channel: Channel?) {
|
||||
channelToUnsubscribe = channel
|
||||
presentingUnsubscribeAlert = channelToUnsubscribe != nil
|
||||
}
|
||||
}
|
||||
|
||||
typealias TabSelection = NavigationState.TabSelection
|
||||
|
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,6 +13,10 @@ final class Subscriptions: ObservableObject {
|
||||
load()
|
||||
}
|
||||
|
||||
var all: [Channel] {
|
||||
channels.sorted { $0.name.lowercased() < $1.name.lowercased() }
|
||||
}
|
||||
|
||||
func subscribe(_ channelID: String) {
|
||||
performChannelSubscriptionRequest(channelID, method: .post)
|
||||
}
|
||||
|
Reference in New Issue
Block a user