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-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-06-28 15:27:53 +00:00
|
|
|
var body: some View {
|
2021-07-11 20:52:49 +00:00
|
|
|
if navigationState.tabSelection == .channel {
|
2021-06-28 15:27:53 +00:00
|
|
|
closeChannelButton(from: video)
|
|
|
|
} else {
|
|
|
|
openChannelButton(from: video)
|
|
|
|
}
|
2021-07-07 22:39:18 +00:00
|
|
|
|
2021-07-09 14:53:53 +00:00
|
|
|
openVideoDetailsButton
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
if navigationState.tabSelection == .playlists {
|
2021-07-09 14:53:53 +00:00
|
|
|
removeFromPlaylistButton
|
|
|
|
} else {
|
|
|
|
addToPlaylistButton
|
2021-07-07 22:39:18 +00:00
|
|
|
}
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func openChannelButton(from video: Video) -> some View {
|
|
|
|
Button("\(video.author) Channel") {
|
2021-07-11 20:52:49 +00:00
|
|
|
navigationState.openChannel(Channel.from(video: video))
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeChannelButton(from video: Video) -> some View {
|
|
|
|
Button("Close \(Channel.from(video: video).name) Channel") {
|
2021-07-11 20:52:49 +00:00
|
|
|
navigationState.closeChannel()
|
2021-06-28 15:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-09 14:53:53 +00:00
|
|
|
|
|
|
|
var openVideoDetailsButton: some View {
|
|
|
|
Button("Open video details") {
|
2021-07-11 20:52:49 +00:00
|
|
|
navigationState.openVideoDetails(video)
|
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
|
|
|
}
|