2022-06-18 12:39:49 +00:00
|
|
|
import Defaults
|
2021-11-02 23:02:02 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct RelatedView: View {
|
2022-06-18 12:39:49 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-11-02 23:02:02 +00:00
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2022-06-18 12:39:49 +00:00
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
2021-11-02 23:02:02 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
List {
|
2022-06-18 12:39:49 +00:00
|
|
|
if let related = player.currentVideo?.related {
|
2021-11-02 23:02:02 +00:00
|
|
|
Section(header: Text("Related")) {
|
2022-06-18 12:39:49 +00:00
|
|
|
ForEach(related) { video in
|
|
|
|
PlayerQueueRow(item: PlayerQueueItem(video))
|
2021-12-01 11:22:19 +00:00
|
|
|
.contextMenu {
|
2022-06-18 12:39:49 +00:00
|
|
|
Section {
|
|
|
|
Button {
|
|
|
|
player.playNext(video)
|
|
|
|
} label: {
|
|
|
|
Label("Play Next", systemImage: "text.insert")
|
|
|
|
}
|
|
|
|
Button {
|
|
|
|
player.enqueueVideo(video)
|
|
|
|
} label: {
|
|
|
|
Label("Play Last", systemImage: "text.append")
|
|
|
|
}
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
2022-06-18 12:39:49 +00:00
|
|
|
|
|
|
|
if accounts.app.supportsUserPlaylists && accounts.signedIn {
|
|
|
|
Section {
|
|
|
|
Button {
|
|
|
|
navigation.presentAddToPlaylist(video)
|
|
|
|
} label: {
|
|
|
|
Label("Add to playlist...", systemImage: "text.badge.plus")
|
|
|
|
}
|
|
|
|
|
|
|
|
if let playlist = playlists.lastUsed {
|
|
|
|
Button {
|
|
|
|
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID, navigation: navigation)
|
|
|
|
} label: {
|
|
|
|
Label("Add to \(playlist.title)", systemImage: "text.badge.star")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 11:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if os(macOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.inset)
|
2021-11-02 23:02:02 +00:00
|
|
|
#elseif os(iOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.grouped)
|
2021-11-02 23:02:02 +00:00
|
|
|
#else
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.plain)
|
2021-11-02 23:02:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RelatedView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
RelatedView()
|
|
|
|
}
|
|
|
|
}
|