diff --git a/Shared/EnvironmentValues.swift b/Shared/EnvironmentValues.swift index 3e1394be..1577bfe7 100644 --- a/Shared/EnvironmentValues.swift +++ b/Shared/EnvironmentValues.swift @@ -30,6 +30,10 @@ private struct InNavigationViewKey: EnvironmentKey { static let defaultValue = true } +private struct InQueueListingKey: EnvironmentKey { + static let defaultValue = false +} + enum ListingStyle: String, CaseIterable, Defaults.Serializable { case cells case list @@ -103,4 +107,10 @@ extension EnvironmentValues { get { self[InNavigationViewKey.self] } set { self[InNavigationViewKey.self] = newValue } } + + var inQueueListing: Bool { + get { self[InQueueListingKey.self] } + set { self[InQueueListingKey.self] = newValue } + } + } diff --git a/Shared/Player/Video Details/PlayerQueueView.swift b/Shared/Player/Video Details/PlayerQueueView.swift index bfd11fe2..83ed0253 100644 --- a/Shared/Player/Video Details/PlayerQueueView.swift +++ b/Shared/Player/Video Details/PlayerQueueView.swift @@ -4,7 +4,6 @@ import SwiftUI struct PlayerQueueView: View { var sidebarQueue: Bool - @Binding var fullScreen: Bool @FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)]) var watches: FetchedResults @@ -138,7 +137,7 @@ struct PlayerQueueView: View { struct PlayerQueueView_Previews: PreviewProvider { static var previews: some View { VStack { - PlayerQueueView(sidebarQueue: true, fullScreen: .constant(true)) + PlayerQueueView(sidebarQueue: true) } .injectFixtureEnvironmentObjects() } diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index f9506ad2..8b1eb631 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -394,14 +394,14 @@ struct VideoPlayerView: View { if !fullScreenPlayer { #if os(iOS) if sidebarQueue { - PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails) + PlayerQueueView(sidebarQueue: true) .frame(maxWidth: 350) .background(colorScheme == .dark ? Color.black : Color.white) .transition(.move(edge: .bottom)) } #elseif os(macOS) if Defaults[.playerSidebar] != .never { - PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails) + PlayerQueueView(sidebarQueue: true) .frame(width: 350) .background(colorScheme == .dark ? Color.black : Color.white) } diff --git a/Shared/Player/WatchNextView.swift b/Shared/Player/WatchNextView.swift index 594ccfc2..3a873613 100644 --- a/Shared/Player/WatchNextView.swift +++ b/Shared/Player/WatchNextView.swift @@ -197,22 +197,9 @@ struct WatchNextView: View { let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: model.isAutoplaying ? 1 : 0) if !queueForMoreVideos.isEmpty { ForEach(queueForMoreVideos) { item in - PlayerQueueRow(item: item) - .contextMenu { - removeButton(item) - removeAllButton() - - if let video = item.video { - VideoContextMenuView(video: video) - } - } - #if os(tvOS) - .padding(.horizontal, 30) - #endif - - #if !os(tvOS) - Divider() - #endif + ContentItemView(item: .init(video: item.video)) + .environment(\.inQueueListing, true) + .environment(\.listingStyle, .list) } } else if player.playbackMode != .related && player.playbackMode != .loopOne { Label( @@ -239,22 +226,6 @@ struct WatchNextView: View { } } } - - private func removeButton(_ item: PlayerQueueItem) -> some View { - Button { - player.remove(item) - } label: { - Label("Remove from the queue", systemImage: "trash") - } - } - - private func removeAllButton() -> some View { - Button { - player.removeQueueItems() - } label: { - Label("Clear the queue", systemImage: "trash.fill") - } - } } struct WatchNextView_Previews: PreviewProvider { diff --git a/Shared/Views/VideoContextMenuView.swift b/Shared/Views/VideoContextMenuView.swift index 2fff6963..5e952a60 100644 --- a/Shared/Views/VideoContextMenuView.swift +++ b/Shared/Views/VideoContextMenuView.swift @@ -8,6 +8,7 @@ struct VideoContextMenuView: View { @Environment(\.inChannelView) private var inChannelView @Environment(\.inChannelPlaylistView) private var inChannelPlaylistView + @Environment(\.inQueueListing) private var inQueueListing @Environment(\.navigationStyle) private var navigationStyle @Environment(\.currentPlaylistID) private var playlistID @@ -36,6 +37,12 @@ struct VideoContextMenuView: View { } @ViewBuilder var contextMenu: some View { + if inQueueListing { + if let item = player.queue.first(where: { $0.videoID == video.videoID }) { + removeFromQueueButton(item) + } + removeAllFromQueueButton() + } if !video.localStreamIsDirectory { if saveHistory { Section { @@ -340,4 +347,20 @@ struct VideoContextMenuView: View { Label("Remove from Playlist", systemImage: "text.badge.minus") } } + + private func removeFromQueueButton(_ item: PlayerQueueItem) -> some View { + Button { + player.remove(item) + } label: { + Label("Remove from the queue", systemImage: "trash") + } + } + + private func removeAllFromQueueButton() -> some View { + Button { + player.removeQueueItems() + } label: { + Label("Clear the queue", systemImage: "trash.fill") + } + } }