2021-08-29 21:36:18 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppSidebarPlaylists: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
|
|
|
private var player = PlayerModel.shared
|
|
|
|
@ObservedObject private var playlists = PlaylistsModel.shared
|
2021-08-29 21:36:18 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Section(header: Text("Playlists")) {
|
2021-09-25 08:18:22 +00:00
|
|
|
ForEach(playlists.playlists.sorted { $0.title.lowercased() < $1.title.lowercased() }) { playlist in
|
2021-09-28 23:01:49 +00:00
|
|
|
NavigationLink(tag: TabSelection.playlist(playlist.id), selection: $navigation.tabSelection) {
|
2022-12-10 21:37:14 +00:00
|
|
|
LazyView(PlaylistVideosView(playlist).modifier(PlayerOverlayModifier()))
|
2021-08-29 21:36:18 +00:00
|
|
|
} label: {
|
2022-04-10 15:07:10 +00:00
|
|
|
playlistLabel(playlist)
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
2021-08-31 21:17:50 +00:00
|
|
|
.id(playlist.id)
|
2021-08-29 21:36:18 +00:00
|
|
|
.contextMenu {
|
2022-01-02 19:39:54 +00:00
|
|
|
Button("Play All") {
|
|
|
|
player.play(playlists.find(id: playlist.id)?.videos ?? [])
|
|
|
|
}
|
2022-09-04 15:23:02 +00:00
|
|
|
Button("Shuffle All") {
|
|
|
|
player.play(playlists.find(id: playlist.id)?.videos ?? [], shuffling: true)
|
|
|
|
}
|
2021-08-29 21:36:18 +00:00
|
|
|
Button("Edit") {
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.presentEditPlaylistForm(playlists.find(id: playlist.id))
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newPlaylistButton
|
|
|
|
.padding(.top, 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-10 15:07:10 +00:00
|
|
|
@ViewBuilder func playlistLabel(_ playlist: Playlist) -> some View {
|
|
|
|
let label = Label(playlist.title, systemImage: RecentsModel.symbolSystemImage(playlist.title))
|
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
if accounts.app.userPlaylistsEndpointIncludesVideos, !playlist.videos.isEmpty {
|
2022-04-10 15:07:10 +00:00
|
|
|
label
|
|
|
|
.backport
|
|
|
|
.badge(Text("\(playlist.videos.count)"))
|
|
|
|
} else {
|
|
|
|
label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-29 21:36:18 +00:00
|
|
|
var newPlaylistButton: some View {
|
2021-09-25 08:18:22 +00:00
|
|
|
Button(action: { navigation.presentNewPlaylistForm() }) {
|
|
|
|
Label("New Playlist", systemImage: "plus.circle")
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
}
|