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