2021-06-28 16:13:07 +05:30
|
|
|
import Siesta
|
2021-06-26 15:09:35 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlaylistsView: View {
|
2021-06-28 16:13:07 +05:30
|
|
|
@ObservedObject private var store = Store<[Playlist]>()
|
2021-06-26 15:09:35 +05:30
|
|
|
|
|
|
|
@State private var selectedPlaylist: Playlist?
|
|
|
|
|
2021-06-28 16:13:07 +05:30
|
|
|
var resource: Resource {
|
|
|
|
InvidiousAPI.shared.playlists
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
resource.addObserver(store)
|
|
|
|
}
|
|
|
|
|
2021-06-26 15:09:35 +05:30
|
|
|
var body: some View {
|
|
|
|
Section {
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
|
HStack(alignment: .top) {
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
selectPlaylistButton
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.bottom, 5)
|
|
|
|
|
2021-06-28 16:13:07 +05:30
|
|
|
Spacer()
|
|
|
|
|
2021-06-26 15:09:35 +05:30
|
|
|
VStack {
|
2021-06-28 16:13:07 +05:30
|
|
|
if currentPlaylist != nil {
|
|
|
|
VideosView(videos: currentPlaylist!.videos)
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 16:13:07 +05:30
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|
2021-06-28 16:13:07 +05:30
|
|
|
}
|
2021-06-26 15:09:35 +05:30
|
|
|
|
2021-06-28 16:13:07 +05:30
|
|
|
var currentPlaylist: Playlist? {
|
|
|
|
selectedPlaylist ?? store.collection.first
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var selectPlaylistButton: some View {
|
2021-06-28 16:13:07 +05:30
|
|
|
Button(currentPlaylist?.title ?? "Select playlist") {
|
|
|
|
guard currentPlaylist != nil else {
|
2021-06-26 15:09:35 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-28 16:13:07 +05:30
|
|
|
selectedPlaylist = store.collection.next(after: currentPlaylist!)
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|
|
|
|
.contextMenu {
|
2021-06-28 16:13:07 +05:30
|
|
|
ForEach(store.collection) { playlist in
|
2021-06-26 15:09:35 +05:30
|
|
|
Button(playlist.title) {
|
|
|
|
selectedPlaylist = playlist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|