yattee/Shared/Views/VideoContextMenuView.swift

130 lines
3.7 KiB
Swift
Raw Normal View History

import Defaults
import SwiftUI
struct VideoContextMenuView: View {
let video: Video
@Binding var playerNavigationLinkActive: Bool
@Environment(\.inNavigationView) private var inNavigationView
2021-09-25 08:18:22 +00:00
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<PlaylistsModel> private var playlists
2021-09-25 12:17:58 +00:00
@EnvironmentObject<RecentsModel> private var recents
2021-09-25 08:18:22 +00:00
@EnvironmentObject<SubscriptionsModel> private var subscriptions
var body: some View {
Section {
playNowButton
}
Section {
playNextButton
addToQueueButton
}
Section {
openChannelButton
subscriptionButton
}
Section {
if navigation.tabSelection != .playlists {
addToPlaylistButton
} else if let playlist = playlists.currentPlaylist {
removeFromPlaylistButton(playlistID: playlist.id)
}
if case let .playlist(id) = navigation.tabSelection {
removeFromPlaylistButton(playlistID: id)
}
}
#if os(tvOS)
Button("Cancel", role: .cancel) {}
#endif
}
var playNowButton: some View {
Button {
player.playNow(video)
2021-08-25 22:12:59 +00:00
if inNavigationView {
playerNavigationLinkActive = true
} else {
player.presentPlayer()
}
} label: {
Label("Play Now", systemImage: "play")
}
}
2021-07-07 22:39:18 +00:00
var playNextButton: some View {
Button {
player.playNext(video)
} label: {
Label("Play Next", systemImage: "text.insert")
2021-09-28 23:01:49 +00:00
}
}
var addToQueueButton: some View {
Button {
player.enqueueVideo(video)
} label: {
Label("Play Last", systemImage: "text.append")
2021-07-07 22:39:18 +00:00
}
}
2021-08-25 22:12:59 +00:00
var openChannelButton: some View {
2021-09-28 23:01:49 +00:00
Button {
2021-09-19 11:06:54 +00:00
let recent = RecentItem(from: video.channel)
recents.add(recent)
2021-09-25 08:18:22 +00:00
navigation.isChannelOpen = true
navigation.sidebarSectionChanged.toggle()
2021-09-28 23:01:49 +00:00
navigation.tabSelection = .recentlyOpened(recent.tag)
} label: {
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
}
}
2021-08-25 22:12:59 +00:00
var subscriptionButton: some View {
Group {
if subscriptions.isSubscribing(video.channel.id) {
2021-09-28 23:01:49 +00:00
Button(role: .destructive) {
#if os(tvOS)
subscriptions.unsubscribe(video.channel.id)
#else
2021-09-25 08:18:22 +00:00
navigation.presentUnsubscribeAlert(video.channel)
#endif
2021-09-28 23:01:49 +00:00
} label: {
Label("Unsubscribe", systemImage: "xmark.circle")
2021-08-25 22:12:59 +00:00
}
} else {
2021-09-28 23:01:49 +00:00
Button {
subscriptions.subscribe(video.channel.id) {
2021-09-25 08:18:22 +00:00
navigation.sidebarSectionChanged.toggle()
}
2021-09-28 23:01:49 +00:00
} label: {
Label("Subscribe", systemImage: "star.circle")
2021-08-25 22:12:59 +00:00
}
}
}
}
var addToPlaylistButton: some View {
2021-09-28 23:01:49 +00:00
Button {
navigation.presentAddToPlaylist(video)
2021-09-28 23:01:49 +00:00
} label: {
Label("Add to playlist...", systemImage: "text.badge.plus")
}
}
func removeFromPlaylistButton(playlistID: String) -> some View {
2021-09-28 23:01:49 +00:00
Button(role: .destructive) {
playlists.removeVideoFromPlaylist(videoIndexID: video.indexID!, playlistID: playlistID)
2021-09-28 23:01:49 +00:00
} label: {
Label("Remove from playlist", systemImage: "text.badge.minus")
}
}
}