2021-06-28 15:27:53 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoContextMenuView: View {
|
2021-07-11 20:52:49 +00:00
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
2021-09-19 11:06:54 +00:00
|
|
|
@EnvironmentObject<Recents> private var recents
|
2021-08-25 22:12:59 +00:00
|
|
|
@EnvironmentObject<Subscriptions> private var subscriptions
|
2021-06-28 15:27:53 +00:00
|
|
|
|
|
|
|
let video: Video
|
|
|
|
|
2021-07-09 14:53:53 +00:00
|
|
|
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
|
|
|
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
@State private var subscribed = false
|
|
|
|
|
2021-06-28 15:27:53 +00:00
|
|
|
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
|
|
|
|
.opacity(subscribed ? 1 : 1)
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
if navigationState.tabSelection == .playlists {
|
|
|
|
removeFromPlaylistButton
|
|
|
|
} 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)
|
|
|
|
recents.open(recent)
|
|
|
|
navigationState.tabSelection = .recentlyOpened(recent.tag)
|
|
|
|
navigationState.isChannelOpen = true
|
2021-08-31 21:17:50 +00:00
|
|
|
navigationState.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
|
|
|
|
navigationState.presentUnsubscribeAlert(video.channel)
|
|
|
|
#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) {
|
|
|
|
navigationState.sidebarSectionChanged.toggle()
|
|
|
|
}
|
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...") {
|
|
|
|
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 15:27:53 +00:00
|
|
|
}
|