2021-06-28 20:57:53 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoContextMenuView: View {
|
2021-07-12 02:22:49 +05:30
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
2021-08-26 03:42:59 +05:30
|
|
|
@EnvironmentObject<Subscriptions> private var subscriptions
|
2021-06-28 20:57:53 +05:30
|
|
|
|
|
|
|
let video: Video
|
|
|
|
|
2021-07-09 20:23:53 +05:30
|
|
|
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
|
|
|
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
|
|
|
|
|
2021-08-26 03:42:59 +05:30
|
|
|
@State private var subscribed = false
|
|
|
|
|
2021-06-28 20:57:53 +05:30
|
|
|
var body: some View {
|
2021-08-26 03:42:59 +05:30
|
|
|
Section {
|
2021-09-01 02:47:50 +05:30
|
|
|
if navigationState.showOpenChannel(video.channel.id) {
|
|
|
|
openChannelButton
|
|
|
|
}
|
2021-08-26 03:42:59 +05:30
|
|
|
|
|
|
|
subscriptionButton
|
|
|
|
.opacity(subscribed ? 1 : 1)
|
2021-07-08 04:09:18 +05:30
|
|
|
|
2021-08-26 03:42:59 +05:30
|
|
|
openVideoDetailsButton
|
2021-07-09 20:23:53 +05:30
|
|
|
|
2021-08-26 03:42:59 +05:30
|
|
|
if navigationState.tabSelection == .playlists {
|
|
|
|
removeFromPlaylistButton
|
|
|
|
} else {
|
|
|
|
addToPlaylistButton
|
|
|
|
}
|
2021-07-08 04:09:18 +05:30
|
|
|
}
|
2021-06-28 20:57:53 +05:30
|
|
|
}
|
|
|
|
|
2021-08-26 03:42:59 +05:30
|
|
|
var openChannelButton: some View {
|
2021-06-28 20:57:53 +05:30
|
|
|
Button("\(video.author) Channel") {
|
2021-08-26 03:42:59 +05:30
|
|
|
navigationState.openChannel(video.channel)
|
2021-09-14 02:11:16 +05:30
|
|
|
navigationState.tabSelection = .channel(video.channel.id)
|
2021-09-01 02:47:50 +05:30
|
|
|
navigationState.sidebarSectionChanged.toggle()
|
2021-06-28 20:57:53 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 03:42:59 +05:30
|
|
|
var subscriptionButton: some View {
|
|
|
|
Group {
|
2021-09-01 02:47:50 +05:30
|
|
|
if subscriptions.isSubscribing(video.channel.id) {
|
2021-08-26 03:42:59 +05:30
|
|
|
Button("Unsubscribe", role: .destructive) {
|
2021-09-01 02:47:50 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
|
|
#else
|
|
|
|
navigationState.presentUnsubscribeAlert(video.channel)
|
|
|
|
#endif
|
2021-08-26 03:42:59 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button("Subscribe") {
|
2021-09-01 02:47:50 +05:30
|
|
|
subscriptions.subscribe(video.channel.id) {
|
|
|
|
navigationState.sidebarSectionChanged.toggle()
|
|
|
|
}
|
2021-08-26 03:42:59 +05:30
|
|
|
}
|
|
|
|
}
|
2021-06-28 20:57:53 +05:30
|
|
|
}
|
|
|
|
}
|
2021-07-09 20:23:53 +05:30
|
|
|
|
|
|
|
var openVideoDetailsButton: some View {
|
|
|
|
Button("Open video details") {
|
2021-07-12 02:22:49 +05:30
|
|
|
navigationState.openVideoDetails(video)
|
2021-07-09 20:23:53 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var addToPlaylistButton: some View {
|
|
|
|
Button("Add to playlist...") {
|
|
|
|
videoIDToAddToPlaylist = video.id
|
|
|
|
showingAddToPlaylist = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var removeFromPlaylistButton: some View {
|
|
|
|
Button("Remove from playlist", role: .destructive) {
|
|
|
|
let resource = InvidiousAPI.shared.playlistVideo(Defaults[.selectedPlaylistID]!, video.indexID!)
|
|
|
|
resource.request(.delete).onSuccess { _ in
|
|
|
|
InvidiousAPI.shared.playlists.load()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 20:57:53 +05:30
|
|
|
}
|