2021-06-28 15:27:53 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoContextMenuView: View {
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<InvidiousAPI> private var api
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-09-28 18:06:05 +00:00
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
2021-09-25 12:17:58 +00:00
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-06-28 15:27:53 +00:00
|
|
|
|
|
|
|
let video: Video
|
|
|
|
|
|
|
|
var body: some View {
|
2021-08-25 22:12:59 +00:00
|
|
|
Section {
|
2021-09-19 11:06:54 +00:00
|
|
|
openChannelButton
|
2021-08-25 22:12:59 +00:00
|
|
|
|
|
|
|
subscriptionButton
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-09-28 18:06:05 +00:00
|
|
|
if case let .playlist(id) = navigation.tabSelection {
|
|
|
|
removeFromPlaylistButton(playlistID: id)
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
if navigation.tabSelection == .playlists {
|
2021-09-28 18:06:05 +00:00
|
|
|
removeFromPlaylistButton(playlistID: playlists.currentPlaylist!.id)
|
2021-08-25 22:12:59 +00:00
|
|
|
} else {
|
|
|
|
addToPlaylistButton
|
|
|
|
}
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
var openChannelButton: some View {
|
2021-06-28 15:27:53 +00:00
|
|
|
Button("\(video.author) Channel") {
|
2021-09-19 11:06:54 +00:00
|
|
|
let recent = RecentItem(from: video.channel)
|
2021-09-28 18:06:05 +00:00
|
|
|
recents.add(recent)
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.tabSelection = .recentlyOpened(recent.tag)
|
|
|
|
navigation.isChannelOpen = true
|
|
|
|
navigation.sidebarSectionChanged.toggle()
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
var subscriptionButton: some View {
|
|
|
|
Group {
|
2021-08-31 21:17:50 +00:00
|
|
|
if subscriptions.isSubscribing(video.channel.id) {
|
2021-08-25 22:12:59 +00:00
|
|
|
Button("Unsubscribe", role: .destructive) {
|
2021-08-31 21:17:50 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
|
|
#else
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.presentUnsubscribeAlert(video.channel)
|
2021-08-31 21:17:50 +00:00
|
|
|
#endif
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button("Subscribe") {
|
2021-08-31 21:17:50 +00:00
|
|
|
subscriptions.subscribe(video.channel.id) {
|
2021-09-25 08:18:22 +00:00
|
|
|
navigation.sidebarSectionChanged.toggle()
|
2021-08-31 21:17:50 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-09 14:53:53 +00:00
|
|
|
|
|
|
|
var addToPlaylistButton: some View {
|
|
|
|
Button("Add to playlist...") {
|
2021-09-28 18:06:05 +00:00
|
|
|
navigation.presentAddToPlaylist(video)
|
2021-07-09 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 18:06:05 +00:00
|
|
|
func removeFromPlaylistButton(playlistID: String) -> some View {
|
2021-07-09 14:53:53 +00:00
|
|
|
Button("Remove from playlist", role: .destructive) {
|
2021-09-28 18:06:05 +00:00
|
|
|
playlists.removeVideoFromPlaylist(videoIndexID: video.indexID!, playlistID: playlistID)
|
2021-07-09 14:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|