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

75 lines
2.2 KiB
Swift
Raw Normal View History

import Defaults
import SwiftUI
struct VideoContextMenuView: View {
2021-09-25 13:48:22 +05:30
@EnvironmentObject<InvidiousAPI> private var api
@EnvironmentObject<NavigationModel> private var navigation
2021-09-25 17:47:58 +05:30
@EnvironmentObject<RecentsModel> private var recents
2021-09-25 13:48:22 +05:30
@EnvironmentObject<SubscriptionsModel> private var subscriptions
let video: Video
@Default(.showingAddToPlaylist) var showingAddToPlaylist
@Default(.videoIDToAddToPlaylist) var videoIDToAddToPlaylist
var body: some View {
2021-08-26 03:42:59 +05:30
Section {
2021-09-19 16:36:54 +05:30
openChannelButton
2021-08-26 03:42:59 +05:30
subscriptionButton
2021-07-08 04:09:18 +05:30
2021-09-25 13:48:22 +05:30
if navigation.tabSelection == .playlists {
2021-08-26 03:42:59 +05:30
removeFromPlaylistButton
} else {
addToPlaylistButton
}
2021-07-08 04:09:18 +05:30
}
}
2021-08-26 03:42:59 +05:30
var openChannelButton: some View {
Button("\(video.author) Channel") {
2021-09-19 16:36:54 +05:30
let recent = RecentItem(from: video.channel)
recents.open(recent)
2021-09-25 13:48:22 +05:30
navigation.tabSelection = .recentlyOpened(recent.tag)
navigation.isChannelOpen = true
navigation.sidebarSectionChanged.toggle()
}
}
2021-08-26 03:42:59 +05:30
var subscriptionButton: some View {
Group {
if subscriptions.isSubscribing(video.channel.id) {
2021-08-26 03:42:59 +05:30
Button("Unsubscribe", role: .destructive) {
#if os(tvOS)
subscriptions.unsubscribe(video.channel.id)
#else
2021-09-25 13:48:22 +05:30
navigation.presentUnsubscribeAlert(video.channel)
#endif
2021-08-26 03:42:59 +05:30
}
} else {
Button("Subscribe") {
subscriptions.subscribe(video.channel.id) {
2021-09-25 13:48:22 +05:30
navigation.sidebarSectionChanged.toggle()
}
2021-08-26 03:42:59 +05:30
}
}
}
}
var addToPlaylistButton: some View {
Button("Add to playlist...") {
videoIDToAddToPlaylist = video.id
showingAddToPlaylist = true
}
}
var removeFromPlaylistButton: some View {
Button("Remove from playlist", role: .destructive) {
2021-09-25 13:48:22 +05:30
let resource = api.playlistVideo(Defaults[.selectedPlaylistID]!, video.indexID!)
resource.request(.delete).onSuccess { _ in
2021-09-25 13:48:22 +05:30
api.playlists.load()
}
}
}
}