mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
74 lines
2.0 KiB
Swift
74 lines
2.0 KiB
Swift
import Defaults
|
|
import SwiftUI
|
|
|
|
struct VideoContextMenuView: View {
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
|
@EnvironmentObject<Subscriptions> private var subscriptions
|
|
|
|
let video: Video
|
|
|
|
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
|
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
|
|
|
|
@State private var subscribed = false
|
|
|
|
var body: some View {
|
|
Section {
|
|
openChannelButton
|
|
|
|
subscriptionButton
|
|
.opacity(subscribed ? 1 : 1)
|
|
|
|
openVideoDetailsButton
|
|
|
|
if navigationState.tabSelection == .playlists {
|
|
removeFromPlaylistButton
|
|
} else {
|
|
addToPlaylistButton
|
|
}
|
|
}
|
|
}
|
|
|
|
var openChannelButton: some View {
|
|
Button("\(video.author) Channel") {
|
|
navigationState.openChannel(video.channel)
|
|
}
|
|
}
|
|
|
|
var subscriptionButton: some View {
|
|
Group {
|
|
if subscriptions.subscribed(video.channel.id) {
|
|
Button("Unsubscribe", role: .destructive) {
|
|
subscriptions.unsubscribe(video.channel.id)
|
|
}
|
|
} else {
|
|
Button("Subscribe") {
|
|
subscriptions.subscribe(video.channel.id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var openVideoDetailsButton: some View {
|
|
Button("Open video details") {
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
}
|