yattee/Apple TV/VideoContextMenuView.swift

62 lines
1.7 KiB
Swift
Raw Normal View History

import Defaults
import SwiftUI
struct VideoContextMenuView: View {
2021-07-11 20:52:49 +00:00
@EnvironmentObject<NavigationState> private var navigationState
let video: Video
@Default(.showingAddToPlaylist) var showingAddToPlaylist
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
var body: some View {
2021-07-11 20:52:49 +00:00
if navigationState.tabSelection == .channel {
closeChannelButton(from: video)
} else {
openChannelButton(from: video)
}
2021-07-07 22:39:18 +00:00
openVideoDetailsButton
2021-07-11 20:52:49 +00:00
if navigationState.tabSelection == .playlists {
removeFromPlaylistButton
} else {
addToPlaylistButton
2021-07-07 22:39:18 +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))
}
}
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()
}
}
var openVideoDetailsButton: some View {
Button("Open video details") {
2021-07-11 20:52:49 +00:00
navigationState.openVideoDetails(video)
}
}
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()
}
}
}
}