1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Views/VideoContextMenuView.swift

58 lines
1.6 KiB
Swift
Raw Normal View History

import Defaults
import SwiftUI
struct VideoContextMenuView: View {
2021-07-12 02:22:49 +05:30
@EnvironmentObject<NavigationState> private var navigationState
let video: Video
@Default(.showingAddToPlaylist) var showingAddToPlaylist
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
var body: some View {
2021-08-03 02:40:22 +05:30
openChannelButton(from: video)
2021-07-08 04:09:18 +05:30
openVideoDetailsButton
2021-07-12 02:22:49 +05:30
if navigationState.tabSelection == .playlists {
removeFromPlaylistButton
} else {
addToPlaylistButton
2021-07-08 04:09:18 +05:30
}
}
func openChannelButton(from video: Video) -> some View {
Button("\(video.author) Channel") {
2021-07-12 02:22:49 +05:30
navigationState.openChannel(Channel.from(video: video))
}
}
func closeChannelButton(from video: Video) -> some View {
Button("Close \(Channel.from(video: video).name) Channel") {
2021-07-12 02:22:49 +05:30
navigationState.closeChannel()
}
}
var openVideoDetailsButton: some View {
Button("Open video details") {
2021-07-12 02:22:49 +05:30
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()
}
}
}
}